From 8b9a01a0efc691239104330bc7fb4c797a614a83 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 25 Feb 2023 01:03:42 +0000 Subject: [PATCH] modules: system: nix: DRY inputs handling --- modules/system/nix/default.nix | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/modules/system/nix/default.nix b/modules/system/nix/default.nix index 056b5da..c8ce001 100644 --- a/modules/system/nix/default.nix +++ b/modules/system/nix/default.nix @@ -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#` + pkgs = inputs.nixpkgs; + } + (lib.optionalAttrs cfg.overrideNixpkgs { + # ... And with `nix run nixpkgs#` + 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#` - pkgs.flake = inputs.nixpkgs; - # ... And with `nix run nixpkgs#` - 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; })