[NIX] Refactor (#330)

This commit is contained in:
Spoonbaker 2023-12-28 12:35:42 -05:00 committed by GitHub
parent 251b93623d
commit 80f2f84111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 117 additions and 296 deletions

View File

@ -1,14 +0,0 @@
(
import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}
)
{src = ./.;}
)
.defaultNix

78
flake.lock generated
View File

@ -1,40 +1,9 @@
{
"nodes": {
"flake-compat": {
"locked": {
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
@ -51,40 +20,26 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1698370541,
"narHash": "sha256-/mQQPmcRbpWsGgFi4vj4Bz2N2Yos4Vr+ru+v3qyEqp0=",
"lastModified": 1703499205,
"narHash": "sha256-lF9rK5mSUfIZJgZxC3ge40tp1gmyyOXZ+lRY3P8bfbg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f1775e6477c6e342bbbdecf363f9f5821d7fd3e4",
"rev": "e1fa12d4f6c6fe19ccb59cac54b5b3f25e160870",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "master",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1702151865,
"narHash": "sha256-9VAt19t6yQa7pHZLDbil/QctAgVsA66DLnzdRGqDisg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "666fc80e7b2afb570462423cb0e1cf1a3a34fedd",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pnpm2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs_2"
"flake-utils": "flake-utils",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1702270329,
@ -102,8 +57,6 @@
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"pnpm2nix": "pnpm2nix"
}
@ -122,21 +75,6 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -2,41 +2,31 @@
description = "Flake for owmods-cli and owmods-gui";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr";
nixpkgs.url = "github:NixOS/nixpkgs/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
pnpm2nix = {
url = "github:nzbr/pnpm2nix-nzbr";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
flake-utils,
flake-compat,
nixpkgs,
pnpm2nix,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = (import nixpkgs) {
inherit system;
overlays = [self.overlay.owmods pnpm2nix.overlays.default];
};
in rec {
# For `nix build` & `nix run`:
packages = rec {
owmods-cli = pkgs.owmods-cli;
owmods-gui = pkgs.owmods-gui;
default = pkgs.owmods-cli;
};
}
)
// {
formatter."x86_64-linux" = nixpkgs.legacyPackages."x86_64-linux".alejandra;
devShell."x86_64-linux" = (import ./nix/shell.nix) {inherit nixpkgs;};
overlay.owmods = import ./nix/overlay.nix;
nixosModules.owmods = import ./nix/modules/nixos.nix;
homeManagerModules.owmods = import ./nix/modules/hm.nix;
};
}: let
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
pkgsFor = system:
(import nixpkgs) {
inherit system;
overlays = [self.overlays.default pnpm2nix.overlays.default];
};
in {
packages = forAllSystems (system: with pkgsFor system; {inherit owmods-cli owmods-gui;});
overlays.default = import ./nix/overlay.nix;
formatter = forAllSystems (system: (pkgsFor system).alejandra);
devShells = forAllSystems (system: {default = import ./nix/shell.nix {pkgs = pkgsFor system;};});
};
nixConfig = {
extra-substituters = ["https://ow-mods.cachix.org"];

View File

@ -1,97 +1,34 @@
# NixOS Installation
# Usage with Nix
You can either install using the package in [nixpkgs](https://search.nixos.org/packages?channel=unstable&show=owmods-cli&from=0&size=50&sort=relevance&type=packages&query=owmods) or by getting it from the flake.
## Without Flakes
Currently, `owmods-cli` is in nixpkgs. ([Nixpkgs status](https://search.nixos.org/packages?channel=unstable&type=packages&query=owmod))
This flake comes with [flake-compat](https://github.com/edolstra/flake-compat), which makes it usable in systems that use flakes, or not.
Alternatively, you can get the latest version from this repo.
## Flakes
The flake provides an overlay and the packages `owmods-cli` and `owmods-gui`.
```nix
ow-mod-man = {
url = "github:ow-mods/ow-mod-man/dev";
inputs.nixpkgs.follows = "nixpkgs";
};
```
You can then reference `ow-mod-man.packages.<system>.owmods-<gui/cli>`, or use the overlay, for example:
```nix
nixpkgs.overlays = [ inputs.ow-mod-man.overlays.default ]
```
## Without flakes
If you can't or don't want to use flakes, you can use [flake-compat](https://github.com/edolstra/flake-compat).
To install it, edit you NixOS/Home Manager configuration with:
```nix
{ pkgs, lib, ... }:
let
ow-mod-man = import (builtins.fetchGit {
flake-compat = import (fetchTarball "https://github.com/edolstra/flake-compat/archive/master.tar.gz");
src = fetchGit {
url = "https://github.com/ow-mods/ow-mod-man.git";
# You can choose which version by changing the ref
ref = "dev";
});
in
{
imports = [
# For NixOS
ow-mod-man.nixosModules.owmods
# For Home Manager
ow-mod-man.homeManagerModules.owmods
];
# Unsafe dependency of the gui version
permittedInsecurePackages = [ "openssl-1.1.1w" ];
# To enable the cli version
programs.owmods-cli.enable = true;
# To enable the gui version
programs.owmods-gui.enable = true;
}
```
## Using Flakes
If you are already using flakes, this is the recommended method, what you need to add is:
- In your flake.nix:
```nix
{
inputs.ow-mod-man = {
url = "github:ow-mods/ow-mod-man/dev";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { ow-mod-man }:
# You need to add the ow-mod-man overlay to your packages
let pkgs = import nixpkgs {
inherit system;
config = {
# Needed for the gui version
permittedInsecurePackages = [ "openssl-1.1.1w" ];
};
# Needed to be able to use the packages
overlays = [ ow-mod-man.overlay.owmods ];
};
in {
homeConfigurations = {
userA = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
# For your home.nix
modules = [ ow-mod-man.homeManagerModules.owmods ];
};
};
ow-mod-man = (flake-compat { inherit src; }).defaultNix;
in ow-mod-man.packages.<system>.owmods-<gui/cli>
nixosConfigurations = {
systemA = lib.nixosSystem {
inherit system;
inherit pkgs;
# For your configuration.nix
modules = [ ow-mod-man.nixosModules.owmods ];
};
};
}
```
- In your configuration.nix:
```nix
{ pkgs, inputs, ... }:
{
# To enable the cli version
programs.owmods-cli.enable = true;
# To enable the gui version
programs.owmods-gui.enable = true;
}
```
- In your home.nix:
```nix
{ pkgs, inputs, ... }:
{
# To enable the cli version
programs.owmods-cli.enable = true;
# To enable the gui version
programs.owmods-gui.enable = true;
}
```
```

View File

@ -1,31 +0,0 @@
{
lib,
pkgs,
config,
...
}:
with lib; let
cli-cfg = config.programs.owmods-cli;
gui-cfg = config.programs.owmods-gui;
in {
options.programs = {
owmods-cli = {
enable = mkEnableOption "owmods-cli program";
};
owmods-gui = {
enable = mkEnableOption "owmods-gui program";
};
};
config = mkIf (cli-cfg.enable || gui-cfg.enable) (
mkMerge [
{
home.packages = [
(mkIf cli-cfg.enable (pkgs.owmods-cli))
(mkIf gui-cfg.enable (pkgs.owmods-gui))
pkgs.mono
];
}
]
);
}

View File

@ -1,31 +0,0 @@
{
lib,
pkgs,
config,
...
}:
with lib; let
cli-cfg = config.programs.owmods-cli;
gui-cfg = config.programs.owmods-gui;
in {
options.programs = {
owmods-cli = {
enable = mkEnableOption "owmods-cli program";
};
owmods-gui = {
enable = mkEnableOption "owmods-gui program";
};
};
config = mkIf (cli-cfg.enable || gui-cfg.enable) (
mkMerge [
{
environment.systemPackages = [
(mkIf cli-cfg.enable (pkgs.owmods-cli))
(mkIf gui-cfg.enable (pkgs.owmods-gui))
pkgs.mono
];
}
]
);
}

View File

@ -1,4 +1,4 @@
final: prev: {
owmods-cli = final.pkgs.callPackage ./owmods-cli.nix {};
owmods-gui = final.pkgs.callPackage ./owmods-gui.nix {};
owmods-cli = final.callPackage ./owmods-cli.nix {};
owmods-gui = final.callPackage ./owmods-gui.nix {};
}

View File

@ -6,12 +6,28 @@
fetchFromGitHub,
installShellFiles,
rustPlatform,
makeWrapper,
mono,
wrapWithMono ? true,
}:
rustPlatform.buildRustPackage rec {
pname = "owmods-cli";
version = "0.12.0";
src = ../.;
# Prevent unneeded rebuilds
src = with lib.fileset;
toSource {
root = ../.;
fileset = unions [
../.cargo
../owmods_gui
../owmods_cli
../owmods_core
../xtask
../Cargo.toml
../Cargo.lock
];
};
cargoLock = {
lockFile = ../Cargo.lock;
@ -20,7 +36,7 @@ rustPlatform.buildRustPackage rec {
nativeBuildInputs = [
pkg-config
installShellFiles
];
] ++ lib.optional wrapWithMono makeWrapper;
buildInputs = [
openssl
@ -34,6 +50,7 @@ rustPlatform.buildRustPackage rec {
installManPage dist/cli/man/*
installShellCompletion --cmd owmods \
dist/cli/completions/owmods.{bash,fish,zsh}
${lib.optionalString wrapWithMono "wrapProgram $out/bin/${meta.mainProgram} --prefix PATH : '${mono}/bin'"}
'';
meta = with lib; {

View File

@ -16,12 +16,27 @@
copyDesktopItems,
rustPlatform,
mkPnpmPackage,
mono,
wrapWithMono ? true,
}:
rustPlatform.buildRustPackage rec {
pname = "owmods-gui";
version = "0.12.0";
src = ../.;
# Prevent unneeded rebuilds
src = with lib.fileset;
toSource {
root = ../.;
fileset = unions [
../.cargo
../owmods_gui
../owmods_cli
../owmods_core
../xtask
../Cargo.toml
../Cargo.lock
];
};
cargoLock = {
lockFile = ../Cargo.lock;
@ -44,8 +59,10 @@ rustPlatform.buildRustPackage rec {
buildAndTestSubdir = "owmods_gui/backend";
postFixup = lib.optionalString wrapWithMono "gappsWrapperArgs+=(--prefix PATH : '${mono}/bin')";
postPatch = let
frontend = mkPnpmPackage rec {
frontend = mkPnpmPackage {
src = ../owmods_gui/frontend;
installInPlace = true;
distDir = "../dist";
@ -81,7 +98,6 @@ rustPlatform.buildRustPackage rec {
downloadPage = "https://github.com/ow-mods/ow-mod-man/releases/tag/gui_v${version}";
changelog = "https://github.com/ow-mods/ow-mod-man/releases/tag/gui_v${version}";
mainProgram = "outer-wilds-mod-manager";
sourceProvenance = with sourceTypes; [binaryNativeCode];
platforms = platforms.linux;
license = licenses.gpl3;
maintainers = with maintainers; [locochoco];

View File

@ -1,26 +1,25 @@
{nixpkgs}: let
pkgs = nixpkgs.legacyPackages."x86_64-linux";
in
pkgs.mkShell {
name = "owmods-shell";
buildInputs = with pkgs; [
rustc
cargo
clippy
rustfmt
nodejs
openssl
nodePackages.pnpm
gcc
webkitgtk
glib-networking
pkg-config
libnotify
gtk3
libsoup
typeshare
];
shellHook = ''
export GIO_MODULE_DIR=${pkgs.glib-networking}/lib/gio/modules/
'';
}
{pkgs ? import <nixpkgs> {}}:
# NOTE(Spoonbaker): This doesn't include the overlay when using `nix-shell` instead of `nix shell`
pkgs.mkShell {
name = "owmods-shell";
buildInputs = with pkgs; [
rustc
cargo
clippy
rustfmt
nodejs
openssl
nodePackages.pnpm
gcc
webkitgtk
glib-networking
pkg-config
libnotify
gtk3
libsoup
typeshare
];
shellHook = ''
export GIO_MODULE_DIR=${pkgs.glib-networking}/lib/gio/modules/
'';
}