From c1214547da21d0075b63bedf1ca5f54af60c3691 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 20 Feb 2023 22:26:51 +0100 Subject: [PATCH 1/2] modules: system: nix: add '/etc/nix/inputs' links --- modules/system/nix/default.nix | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/system/nix/default.nix b/modules/system/nix/default.nix index f8e7c24..bae6e6f 100644 --- a/modules/system/nix/default.nix +++ b/modules/system/nix/default.nix @@ -7,6 +7,8 @@ in options.my.system.nix = with lib; { enable = my.mkDisableOption "nix configuration"; + linkInputs = my.mkDisableOption "link inputs to `/etc/nix/inputs/`"; + addToRegistry = my.mkDisableOption "add inputs and self to registry"; addToNixPath = my.mkDisableOption "add inputs and self to nix path"; @@ -38,6 +40,24 @@ in }; }) + (lib.mkIf cfg.linkInputs { + environment.etc = + let + makeLink = n: v: { + name = "nix/inputs/${n}"; + value = { source = v.outPath; }; + }; + makeLinks = lib.mapAttrs' makeLink; + in + makeLinks { + inherit (inputs) + self + nixpkgs + nur + ; + }; + }) + (lib.mkIf cfg.addToNixPath { nix.nixPath = [ "self=${inputs.self}" From 6eb87c21b7be926d7a09a3fa582fc0919b57339d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 23 Feb 2023 21:00:30 +0000 Subject: [PATCH 2/2] modules: system: nix: use stable 'NIX_PATH' Since the links are updated on system switch, NIX_PATH will automatically point to the actual system version of the inputs at all times --- modules/system/nix/default.nix | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/system/nix/default.nix b/modules/system/nix/default.nix index bae6e6f..463c0f5 100644 --- a/modules/system/nix/default.nix +++ b/modules/system/nix/default.nix @@ -17,6 +17,18 @@ in }; config = lib.mkIf cfg.enable (lib.mkMerge [ + { + assertions = [ + { + assertion = cfg.addToNixPath -> cfg.linkInputs; + message = '' + enabling `my.system.nix.addToNixPath` needs to have + `my.system.nix.linkInputs = true` + ''; + } + ]; + } + { nix = { package = pkgs.nix; @@ -60,11 +72,11 @@ in (lib.mkIf cfg.addToNixPath { nix.nixPath = [ - "self=${inputs.self}" - "pkgs=${inputs.nixpkgs}" - "nur=${inputs.nur}" + "self=/etc/nix/inputs/self" + "pkgs=/etc/nix/inputs/nixpkgs" + "nur=/etc/nix/inputs/nur" ] - ++ lib.optional cfg.overrideNixpkgs "nixpkgs=${inputs.nixpkgs}" + ++ lib.optional cfg.overrideNixpkgs "nixpkgs=/etc/nix/inputs/nixpkgs" ++ options.nix.nixPath.default; }) ]);