From 7648c9befcc011091eccdf48a61a819cc835f2f8 Mon Sep 17 00:00:00 2001 From: Malo Bourgon Date: Sat, 13 Aug 2022 16:41:43 -0700 Subject: [PATCH] Refactor `nix.nixPath` to make diff easier to compare with NixOS module --- modules/nix/default.nix | 55 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/modules/nix/default.nix b/modules/nix/default.nix index 7a4bdae..60f7b4b 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -88,6 +88,29 @@ let in attrsOf (either confAtom (listOf confAtom)); + # Not in NixOS module + nixPathType = 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; + }; + in { @@ -291,37 +314,15 @@ in ''; }; + # Definition differs substantially from NixOS module nixPath = mkOption { - 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 . + type = nixPathType; + default = [ + # Include default path . { 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 @@ -664,7 +665,7 @@ in ]; # Set up the environment variables for running Nix. - environment.variables = cfg.envVars // { NIX_PATH = concatStringsSep ":" cfg.nixPath; }; + environment.variables = cfg.envVars // { NIX_PATH = cfg.nixPath; }; # Unreladed to use in NixOS module environment.extraInit = ''