Skip to content

Commit 113e4cc

Browse files
committed
don't inherit PATH from host if the guest system != host system, add an option for it
Same logic as we do elsewhere, surprised this didn't come up before.
1 parent 02a27f5 commit 113e4cc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

share/modules/nixos-shell-config.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ let
44
cfg = config.nixos-shell;
55
home = builtins.getEnv "HOME";
66
mkVMDefault = lib.mkOverride 900;
7+
foreignVM = options.virtualisation.host.pkgs.isDefined && config.virtualisation.host.pkgs.stdenv.hostPlatform != pkgs.stdenv.hostPlatform;
78
in {
89
config =
910
let
@@ -95,7 +96,7 @@ in {
9596
cfg.mounts.extraMounts);
9697

9798
# avoid leaking incompatible host binaries into the VM
98-
system.activationScripts.shadow-nix-profile = lib.mkIf (options.virtualisation.host.pkgs.isDefined && config.virtualisation.host.pkgs.stdenv.hostPlatform != pkgs.stdenv.hostPlatform) (lib.stringAfter [ "specialfs" "users" "groups" ] ''
99+
system.activationScripts.shadow-nix-profile = lib.mkIf foreignVM (lib.stringAfter [ "specialfs" "users" "groups" ] ''
99100
mkdir -p ${lib.escapeShellArg home}/.nix-profile/
100101
mount --bind ${config.system.path} ${lib.escapeShellArg home}/.nix-profile/
101102
'');
@@ -117,7 +118,7 @@ in {
117118
118119
${lib.optionalString (pwd != "") "cd '${pwd}' 2>/dev/null"}
119120
${lib.optionalString (term != "") "export TERM='${term}'"}
120-
${lib.optionalString (path != "") "export PATH=\"${path}:$PATH\""}
121+
${lib.optionalString (cfg.inheritPath && path != "") "export PATH=\"${path}:$PATH\""}
121122
'';
122123
};
123124

share/modules/nixos-shell.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
];
77

88
options.nixos-shell = with lib; {
9+
inheritPath = mkOption {
10+
type = types.bool;
11+
default = options.virtualisation.host.pkgs.isDefined && config.virtualisation.host.pkgs.stdenv.hostPlatform == pkgs.stdenv.hostPlatform;
12+
description = "Whether to inherit the user's PATH.";
13+
};
14+
915
mounts = let
1016
cache = mkOption {
1117
type = types.enum ["none" "loose" "fscache" "mmap"];

0 commit comments

Comments
 (0)