nixos/system-environment: replace env vars in values of variables too

We were only replacing them in the profiles. We also need to do this in
the values of variables, including both the session-relative variables
and the non-session-relative variables.
This commit is contained in:
Michael Peyton Jones 2019-09-30 20:41:20 +01:00 committed by worldofpeace
parent 5afde25a10
commit 9d61ddaf82

View File

@ -8,11 +8,6 @@ let
cfg = config.environment;
pamProfiles =
map
(replaceStrings ["$HOME" "$USER"] ["@{HOME}" "@{PAM_USER}"])
cfg.profiles;
in
{
@ -75,13 +70,18 @@ in
let
suffixedVariables =
flip mapAttrs cfg.profileRelativeSessionVariables (envVar: suffixes:
flip concatMap pamProfiles (profile:
flip concatMap cfg.profiles (profile:
map (suffix: "${profile}${suffix}") suffixes
)
);
# We're trying to use the same syntax for PAM variables and env variables.
# That means we need to map the env variables that people might use to their
# equivalent PAM variable.
replaceEnvVars = replaceStrings ["$HOME" "$USER"] ["@{HOME}" "@{PAM_USER}"]
pamVariable = n: v:
''${n} DEFAULT="${concatStringsSep ":" (toList v)}"'';
''${n} DEFAULT="${concatStringsSep ":" (map replaceEnvVars (toList v))}"'';
pamVariables =
concatStringsSep "\n"