Skip to content

Commit 6405472

Browse files
authored
Merge pull request #360 from DeterminateSystems/hashString-devirtualize
builtins.hashString: Devirtualize lazy paths, and re-enable lazy trees tests
2 parents 9438dff + 5d6ab84 commit 6405472

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

ci/gha/tests/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ rec {
8282
'';
8383
repl-completion = pkgs.callPackage ../../../tests/repl-completion.nix { inherit (packages') nix; };
8484

85+
lazyTrees = nixComponents.nix-functional-tests.override {
86+
pname = "nix-lazy-trees-tests";
87+
lazyTrees = true;
88+
};
89+
8590
/**
8691
Checks for our packaging expressions.
8792
This shouldn't build anything significant; just check that things

src/libexpr/primops.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,8 +4741,9 @@ static void prim_hashString(EvalState & state, const PosIdx pos, Value ** args,
47414741
state.error<EvalError>("unknown hash algorithm '%1%'", algo).atPos(pos).debugThrow();
47424742

47434743
NixStringContext context; // discarded
4744-
auto s =
4745-
state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");
4744+
auto s = state.devirtualize(
4745+
state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString"),
4746+
context);
47464747

47474748
v.mkString(hashString(*ha, s).to_string(HashFormat::Base16, false), state.mem);
47484749
}

src/nix/app.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ UnresolvedApp InstallableValue::toApp(EvalState & state)
9090
},
9191
[&](const NixStringContextElem::Opaque & o) -> DerivedPath {
9292
return DerivedPath::Opaque{
93-
.path = o.path,
93+
.path = state.devirtualize(o.path),
9494
};
9595
},
9696
[&](const NixStringContextElem::Path & p) -> DerivedPath {
@@ -102,7 +102,7 @@ UnresolvedApp InstallableValue::toApp(EvalState & state)
102102

103103
return UnresolvedApp{App{
104104
.context = std::move(context2),
105-
.program = program,
105+
.program = state.devirtualize(program, context),
106106
}};
107107
}
108108

tests/functional/fetchGit.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,17 @@ rm "$TEST_ROOT"/flake/flake.lock
363363
nix eval "path:$TEST_ROOT/flake"#isModern
364364
nix eval --nix-219-compat "path:$TEST_ROOT/flake"#isModern
365365
[[ $(jq -r .nodes.eol.locked.narHash < "$TEST_ROOT"/flake/flake.lock) = "$newHash" ]]
366+
367+
368+
# Test that builtins.hashString devirtualizes lazy paths (https://github.com/DeterminateSystems/determinate/issues/160).
369+
hashStringRepo="$TEST_ROOT/hashString"
370+
createGitRepo "$hashStringRepo"
371+
echo hello > "$hashStringRepo"/hello
372+
git -C "$hashStringRepo" add hello
373+
git -C "$hashStringRepo" commit -m 'Initial'
374+
hashStringRev=$(git -C "$hashStringRepo" rev-parse HEAD)
375+
376+
hash1=$(nix eval --lazy-trees --raw --expr "builtins.hashString \"sha256\" (toString ((builtins.fetchGit { url = file://$hashStringRepo; rev = \"$hashStringRev\"; })))")
377+
hash2=$(nix eval --lazy-trees --raw --expr "builtins.hashString \"sha256\" (toString ((builtins.fetchGit { url = file://$hashStringRepo; rev = \"$hashStringRev\"; })))")
378+
379+
[[ "$hash1" = "$hash2" ]]

0 commit comments

Comments
 (0)