mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02:00
EvalState::mountInput(): Throw an error if there is a NAR hash mismatch
This commit is contained in:
parent
630bdff7e9
commit
91cde8c79d
2 changed files with 12 additions and 5 deletions
|
@ -83,8 +83,16 @@ StorePath EvalState::mountInput(
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: what to do with the NAR hash in lazy mode?
|
// FIXME: what to do with the NAR hash in lazy mode?
|
||||||
if (!settings.lazyTrees)
|
if (!settings.lazyTrees && originalInput.getNarHash()) {
|
||||||
assert(!originalInput.getNarHash() || storePath == originalInput.computeStorePath(*store));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
return storePath;
|
return storePath;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,14 +142,13 @@ path4=$(nix eval --impure --refresh --raw --expr "(builtins.fetchGit file://$rep
|
||||||
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyRev\" (builtins.fetchGit $repo)") == "false" ]]
|
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyRev\" (builtins.fetchGit $repo)") == "false" ]]
|
||||||
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyShortRev\" (builtins.fetchGit $repo)") == "false" ]]
|
[[ $(nix eval --impure --expr "builtins.hasAttr \"dirtyShortRev\" (builtins.fetchGit $repo)") == "false" ]]
|
||||||
|
|
||||||
# FIXME: check narHash
|
expect 102 nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-B5yIPHhEm0eysJKEsO7nqxprh9vcblFxpJG11gXJus1=\"; }).outPath"
|
||||||
#expect 102 nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-B5yIPHhEm0eysJKEsO7nqxprh9vcblFxpJG11gXJus1=\"; }).outPath"
|
|
||||||
|
|
||||||
path5=$(nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath")
|
path5=$(nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath")
|
||||||
[[ $path = $path5 ]]
|
[[ $path = $path5 ]]
|
||||||
|
|
||||||
# Ensure that NAR hashes are checked.
|
# Ensure that NAR hashes are checked.
|
||||||
#expectStderr 102 nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-Hr8g6AqANb4xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath" | grepQuiet "error: NAR hash mismatch"
|
expectStderr 102 nix eval --raw --expr "(builtins.fetchGit { url = $repo; rev = \"$rev2\"; narHash = \"sha256-Hr8g6AqANb4xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath" | grepQuiet "error: NAR hash mismatch"
|
||||||
|
|
||||||
# It's allowed to use only a narHash, but you should get a warning.
|
# It's allowed to use only a narHash, but you should get a warning.
|
||||||
expectStderr 0 nix eval --raw --expr "(builtins.fetchGit { url = $repo; ref = \"tag2\"; narHash = \"sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath" | grepQuiet "warning: Input .* is unlocked"
|
expectStderr 0 nix eval --raw --expr "(builtins.fetchGit { url = $repo; ref = \"tag2\"; narHash = \"sha256-Hr8g6AqANb3xqX28eu1XnjK/3ab8Gv6TJSnkb1LezG9=\"; }).outPath" | grepQuiet "warning: Input .* is unlocked"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue