Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only set default values for nix-path if nothing else is set #11429

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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 src/libexpr/eval-gc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void initGC()
#endif

// NIX_PATH must override the regular setting
// See the comment in applyConfig
// See the XXX comment in `applyConfig()`
if (auto nixPathEnv = getEnv("NIX_PATH")) {
globalConfig.set("nix-path", concatStringsSep(" ", EvalSettings::parseNixPath(nixPathEnv.value())));
}
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ EvalState::EvalState(
for (auto & i : settings.nixPath.get()) {
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
}
// TODO: only set if nothing else is
if (!settings.restrictEval) {
for (auto & i : EvalSettings::getDefaultNixPath()) {
lookupPath.elements.emplace_back(LookupPath::Elem::parse(i));
Expand Down
13 changes: 13 additions & 0 deletions tests/functional/nix_path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ done
# finding something that's not in any of the default paths fails
( ! $(nix-instantiate --find-file test) )

# XXX: we can't manipulate $NIX_STATE_DIR contents on NixOS
# TODO: port to NixOS somehow; ideally we'd run the test suite in a non-NixOS VM
if [[ ! isTestOnNixOS ]]; then
mkdir -p $NIX_STATE_DIR/profiles/per-user/root/channels/nixpkgs
# check that the default values are set
[[ $(nix-instantiate --eval -E 'with builtins; length nixPath') = 2 ]]
# setting anything overrides the default paths
# this ensures we can force an empty search path
[[ $(NIX_PATH= nix-instantiate --eval -E 'with builtins; length nixPath') = 0 ]]
[[ $(nix-instantiate --nix-path "" --eval -E 'with builtins; length nixPath') = 0 ]]
[[ $(nix-instantiate -I "" --eval -E 'with builtins; length nixPath') = 1 ]]
fi

echo "nix-path = test=$TEST_ROOT/from-nix-path-file" >> "$test_nix_conf"

# Use nix.conf in absence of NIX_PATH
Expand Down
Loading