From 9d61ddaf822798d0e02092e471060b5ba672f2ab Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Mon, 30 Sep 2019 20:41:20 +0100 Subject: [PATCH 1/2] 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. --- nixos/modules/config/system-environment.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nixos/modules/config/system-environment.nix b/nixos/modules/config/system-environment.nix index 792d1dbb38f6..e934e79e7e8e 100644 --- a/nixos/modules/config/system-environment.nix +++ b/nixos/modules/config/system-environment.nix @@ -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" From d8b9742deb3994018d94fc550e777ea684baca6e Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Mon, 30 Sep 2019 21:01:33 +0100 Subject: [PATCH 2/2] nixos/system-environment: fix syntax for environment variables `@` synax is for `PAM_ITEM`s, `HOME` needs to use `$`. --- nixos/modules/config/system-environment.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/system-environment.nix b/nixos/modules/config/system-environment.nix index e934e79e7e8e..4b663ebf85a4 100644 --- a/nixos/modules/config/system-environment.nix +++ b/nixos/modules/config/system-environment.nix @@ -78,7 +78,9 @@ in # 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}"] + # Note: PAM_USER is a PAM_ITEM, HOME is an environment variable, they have + # different syntax. + replaceEnvVars = replaceStrings ["$HOME" "$USER"] ["\${HOME}" "@{PAM_USER}"]; pamVariable = n: v: ''${n} DEFAULT="${concatStringsSep ":" (map replaceEnvVars (toList v))}"'';