From 02232f71c5712d08d6fb9d0dbedec50509cebbba Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 11 Jan 2025 15:44:41 +0000 Subject: [PATCH 1/4] nix-tools: drop `nixPackage` We already put `/nix/var/nix/profiles/default/bin` on the `$PATH`, and whatever `nix.package` is set to already gets installed into `/run/current-system/sw/bin`, so this is pointless. --- modules/nix/nix-darwin.nix | 1 - pkgs/nix-tools/default.nix | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/nix/nix-darwin.nix b/modules/nix/nix-darwin.nix index 4a989d79..4fed9fda 100644 --- a/modules/nix/nix-darwin.nix +++ b/modules/nix/nix-darwin.nix @@ -4,7 +4,6 @@ let nix-tools = pkgs.callPackage ../../pkgs/nix-tools { inherit (config.system) profile; inherit (config.environment) systemPath; - nixPackage = config.nix.package; }; darwin-uninstaller = pkgs.callPackage ../../pkgs/darwin-uninstaller { }; diff --git a/pkgs/nix-tools/default.nix b/pkgs/nix-tools/default.nix index 4a496bb1..449a8c4d 100644 --- a/pkgs/nix-tools/default.nix +++ b/pkgs/nix-tools/default.nix @@ -5,12 +5,11 @@ , substituteAll , stdenv , profile ? "/nix/var/nix/profiles/system" -, nixPackage ? "/nix/var/nix/profiles/default" , systemPath ? "$HOME/.nix-profile/bin:/etc/profiles/per-user/$USER/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" }: let - extraPath = lib.makeBinPath [ nixPackage coreutils jq git ]; + extraPath = lib.makeBinPath [ coreutils jq git ]; writeProgram = name: env: src: substituteAll ({ From 3d95b013516aa3c97e645ad803d1a497097dab90 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 18 Jan 2025 20:27:17 +0000 Subject: [PATCH 2/4] nix-tools: make `systemPath` more readable --- pkgs/nix-tools/default.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkgs/nix-tools/default.nix b/pkgs/nix-tools/default.nix index 449a8c4d..582309ef 100644 --- a/pkgs/nix-tools/default.nix +++ b/pkgs/nix-tools/default.nix @@ -5,7 +5,22 @@ , substituteAll , stdenv , profile ? "/nix/var/nix/profiles/system" -, systemPath ? "$HOME/.nix-profile/bin:/etc/profiles/per-user/$USER/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" +, # This should be kept in sync with the default + # `environment.systemPath`. We err on side of including conditional + # things like the profile directories, since they’re more likely to + # help than hurt, and this default is mostly used for fresh + # installations anyway. + systemPath ? lib.concatStringsSep ":" [ + "$HOME/.nix-profile/bin" + "/etc/profiles/per-user/$USER/bin" + "/run/current-system/sw/bin" + "/nix/var/nix/profiles/default/bin" + "/usr/local/bin" + "/usr/bin" + "/bin" + "/usr/sbin" + "/sbin" +] }: let From 4d0ae6980d128baecf7e7f636e4df4a95740d628 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 11 Jan 2025 15:44:41 +0000 Subject: [PATCH 3/4] nix-tools: overwrite `$PATH` rather than prepending MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I don’t see any reason for these scripts to depend on more environmental state than necessary. --- pkgs/nix-tools/darwin-option.sh | 2 +- pkgs/nix-tools/darwin-rebuild.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/nix-tools/darwin-option.sh b/pkgs/nix-tools/darwin-option.sh index 8e40e93c..d4cb5487 100755 --- a/pkgs/nix-tools/darwin-option.sh +++ b/pkgs/nix-tools/darwin-option.sh @@ -1,7 +1,7 @@ #! @shell@ set -e set -o pipefail -export PATH=@path@:$PATH +export PATH=@path@ evalNix() { nix-instantiate --eval --strict "${extraEvalFlags[@]}" -E "with import {}; $*" 2>/dev/null diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index f945e6b4..74ec7ecf 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -1,8 +1,7 @@ #! @shell@ set -e set -o pipefail -export PATH=@path@:$PATH - +export PATH=@path@ showSyntax() { echo "darwin-rebuild [--help] {edit | switch | activate | build | check | changelog}" >&2 From b5b7888793329a8c70c216cae9db8a0180b3dcda Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 11 Jan 2025 15:44:41 +0000 Subject: [PATCH 4/4] nix-tools: set `$NIX_PATH` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be important once most users are running `sudo darwin-rebuild` and therefore not getting their environment’s `$NIX_PATH` passed through. --- modules/nix/nix-darwin.nix | 1 + pkgs/nix-tools/darwin-option.sh | 2 ++ pkgs/nix-tools/darwin-rebuild.sh | 2 ++ pkgs/nix-tools/default.nix | 9 +++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/nix/nix-darwin.nix b/modules/nix/nix-darwin.nix index 4fed9fda..a064f49a 100644 --- a/modules/nix/nix-darwin.nix +++ b/modules/nix/nix-darwin.nix @@ -4,6 +4,7 @@ let nix-tools = pkgs.callPackage ../../pkgs/nix-tools { inherit (config.system) profile; inherit (config.environment) systemPath; + nixPath = lib.concatStringsSep ":" config.nix.nixPath; }; darwin-uninstaller = pkgs.callPackage ../../pkgs/darwin-uninstaller { }; diff --git a/pkgs/nix-tools/darwin-option.sh b/pkgs/nix-tools/darwin-option.sh index d4cb5487..79ecee91 100755 --- a/pkgs/nix-tools/darwin-option.sh +++ b/pkgs/nix-tools/darwin-option.sh @@ -1,7 +1,9 @@ #! @shell@ set -e set -o pipefail + export PATH=@path@ +export NIX_PATH=${NIX_PATH:-@nixPath@} evalNix() { nix-instantiate --eval --strict "${extraEvalFlags[@]}" -E "with import {}; $*" 2>/dev/null diff --git a/pkgs/nix-tools/darwin-rebuild.sh b/pkgs/nix-tools/darwin-rebuild.sh index 74ec7ecf..2e250c5d 100644 --- a/pkgs/nix-tools/darwin-rebuild.sh +++ b/pkgs/nix-tools/darwin-rebuild.sh @@ -1,7 +1,9 @@ #! @shell@ set -e set -o pipefail + export PATH=@path@ +export NIX_PATH=${NIX_PATH:-@nixPath@} showSyntax() { echo "darwin-rebuild [--help] {edit | switch | activate | build | check | changelog}" >&2 diff --git a/pkgs/nix-tools/default.nix b/pkgs/nix-tools/default.nix index 582309ef..8d6b89b7 100644 --- a/pkgs/nix-tools/default.nix +++ b/pkgs/nix-tools/default.nix @@ -21,6 +21,11 @@ "/usr/sbin" "/sbin" ] +, # This should be kept in sync with the default `nix.nixPath`. + nixPath ? lib.concatStringsSep ":" [ + "darwin-config=/etc/nix-darwin/configuration.nix" + "/nix/var/nix/profiles/per-user/root/channels" +] }: let @@ -39,14 +44,14 @@ in { darwin-option = writeProgram "darwin-option" { - inherit path; + inherit path nixPath; inherit (stdenv) shell; } ./darwin-option.sh; darwin-rebuild = writeProgram "darwin-rebuild" { - inherit path profile; + inherit path nixPath profile; inherit (stdenv) shell; postInstall = '' mkdir -p $out/share/zsh/site-functions