diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2019-05-01 12:30:00 +0200 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2019-05-01 12:30:00 +0200 |
| commit | 4d235b800d2add9adba90686bcadbf4f1beb5d9c (patch) | |
| tree | d3614d6e58e46774af022726de0aeb8baa9ef3e5 /modules | |
| parent | 51ecc4151f3dd5ae92c6eba5824ca77b72faa6df (diff) | |
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.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/nix/default.nix | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/modules/nix/default.nix b/modules/nix/default.nix index 6ad33ba..9db2371 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>. - "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. <literal><nixpkgs></literal>). + + 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"); |
