modules: system: nix: DRY inputs handling

This commit is contained in:
Bruno BELANYI 2023-02-25 01:03:42 +00:00
parent 3c6e8933a1
commit 8b9a01a0ef
1 changed files with 21 additions and 17 deletions

View File

@ -2,6 +2,21 @@
{ config, inputs, lib, options, pkgs, ... }: { config, inputs, lib, options, pkgs, ... }:
let let
cfg = config.my.system.nix; cfg = config.my.system.nix;
channels = lib.my.merge [
{
# Allow me to use my custom package using `nix run self#pkg`
self = inputs.self;
# Add NUR to run some packages that are only present there
nur = inputs.nur;
# Use pinned nixpkgs when using `nix run pkgs#<whatever>`
pkgs = inputs.nixpkgs;
}
(lib.optionalAttrs cfg.overrideNixpkgs {
# ... And with `nix run nixpkgs#<whatever>`
nixpkgs = inputs.nixpkgs;
})
];
in in
{ {
options.my.system.nix = with lib; { options.my.system.nix = with lib; {
@ -40,16 +55,12 @@ in
} }
(lib.mkIf cfg.addToRegistry { (lib.mkIf cfg.addToRegistry {
nix.registry = { nix.registry =
# Allow me to use my custom package using `nix run self#pkg` let
self.flake = inputs.self; makeEntry = v: { flake = v; };
# Use pinned nixpkgs when using `nix run pkgs#<whatever>` makeEntries = lib.mapAttrs (lib.const makeEntry);
pkgs.flake = inputs.nixpkgs; in
# ... And with `nix run nixpkgs#<whatever>` makeEntries channels;
nixpkgs.flake = lib.mkIf cfg.overrideNixpkgs inputs.nixpkgs;
# Add NUR to run some packages that are only present there
nur.flake = inputs.nur;
};
}) })
(lib.mkIf cfg.linkInputs { (lib.mkIf cfg.linkInputs {
@ -60,13 +71,6 @@ in
value = { source = v.outPath; }; value = { source = v.outPath; };
}; };
makeLinks = lib.mapAttrs' makeLink; makeLinks = lib.mapAttrs' makeLink;
channels = {
self = inputs.self;
pkgs = inputs.nixpkgs;
nur = inputs.nur;
} // lib.optionalAttrs cfg.overrideNixpkgs {
nixpkgs = inputs.nixpkgs;
};
in in
makeLinks channels; makeLinks channels;
}) })