summary refs log tree commit diff
path: root/nixos/modules/config
diff options
context:
space:
mode:
authorNicolas Pierron <nicolas.b.pierron@gmail.com>2014-08-29 22:38:12 +0200
committerNicolas Pierron <nicolas.b.pierron@gmail.com>2014-09-07 19:41:00 +0200
commitbecde6132bf4847b80666aecb619032c286cc733 (patch)
tree63e43850803a2d04393b0108d7e45f429f8718e9 /nixos/modules/config
parent388b7baa735612aab9080b0c612e3a5085912207 (diff)
downloadnixlib-becde6132bf4847b80666aecb619032c286cc733.tar
nixlib-becde6132bf4847b80666aecb619032c286cc733.tar.gz
nixlib-becde6132bf4847b80666aecb619032c286cc733.tar.bz2
nixlib-becde6132bf4847b80666aecb619032c286cc733.tar.lz
nixlib-becde6132bf4847b80666aecb619032c286cc733.tar.xz
nixlib-becde6132bf4847b80666aecb619032c286cc733.tar.zst
nixlib-becde6132bf4847b80666aecb619032c286cc733.zip
Replace environment.profileVariables by environment.profileRelativeEnvVars
Diffstat (limited to 'nixos/modules/config')
-rw-r--r--nixos/modules/config/shells-environment.nix43
1 files changed, 25 insertions, 18 deletions
diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix
index 2559c53ac163..e5b342afcc41 100644
--- a/nixos/modules/config/shells-environment.nix
+++ b/nixos/modules/config/shells-environment.nix
@@ -9,6 +9,23 @@ let
 
   cfg = config.environment;
 
+  exportedEnvVars =
+    let
+      absoluteVariables =
+        mapAttrs (n: toList) cfg.variables;
+
+      suffixedVariables =
+        flip mapAttrs cfg.profileRelativeEnvVars (envVar: listSuffixes:
+          concatMap (profile: map (suffix: "${profile}${suffix}") listSuffixes) cfg.profiles
+        );
+
+      allVariables =
+        zipAttrsWith (n: concatLists) [ absoluteVariables suffixedVariables ];
+
+      exportVariables =
+        mapAttrsToList (n: v: ''export ${n}="${concatStringsSep ":" v}"'') allVariables;
+    in
+      concatStringsSep "\n" exportVariables;
 in
 
 {
@@ -49,22 +66,15 @@ in
       type = types.listOf types.string;
     };
 
-    environment.profileVariables = mkOption {
-      default = (p: {});
+    environment.profileRelativeEnvVars = mkOption {
+      type = types.attrsOf (types.listOf types.str);
+      example = { PATH = [ "/bin" "/sbin" ]; MANPATH = [ "/man" "/share/man" ]; };
       description = ''
-        A function which given a profile path should give back
-        a set of environment variables for that profile.
+	Attribute set of environment variable.  Each attribute maps to a list
+	of relative paths.  Each relative path is appended to the each profile
+        of <option>environment.profiles</option> to form the content of the
+        corresponding environment variable.
       '';
-      # !!! this should be of the following type:
-      #type = types.functionTo (types.attrsOf (types.optionSet envVar));
-      # and envVar should be changed to something more like environOpts.
-      # Having unique `value' _or_ multiple `list' is much more useful
-      # than just sticking everything together with ':' unconditionally.
-      # Anyway, to have this type mentioned above
-      # types.optionSet needs to be transformed into a type constructor
-      # (it has a !!! mark on that in nixpkgs)
-      # for now we hack all this to be
-      type = types.functionTo (types.attrsOf (types.listOf types.string));
     };
 
     # !!! isn't there a better way?
@@ -165,10 +175,7 @@ in
 
     system.build.setEnvironment = pkgs.writeText "set-environment"
        ''
-         ${concatStringsSep "\n" (
-           (mapAttrsToList (n: v: ''export ${n}="${concatStringsSep ":" v}"'')
-             # This line is a kind of a hack because of !!! note above
-             (zipAttrsWith (const concatLists) ([ (mapAttrs (n: v: [ v ]) cfg.variables) ] ++ map cfg.profileVariables cfg.profiles))))}
+         ${exportedEnvVars}
 
          ${cfg.extraInit}