Skip to content

Commit

Permalink
only set default values for nix-path if nothing else is set
Browse files Browse the repository at this point in the history
TODO: this doesn't work yet.
we currently have no way of checking if a config value was set or not.

this is the expected behavior for default values:
new values should override them, not prepend.

the change fixes a logic bug introduced when fixing the previously confused
override mechanism in e062021.
  • Loading branch information
fricklerhandwerk committed Sep 4, 2024
1 parent 668d63d commit 9eb6355
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
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
6 changes: 6 additions & 0 deletions tests/functional/nix_path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ done
# finding something that's not in any of the default paths fails
( ! $(nix-instantiate --find-file test) )

# 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 ]]

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

# Use nix.conf in absence of NIX_PATH
Expand Down

0 comments on commit 9eb6355

Please sign in to comment.