1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-31 04:04:45 +00:00

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.
This commit is contained in:
Daiderd Jordan 2019-05-01 12:30:00 +02:00
parent 51ecc4151f
commit 4d235b800d
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -311,17 +311,44 @@ in
}; };
nix.nixPath = mkOption { 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 = default =
[ # Include default path <darwin-config>. [ # Include default path <darwin-config>.
"darwin-config=${config.environment.darwinConfig}" { darwin-config = "${config.environment.darwinConfig}"; }
"/nix/var/nix/profiles/per-user/root/channels" "/nix/var/nix/profiles/per-user/root/channels"
"$HOME/.nix-defexpr/channels" "$HOME/.nix-defexpr/channels"
]; ];
example =
[ { trunk = "/src/nixpkgs"; }
];
description = '' description = ''
The default Nix expression search path, used by the Nix The default Nix expression search path, used by the Nix
evaluator to look up paths enclosed in angle brackets evaluator to look up paths enclosed in angle brackets
(e.g. <literal>&lt;nixpkgs&gt;</literal>). (e.g. <literal>&lt;nixpkgs&gt;</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/var/nix/profiles/per-user/root/channels"
]); ]);
nix.package = mkIf (config.system.stateVersion < 3) nix.package = mkIf (config.system.stateVersion < 3)
(mkDefault "/nix/var/nix/profiles/default"); (mkDefault "/nix/var/nix/profiles/default");