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

View file

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