Skip to content

Commit f3a114e

Browse files
dtzWillgrahamc
authored andcommitted
NIX_PATH: don't prepend $HOME-based value in session variable, set later
environment.sessionVariables cannot refer to the values of env vars, and as a result this has caused problems in a variety of scenarios. One use for these is that they're injected into /etc/profile, elewhere these are used to populate an 'envfile' for pam (`pam 5 pam_env.conf`) which mentions use of HOME being potentially problematic. Anyway if the goal is to make things easier for users, simply do the NIX_PATH modification as extraInit. This fixes the annoying problems generated by the current approach (#40165 and others) while hopefully serving the original goal. One way to check if things are borked is to try: $ sudo env | grep NIX_PATH Which (before this change) prints NIX_PATH variable with an unexpanded $HOME in the value. ------- This does mean the following won't contain user channels for 'will': $ sudo -u will nix-instantiate --eval -E builtins.nixPath However AFAICT currently they won't be present either, due to unescaped $HOME. Unsure if similar situation for other users of sessionVariables (not sudo) work with current situation (if they exist they will regress after this change AFAIK).
1 parent 74df71b commit f3a114e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

nixos/modules/services/misc/nix-daemon.nix

+3-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ in
345345
type = types.listOf types.str;
346346
default =
347347
[
348-
"$HOME/.nix-defexpr/channels"
349348
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
350349
"nixos-config=/etc/nixos/configuration.nix"
351350
"/nix/var/nix/profiles/per-user/root/channels"
@@ -436,7 +435,7 @@ in
436435

437436
# Set up the environment variables for running Nix.
438437
environment.sessionVariables = cfg.envVars //
439-
{ NIX_PATH = concatStringsSep ":" cfg.nixPath;
438+
{ NIX_PATH = cfg.nixPath;
440439
};
441440

442441
environment.extraInit = optionalString (!isNix20)
@@ -446,6 +445,8 @@ in
446445
if [ "$USER" != root -o ! -w /nix/var/nix/db ]; then
447446
export NIX_REMOTE=daemon
448447
fi
448+
'' + ''
449+
export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}"
449450
'';
450451

451452
nix.nrBuildUsers = mkDefault (lib.max 32 cfg.maxJobs);

0 commit comments

Comments
 (0)