Skip to content

Commit

Permalink
Properly normalize the content-addressed paths
Browse files Browse the repository at this point in the history
Make sure that their timestamp are always normalized.
Otherwise, strange − and non-deterministic − things might happen, like
NixOS/nixpkgs#121813

Fix #4775
  • Loading branch information
thufschmitt committed May 5, 2021
1 parent fe3a10a commit bf485dc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/libstore/build/local-derivation-goal.cc
Expand Up @@ -2300,10 +2300,6 @@ void LocalDerivationGoal::registerOutputs()
sink.s = make_ref<std::string>(rewriteStrings(*sink.s, outputRewrites));
StringSource source(*sink.s);
restorePath(actualPath, source);

/* FIXME: set proper permissions in restorePath() so
we don't have to do another traversal. */
canonicalisePathMetaData(actualPath, -1, inodesSeen);
}
};

Expand Down Expand Up @@ -2452,6 +2448,10 @@ void LocalDerivationGoal::registerOutputs()
},
}, 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
will leave leave them where they are, for now, rather than move to
their usual "final destination" */
Expand Down
7 changes: 7 additions & 0 deletions tests/build.sh
Expand Up @@ -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
(.outputs.out | match(".*multiple-outputs-b")))
'

testNormalization () {
clearStore
outPath=$(nix-build ./simple.nix)
test "$(stat -c %Y $outPath)" -eq 1
}
testNormalization
8 changes: 8 additions & 0 deletions tests/ca/build.sh
Expand Up @@ -59,9 +59,17 @@ testNixCommand () {
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
# testRemoteCache
clearStore
testNormalization
testDeterministicCA
clearStore
testCutoff
Expand Down

0 comments on commit bf485dc

Please sign in to comment.