From 4d235b800d2add9adba90686bcadbf4f1beb5d9c Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Wed, 1 May 2019 12:30:00 +0200 Subject: [PATCH] nix: allow specifying named NIX_PATH using and attrset This gives the option nicer merge behaviour, otherwise setting a named entry multiple times would result in duplicates which can't be resolved without overriding the entire list. --- modules/nix/default.nix | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/modules/nix/default.nix b/modules/nix/default.nix index 6ad33ba8..9db2371b 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -311,17 +311,44 @@ in }; nix.nixPath = mkOption { - type = types.listOf types.str; + type = mkOptionType { + name = "nix path"; + merge = loc: defs: + let + values = flatten (map (def: + (map (x: + if isAttrs x then (mapAttrsToList nameValuePair x) + else if isString x then x + else throw "The option value `${showOption loc}` in `${def.file}` is not a attset or string.") + (if isList def.value then def.value else [def.value]))) defs); + + namedPaths = mapAttrsToList (n: v: "${n}=${(head v).value}") + (zipAttrs + (map (x: { "${x.name}" = { inherit (x) value; }; }) + (filter isAttrs values))); + + searchPaths = unique + (filter isString values); + in + namedPaths ++ searchPaths; + }; default = [ # Include default path . - "darwin-config=${config.environment.darwinConfig}" + { darwin-config = "${config.environment.darwinConfig}"; } "/nix/var/nix/profiles/per-user/root/channels" "$HOME/.nix-defexpr/channels" ]; + example = + [ { trunk = "/src/nixpkgs"; } + ]; description = '' The default Nix expression search path, used by the Nix evaluator to look up paths enclosed in angle brackets (e.g. <nixpkgs>). + + Named entries can be specified using an attribute set, if an + entry is configured multiple times the value with the lowest + ordering will be used. ''; }; }; @@ -342,6 +369,7 @@ in "/nix/var/nix/profiles/per-user/root/channels" ]); + nix.package = mkIf (config.system.stateVersion < 3) (mkDefault "/nix/var/nix/profiles/default");