mirror of
https://github.com/NixOS/nix.git
synced 2025-11-19 00:39:37 +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 { };
|
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.
|
Checks for our packaging expressions.
|
||||||
This shouldn't build anything significant; just check that things
|
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
|
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);
|
storeFS->mount(CanonPath(store->printStorePath(storePath)), accessor);
|
||||||
|
|
||||||
if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash()) {
|
if (requireLockable && (!settings.lazyTrees || !input.isLocked()) && !input.getNarHash())
|
||||||
// FIXME: use fetchToStore to make it cache this
|
input.attrs.insert_or_assign("narHash", getNarHash()->to_string(HashFormat::SRI, true));
|
||||||
auto narHash = accessor->hashPath(CanonPath::root);
|
|
||||||
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: what to do with the NAR hash in lazy mode?
|
if (originalInput.getNarHash() && *getNarHash() != *originalInput.getNarHash())
|
||||||
if (!settings.lazyTrees && originalInput.getNarHash()) {
|
throw Error(
|
||||||
auto expected = originalInput.computeStorePath(*store);
|
(unsigned int) 102,
|
||||||
if (storePath != expected)
|
"NAR hash mismatch in input '%s', expected '%s' but got '%s'",
|
||||||
throw Error(
|
originalInput.to_string(),
|
||||||
(unsigned int) 102,
|
getNarHash()->to_string(HashFormat::SRI, true),
|
||||||
"NAR hash mismatch in input '%s', expected '%s' but got '%s'",
|
originalInput.getNarHash()->to_string(HashFormat::SRI, true));
|
||||||
originalInput.to_string(),
|
|
||||||
store->printStorePath(storePath),
|
|
||||||
store->printStorePath(expected));
|
|
||||||
}
|
|
||||||
|
|
||||||
return storePath;
|
return storePath;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -882,7 +882,8 @@ struct GitInputScheme : InputScheme
|
||||||
|
|
||||||
bool isLocked(const Input & input) const override
|
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
|
show-trace = true
|
||||||
include nix.conf.extra
|
include nix.conf.extra
|
||||||
trusted-users = $(whoami)
|
trusted-users = $(whoami)
|
||||||
|
${_NIX_TEST_EXTRA_CONFIG:-}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
cat > "$NIX_CONF_DIR"/nix.conf.extra <<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'.
|
# Test 'nix flake metadata --json'.
|
||||||
json=$(nix flake metadata flake1 --json | jq .)
|
json=$(nix flake metadata flake1 --json | jq .)
|
||||||
[[ $(echo "$json" | jq -r .description) = 'Bla bla' ]]
|
[[ $(echo "$json" | jq -r .description) = 'Bla bla' ]]
|
||||||
[[ -d $(echo "$json" | jq -r .path) ]]
|
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) ]]
|
[[ $(echo "$json" | jq -r .lastModified) = $(git -C "$flake1Dir" log -n1 --format=%ct) ]]
|
||||||
hash1=$(echo "$json" | jq -r .revision)
|
hash1=$(echo "$json" | jq -r .revision)
|
||||||
[[ -n $(echo "$json" | jq -r .fingerprint) ]]
|
[[ -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
|
nix build -o "$TEST_ROOT/result" "$flake2Dir#bar" --commit-lock-file
|
||||||
[[ -e "$flake2Dir/flake.lock" ]]
|
[[ -e "$flake2Dir/flake.lock" ]]
|
||||||
[[ -z $(git -C "$flake2Dir" diff main || echo failed) ]]
|
[[ -z $(git -C "$flake2Dir" diff main || echo failed) ]]
|
||||||
[[ $(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}'$ ]]
|
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.
|
# Rerunning the build should not change the lockfile.
|
||||||
nix build -o "$TEST_ROOT/result" "$flake2Dir#bar"
|
nix build -o "$TEST_ROOT/result" "$flake2Dir#bar"
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@
|
||||||
|
|
||||||
# For running the functional tests against a different pre-built Nix.
|
# For running the functional tests against a different pre-built Nix.
|
||||||
test-daemon ? null,
|
test-daemon ? null,
|
||||||
|
|
||||||
|
# Whether to run tests with lazy trees enabled.
|
||||||
|
lazyTrees ? false,
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
@ -95,6 +98,8 @@ mkMesonDerivation (
|
||||||
mkdir $out
|
mkdir $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
_NIX_TEST_EXTRA_CONFIG = lib.optionalString lazyTrees "lazy-trees = true";
|
||||||
|
|
||||||
meta = {
|
meta = {
|
||||||
platforms = lib.platforms.unix;
|
platforms = lib.platforms.unix;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue