diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 3f595e3..37b839a 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -2288,8 +2288,15 @@ void DerivationGoal::computeClosure() % path % i->second.hashAlgo % printHash16or32(h) % printHash16or32(h2)); } - /* Get rid of all weird permissions. */ - canonicalisePathMetaData(path, buildUser.enabled() ? buildUser.getUID() : -1); + /* Get rid of all weird permissions. If `path' already existed (as + can happen with multiple-output derivations), it is already owned + by `root' and not by the build user. In that case, skip + canonicalisation altogether. + See for details. */ + canonicalisePathMetaData(path, + (buildUser.enabled() && st.st_uid == buildUser.getUID()) + ? buildUser.getUID() + : -1); /* For this output path, find the references to other paths contained in it. Compute the SHA-256 NAR hash at the same