Properly normalize the content-addressed paths

Make sure that their timestamp are always normalized.
Otherwise, strange − and non-deterministic − things might happen, like
https://github.com/NixOS/nixpkgs/issues/121813

Fix #4775
This commit is contained in:
regnat 2021-05-05 21:00:08 +02:00
parent fe3a10a9b2
commit bf485dcf46
3 changed files with 19 additions and 4 deletions

View file

@ -2300,10 +2300,6 @@ void LocalDerivationGoal::registerOutputs()
sink.s = make_ref<std::string>(rewriteStrings(*sink.s, outputRewrites)); sink.s = make_ref<std::string>(rewriteStrings(*sink.s, outputRewrites));
StringSource source(*sink.s); StringSource source(*sink.s);
restorePath(actualPath, source); restorePath(actualPath, source);
/* FIXME: set proper permissions in restorePath() so
we don't have to do another traversal. */
canonicalisePathMetaData(actualPath, -1, inodesSeen);
} }
}; };
@ -2452,6 +2448,10 @@ void LocalDerivationGoal::registerOutputs()
}, },
}, output.output); }, output.output);
/* FIXME: set proper permissions in restorePath() so
we don't have to do another traversal. */
canonicalisePathMetaData(actualPath, -1, inodesSeen);
/* Calculate where we'll move the output files. In the checking case we /* Calculate where we'll move the output files. In the checking case we
will leave leave them where they are, for now, rather than move to will leave leave them where they are, for now, rather than move to
their usual "final destination" */ their usual "final destination" */

View file

@ -10,3 +10,10 @@ nix build -f multiple-outputs.nix --json a.all b.all | jq --exit-status '
(.drvPath | match(".*multiple-outputs-b.drv")) and (.drvPath | match(".*multiple-outputs-b.drv")) and
(.outputs.out | match(".*multiple-outputs-b"))) (.outputs.out | match(".*multiple-outputs-b")))
' '
testNormalization () {
clearStore
outPath=$(nix-build ./simple.nix)
test "$(stat -c %Y $outPath)" -eq 1
}
testNormalization

View file

@ -59,9 +59,17 @@ testNixCommand () {
nix build --experimental-features 'nix-command ca-derivations' --file ./content-addressed.nix --no-link nix build --experimental-features 'nix-command ca-derivations' --file ./content-addressed.nix --no-link
} }
# Regression test for https://github.com/NixOS/nix/issues/4775
testNormalization () {
clearStore
outPath=$(buildAttr rootCA 1)
test "$(stat -c %Y $outPath)" -eq 1
}
# Disabled until we have it properly working # Disabled until we have it properly working
# testRemoteCache # testRemoteCache
clearStore clearStore
testNormalization
testDeterministicCA testDeterministicCA
clearStore clearStore
testCutoff testCutoff