diff --git a/flake.nix b/flake.nix index b5fa93e58..0207134cd 100644 --- a/flake.nix +++ b/flake.nix @@ -220,6 +220,11 @@ ''; repl-completion = nixpkgsFor.${system}.native.callPackage ./tests/repl-completion.nix { }; + lazyTrees = nixpkgsFor.${system}.native.nixComponents2.nix-functional-tests.override { + pname = "nix-lazy-trees-tests"; + lazyTrees = true; + }; + /** Checks for our packaging expressions. This shouldn't build anything significant; just check that things diff --git a/src/libexpr/paths.cc b/src/libexpr/paths.cc index 40c0a23b6..65b8212e1 100644 --- a/src/libexpr/paths.cc +++ b/src/libexpr/paths.cc @@ -77,25 +77,31 @@ StorePath EvalState::mountInput( allowPath(storePath); // FIXME: should just whitelist the entire virtual store + std::optional _narHash; + + auto getNarHash = [&]() { + if (!_narHash) { + if (store->isValidPath(storePath)) + _narHash = store->queryPathInfo(storePath)->narHash; + else + // FIXME: use fetchToStore to make it cache this + _narHash = accessor->hashPath(CanonPath::root); + } + return _narHash; + }; + storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor); - if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash()) { - // FIXME: use fetchToStore to make it cache this - auto narHash = accessor->hashPath(CanonPath::root); - input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true)); - } + if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash()) + input.attrs.insert_or_assign("narHash", getNarHash()->to_string(HashFormat::SRI, true)); - // FIXME: what to do with the NAR hash in lazy mode? - if (!settings.lazyTrees && originalInput.getNarHash()) { - auto expected = originalInput.computeStorePath(*store); - if (storePath != expected) - throw Error( - (unsigned int) 102, - "NAR hash mismatch in input '%s', expected '%s' but got '%s'", - originalInput.to_string(), - store->printStorePath(storePath), - store->printStorePath(expected)); - } + if (originalInput.getNarHash() && *getNarHash() != *originalInput.getNarHash()) + throw Error( + (unsigned int) 102, + "NAR hash mismatch in input '%s', expected '%s' but got '%s'", + originalInput.to_string(), + getNarHash()->to_string(HashFormat::SRI, true), + originalInput.getNarHash()->to_string(HashFormat::SRI, true)); return storePath; } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 7730e0db4..2825b72ab 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -882,7 +882,8 @@ struct GitInputScheme : InputScheme bool isLocked(const Input & input) const override { - return (bool) input.getRev(); + auto rev = input.getRev(); + return rev && rev != nullRev; } }; diff --git a/tests/functional/common/init.sh b/tests/functional/common/init.sh index 6e9bffec5..7f28a09d7 100755 --- a/tests/functional/common/init.sh +++ b/tests/functional/common/init.sh @@ -54,6 +54,7 @@ flake-registry = $TEST_ROOT/registry.json show-trace = true include nix.conf.extra trusted-users = $(whoami) +${_NIX_TEST_EXTRA_CONFIG:-} EOF cat > "$NIX_CONF_DIR"/nix.conf.extra <