From 9b6f77200f8a88c8b5e5da47e90b73f86aab27b9 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Wed, 22 May 2024 13:34:01 -0400 Subject: [PATCH 1/3] environment: Rework test to assert against full $PATH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s deterministic after all, so test against the full thing for greater flexibility in testing and confidence in lack of unexpected changes to previously-untested parts of the default $PATH. Do this in a subshell to avoid polluting the test script’s environment. --- tests/environment-path.nix | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/environment-path.nix b/tests/environment-path.nix index 7d2f46dd9..5ddaf9c96 100644 --- a/tests/environment-path.nix +++ b/tests/environment-path.nix @@ -4,10 +4,18 @@ with lib; { 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 ":" [ + "/homeless-shelter/.nix-profile/bin" + "/run/current-system/sw/bin" + "/nix/var/nix/profiles/default/bin" + "/usr/local/bin" + "/usr/bin" + "/usr/sbin" + "/bin" + "/sbin" + ]}" ''; } From bd0ed8599fd4871e79543e09075dac2c2c25ff2a Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Wed, 22 May 2024 13:43:33 -0400 Subject: [PATCH 2/3] environment: Test how order of systemPath and profiles manifests --- tests/environment-path.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/environment-path.nix b/tests/environment-path.nix index 5ddaf9c96..0bb9a0558 100644 --- a/tests/environment-path.nix +++ b/tests/environment-path.nix @@ -3,19 +3,37 @@ with lib; { + environment.systemPath = mkMerge [ + (mkBefore [ "beforePath" ]) + [ "myPath" ] + (mkAfter [ "afterPath" ]) + ]; + + environment.profiles = mkMerge [ + (mkBefore [ "beforeProfile" ]) + [ "myProfile" ] + (mkAfter [ "afterProfile" ]) + ]; + test = '' echo 'checking PATH' >&2 env_path=$(bash -c 'source ${config.system.build.setEnvironment}; echo $PATH') 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" ]}" ''; } From 7f897008d4f3c7dda86e19106169eb947a0ac308 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Wed, 22 May 2024 09:41:12 -0400 Subject: [PATCH 3/3] environment: Adjust systemPath order to allow injecting in the middle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, it was not possible to inject PATH entries between profiles and the “default system” PATH entries. This confounds adding, e.g. Homebrew on aarch64’s non-standard prefix as higher priority than the builtin system paths, but lower than Nix profiles. This is a backwards-incompatible change for some users, but should only be so in the case a user used `mkOrder` with a value between 1000 (the default priority) and 1200. Value of 1200 chosen as the same delta from the default as just below in `environment.profiles` (which uses 800), and mkAfter is 1500 so will still go after this. --- modules/environment/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/environment/default.nix b/modules/environment/default.nix index 753ee311f..bb996222f 100644 --- a/modules/environment/default.nix +++ b/modules/environment/default.nix @@ -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 [