mirror of
https://github.com/NixOS/nix.git
synced 2025-11-18 00:12:43 +01:00
Merge pull request #105 from DeterminateSystems/run-lazy-trees-tests
Run the Nix test suite with lazy trees enabled
This commit is contained in:
commit
46c1a714ba
6 changed files with 43 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -77,25 +77,31 @@ StorePath EvalState::mountInput(
|
|||
|
||||
allowPath(storePath); // FIXME: should just whitelist the entire virtual store
|
||||
|
||||
std::optional<Hash> _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)
|
||||
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(),
|
||||
store->printStorePath(storePath),
|
||||
store->printStorePath(expected));
|
||||
}
|
||||
getNarHash()->to_string(HashFormat::SRI, true),
|
||||
originalInput.getNarHash()->to_string(HashFormat::SRI, true));
|
||||
|
||||
return storePath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <<EOF
|
||||
|
|
|
|||
|
|
@ -69,7 +69,9 @@ nix flake metadata "$flake1Dir" | grepQuiet 'URL:.*flake1.*'
|
|||
# Test 'nix flake metadata --json'.
|
||||
json=$(nix flake metadata flake1 --json | jq .)
|
||||
[[ $(echo "$json" | jq -r .description) = 'Bla bla' ]]
|
||||
if [[ $(nix config show lazy-trees) = false ]]; then
|
||||
[[ -d $(echo "$json" | jq -r .path) ]]
|
||||
fi
|
||||
[[ $(echo "$json" | jq -r .lastModified) = $(git -C "$flake1Dir" log -n1 --format=%ct) ]]
|
||||
hash1=$(echo "$json" | jq -r .revision)
|
||||
[[ -n $(echo "$json" | jq -r .fingerprint) ]]
|
||||
|
|
@ -161,7 +163,11 @@ expect 1 nix build -o "$TEST_ROOT/result" "$flake2Dir#bar" --no-update-lock-file
|
|||
nix build -o "$TEST_ROOT/result" "$flake2Dir#bar" --commit-lock-file
|
||||
[[ -e "$flake2Dir/flake.lock" ]]
|
||||
[[ -z $(git -C "$flake2Dir" diff main || echo failed) ]]
|
||||
if [[ $(nix config show lazy-trees) = false ]]; then
|
||||
[[ $(jq --indent 0 . < "$flake2Dir/flake.lock") =~ ^'{"nodes":{"flake1":{"locked":{"lastModified":'.*',"narHash":"sha256-'.*'","ref":"refs/heads/master","rev":"'.*'","revCount":2,"type":"git","url":"file:///'.*'"},"original":{"id":"flake1","type":"indirect"}},"root":{"inputs":{"flake1":"flake1"}}},"root":"root","version":7}'$ ]]
|
||||
else
|
||||
[[ $(jq --indent 0 . < "$flake2Dir/flake.lock") =~ ^'{"nodes":{"flake1":{"locked":{"lastModified":'.*',"ref":"refs/heads/master","rev":"'.*'","revCount":2,"type":"git","url":"file:///'.*'"},"original":{"id":"flake1","type":"indirect"}},"root":{"inputs":{"flake1":"flake1"}}},"root":"root","version":7}'$ ]]
|
||||
fi
|
||||
|
||||
# Rerunning the build should not change the lockfile.
|
||||
nix build -o "$TEST_ROOT/result" "$flake2Dir#bar"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@
|
|||
|
||||
# For running the functional tests against a different pre-built Nix.
|
||||
test-daemon ? null,
|
||||
|
||||
# Whether to run tests with lazy trees enabled.
|
||||
lazyTrees ? false,
|
||||
}:
|
||||
|
||||
let
|
||||
|
|
@ -95,6 +98,8 @@ mkMesonDerivation (
|
|||
mkdir $out
|
||||
'';
|
||||
|
||||
_NIX_TEST_EXTRA_CONFIG = lib.optionalString lazyTrees "lazy-trees = true";
|
||||
|
||||
meta = {
|
||||
platforms = lib.platforms.unix;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue