[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": { "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": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "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": { "locked": {
"lastModified": 1701680307, "lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
@ -51,40 +20,26 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1698370541, "lastModified": 1703499205,
"narHash": "sha256-/mQQPmcRbpWsGgFi4vj4Bz2N2Yos4Vr+ru+v3qyEqp0=", "narHash": "sha256-lF9rK5mSUfIZJgZxC3ge40tp1gmyyOXZ+lRY3P8bfbg=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f1775e6477c6e342bbbdecf363f9f5821d7fd3e4", "rev": "e1fa12d4f6c6fe19ccb59cac54b5b3f25e160870",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "master", "ref": "nixpkgs-unstable",
"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",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"pnpm2nix": { "pnpm2nix": {
"inputs": { "inputs": {
"flake-utils": "flake-utils_2", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs_2" "nixpkgs": [
"nixpkgs"
]
}, },
"locked": { "locked": {
"lastModified": 1702270329, "lastModified": 1702270329,
@ -102,8 +57,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"pnpm2nix": "pnpm2nix" "pnpm2nix": "pnpm2nix"
} }
@ -122,21 +75,6 @@
"repo": "default", "repo": "default",
"type": "github" "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", "root": "root",

View File

@ -2,41 +2,31 @@
description = "Flake for owmods-cli and owmods-gui"; description = "Flake for owmods-cli and owmods-gui";
inputs = { inputs = {
flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; pnpm2nix = {
pnpm2nix.url = "github:nzbr/pnpm2nix-nzbr"; url = "github:nzbr/pnpm2nix-nzbr";
nixpkgs.url = "github:NixOS/nixpkgs/master"; inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = { outputs = {
self, self,
flake-utils,
flake-compat,
nixpkgs, nixpkgs,
pnpm2nix, pnpm2nix,
}: }: let
flake-utils.lib.eachDefaultSystem ( forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed;
system: let pkgsFor = system:
pkgs = (import nixpkgs) { (import nixpkgs) {
inherit system; inherit system;
overlays = [self.overlay.owmods pnpm2nix.overlays.default]; overlays = [self.overlays.default pnpm2nix.overlays.default];
}; };
in rec { in {
# For `nix build` & `nix run`: packages = forAllSystems (system: with pkgsFor system; {inherit owmods-cli owmods-gui;});
packages = rec { overlays.default = import ./nix/overlay.nix;
owmods-cli = pkgs.owmods-cli;
owmods-gui = pkgs.owmods-gui; formatter = forAllSystems (system: (pkgsFor system).alejandra);
default = pkgs.owmods-cli; devShells = forAllSystems (system: {default = import ./nix/shell.nix {pkgs = pkgsFor system;};});
}; };
}
)
// {
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;
};
nixConfig = { nixConfig = {
extra-substituters = ["https://ow-mods.cachix.org"]; 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. Currently, `owmods-cli` is in nixpkgs. ([Nixpkgs status](https://search.nixos.org/packages?channel=unstable&type=packages&query=owmod))
## Without Flakes
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 ```nix
{ pkgs, lib, ... }:
let 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"; url = "https://github.com/ow-mods/ow-mod-man.git";
# You can choose which version by changing the ref
ref = "dev"; 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 }: ow-mod-man = (flake-compat { inherit src; }).defaultNix;
# You need to add the ow-mod-man overlay to your packages in ow-mod-man.packages.<system>.owmods-<gui/cli>
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 ];
};
};
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: { final: prev: {
owmods-cli = final.pkgs.callPackage ./owmods-cli.nix {}; owmods-cli = final.callPackage ./owmods-cli.nix {};
owmods-gui = final.pkgs.callPackage ./owmods-gui.nix {}; owmods-gui = final.callPackage ./owmods-gui.nix {};
} }

View File

@ -6,12 +6,28 @@
fetchFromGitHub, fetchFromGitHub,
installShellFiles, installShellFiles,
rustPlatform, rustPlatform,
makeWrapper,
mono,
wrapWithMono ? true,
}: }:
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
pname = "owmods-cli"; pname = "owmods-cli";
version = "0.12.0"; 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 = { cargoLock = {
lockFile = ../Cargo.lock; lockFile = ../Cargo.lock;
@ -20,7 +36,7 @@ rustPlatform.buildRustPackage rec {
nativeBuildInputs = [ nativeBuildInputs = [
pkg-config pkg-config
installShellFiles installShellFiles
]; ] ++ lib.optional wrapWithMono makeWrapper;
buildInputs = [ buildInputs = [
openssl openssl
@ -34,6 +50,7 @@ rustPlatform.buildRustPackage rec {
installManPage dist/cli/man/* installManPage dist/cli/man/*
installShellCompletion --cmd owmods \ installShellCompletion --cmd owmods \
dist/cli/completions/owmods.{bash,fish,zsh} dist/cli/completions/owmods.{bash,fish,zsh}
${lib.optionalString wrapWithMono "wrapProgram $out/bin/${meta.mainProgram} --prefix PATH : '${mono}/bin'"}
''; '';
meta = with lib; { meta = with lib; {

View File

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

View File

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