Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ NIX_USERNAME := $(shell \
else \
echo "$(shell whoami)"; \
fi)
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || echo "not_found")
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The command -v nix >/dev/null 2>&1 check, while useful for detecting the nix executable, only verifies its presence in the PATH. Unlike sourcing the profile scripts (. ~/.nix-profile/... or . /nix/var/nix/profiles/...), it does not ensure that the necessary Nix environment variables (like NIX_PATH) are correctly set up. If only this check succeeds, the NIX_ENV variable will be empty, which the nix-check target interprets as a functional Nix environment. This could lead to subsequent Nix commands failing due to an incomplete environment setup, even though nix-check passes.

To make this fallback more robust, consider replacing command -v nix >/dev/null 2>&1 with a check that also verifies basic Nix functionality, such as nix --version >/dev/null 2>&1. This would ensure that if nix is found, it is also capable of executing basic commands, implying a more complete environment.

NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || nix --version >/dev/null 2>&1 || echo "not_found")

Copilot AI Mar 19, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIX_ENV is computed with :=, so it’s evaluated once when Make parses the file. If make nix-setup runs on a machine without Nix, nix-install can install Nix but nix-check will still see the original NIX_ENV=not_found and fail in the same invocation. Also, sourcing nix.sh/nix-daemon.sh inside $(shell ...) can’t actually set environment for later Make recipes (it runs in a subshell), so this variable is effectively just a presence check.

Consider moving the detection into the nix-check/nix-install recipes (e.g., command -v nix), or change NIX_ENV to a recursively-expanded variable (=) / function so it’s evaluated at use time and reflects installs done earlier in the same make run.

Suggested change
NIX_ENV := $(shell . ~/.nix-profile/etc/profile.d/nix.sh 2>/dev/null || . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh 2>/dev/null || command -v nix >/dev/null 2>&1 || echo "not_found")
NIX_ENV = $(shell command -v nix >/dev/null 2>&1 || echo "not_found")

Copilot uses AI. Check for mistakes.
NIX_FLAGS := --extra-experimental-features 'flakes nix-command' --no-pure-eval --impure
# Only add cache options when user is trusted or on Darwin/CI (avoids "ignoring untrusted substituter" warnings)
ifeq ($(OS),Darwin)
Expand Down
Loading