Skip to content

Commit

Permalink
Merge pull request #956 from amarshall/systempath-order
Browse files Browse the repository at this point in the history
environment: Adjust systemPath order to allow injecting in the middle
  • Loading branch information
Enzime authored May 24, 2024
2 parents eac4f25 + 7f89700 commit 0bea822
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion modules/environment/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ in

config = {

environment.systemPath = [ (makeBinPath cfg.profiles) "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" ];
environment.systemPath = mkMerge [
[ (makeBinPath cfg.profiles) ]
(mkOrder 1200 [ "/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" ])
];

# Use user, default and system profiles.
environment.profiles = mkMerge [
Expand Down
34 changes: 30 additions & 4 deletions tests/environment-path.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,37 @@
with lib;

{
environment.systemPath = mkMerge [
(mkBefore [ "beforePath" ])
[ "myPath" ]
(mkAfter [ "afterPath" ])
];

environment.profiles = mkMerge [
(mkBefore [ "beforeProfile" ])
[ "myProfile" ]
(mkAfter [ "afterProfile" ])
];

test = ''
echo checking /run/current-system/sw/bin in environment >&2
grep 'export PATH=.*:/run/current-system/sw/bin' ${config.system.build.setEnvironment}
echo 'checking PATH' >&2
env_path=$(bash -c 'source ${config.system.build.setEnvironment}; echo $PATH')
echo checking /bin and /sbin in environment >&2
grep 'export PATH=.*:/usr/bin:/usr/sbin:/bin:/sbin' ${config.system.build.setEnvironment}
test "$env_path" = "${builtins.concatStringsSep ":" [
"beforePath"
"myPath"
"beforeProfile/bin"
"/homeless-shelter/.nix-profile/bin"
"myProfile/bin"
"/run/current-system/sw/bin"
"/nix/var/nix/profiles/default/bin"
"afterProfile/bin"
"/usr/local/bin"
"/usr/bin"
"/usr/sbin"
"/bin"
"/sbin"
"afterPath"
]}"
'';
}

0 comments on commit 0bea822

Please sign in to comment.