flake: provide a single NixOS module

Instead of providing two NixOS modules (one for using system pkgs,
one for using locked pkgs), provide a single module with option
`useVersionLockedPkgs`.

This fixes that all nix-bitcoin options are displayed twice
on search.nixos.org:
https://search.nixos.org/flakes?type=options&query=clightning
This commit is contained in:
Erik Arvstedt 2021-12-27 16:58:15 +01:00
parent d69524143b
commit 6be3fb3e77
No known key found for this signature in database
GPG Key ID: 33312B944DD97846
2 changed files with 39 additions and 24 deletions

View File

@ -8,19 +8,11 @@
nixosConfigurations.mynode = nix-bitcoin.inputs.nixpkgs.lib.nixosSystem { nixosConfigurations.mynode = nix-bitcoin.inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";
modules = [ modules = [
## Note: nix-bitcoin.nixosModule
## If you use a custom nixpkgs version for evaluating your system,
## consider using `withLockedPkgs` instead of `withSystemPkgs` to use the exact
## pkgs versions for nix-bitcoin services that are tested by nix-bitcoin.
## The downsides are increased evaluation times and increased system
## closure size.
#
# nix-bitcoin.nixosModules.withLockedPkgs
nix-bitcoin.nixosModules.withSystemPkgs
## Optional: # Optional:
## Import the secure-node preset, an opinionated config to enhance security # Import the secure-node preset, an opinionated config to enhance security
## and privacy. # and privacy.
# #
# "${nix-bitcoin}/modules/presets/secure-node.nix" # "${nix-bitcoin}/modules/presets/secure-node.nix"
@ -46,6 +38,15 @@
isNormalUser = true; isNormalUser = true;
password = "a"; password = "a";
}; };
# If you use a custom nixpkgs version for evaluating your system
# (instead of `nix-bitcoin.inputs.nixpkgs` like in this example),
# consider setting `useVersionLockedPkgs = true` to use the exact pkgs
# versions for nix-bitcoin services that are tested by nix-bitcoin.
# The downsides are increased evaluation times and increased system
# closure size.
#
# nix-bitcoin.useVersionLockedPkgs = true;
} }
]; ];
}; };

View File

@ -28,19 +28,33 @@
nbPkgs = lib.mkNbPkgs { inherit (final) system; pkgs = final; }; nbPkgs = lib.mkNbPkgs { inherit (final) system; pkgs = final; };
in removeAttrs nbPkgs [ "pinned" "nixops19_09" "krops" ]; in removeAttrs nbPkgs [ "pinned" "nixops19_09" "krops" ];
nixosModules = { nixosModule = { config, pkgs, lib, ... }: {
# Uses the default system pkgs for nix-bitcoin.pkgs
withSystemPkgs = { pkgs, ... }: {
imports = [ ./modules/modules.nix ]; imports = [ ./modules/modules.nix ];
nix-bitcoin.pkgs = (lib.mkNbPkgs { inherit (pkgs) system; inherit pkgs; }).modulesPkgs;
options = with lib; {
nix-bitcoin.useVersionLockedPkgs = mkOption {
type = types.bool;
default = false;
description = ''
Use the nixpkgs version locked by this flake for `nix-bitcoin.pkgs`.
Only relevant if you are using a nixpkgs version for evaluating your system
that differs from the one that is locked by this flake (via input `nixpkgs`).
If this is the case, enabling this option may result in a more stable system
because the nix-bitcoin services use the exact pkgs versions that are tested
by nix-bitcoin.
The downsides are increased evaluation times and increased system
closure size.
If `false`, the default system pkgs are used.
'';
};
}; };
# Uses the nixpkgs version locked by this flake for nix-bitcoin.pkgs. config = {
# More stable, but slightly slower to evaluate and needs more space if the nix-bitcoin.pkgs =
# locked and the system nixpkgs versions differ. if config.nix-bitcoin.useVersionLockedPkgs
withLockedPkgs = { config, ... }: { then (self.lib.mkNbPkgs { inherit (config.nixpkgs) system; }).modulesPkgs
imports = [ ./modules/modules.nix ]; else (self.lib.mkNbPkgs { inherit (pkgs) system; inherit pkgs; }).modulesPkgs;
nix-bitcoin.pkgs = (lib.mkNbPkgs { inherit (config.nixpkgs) system; }).modulesPkgs;
}; };
}; };
@ -77,7 +91,7 @@
inherit system; inherit system;
configuration = { configuration = {
imports = [ imports = [
nix-bitcoin.nixosModules.withSystemPkgs nix-bitcoin.nixosModule
"${nix-bitcoin}/modules/presets/secure-node.nix" "${nix-bitcoin}/modules/presets/secure-node.nix"
]; ];