From 9530cc31700f68fd229eee69eabd2baa099f404a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 14 Jan 2005 13:51:38 +0000 Subject: * Start move towards SHA-256 hashes instead of MD5. * Start cleaning up unique store path generation (they weren't always unique; in particular the suffix ("-aterm-2.2", "-builder.sh") was not part of the hash, therefore changes to the suffix would cause multiple store objects with the same hash). --- src/libexpr/primops.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/libexpr/primops.cc') diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index f73e60e387bd..59b85a6d6233 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -59,7 +59,7 @@ static Path copyAtom(EvalState & state, const Path & srcPath) ne.closure.elems[dstPath] = elem; Hash drvHash = hashDerivation(state, ne); - Path drvPath = writeTerm(unparseStoreExpr(ne), ""); + Path drvPath = writeTerm(unparseStoreExpr(ne), "c"); state.drvHashes.insert(make_pair(drvPath, drvHash)); state.drvRoots[drvPath] = ne.closure.roots; @@ -250,21 +250,32 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args) throw Error(format("invalid character `%1%' in derivation name `%2%'") % *i % drvName); } + + /* Construct the "masked" derivation store expression, which is + the final one except that the list of output paths is set to + the set of output names, and the corresponding environment + variables have an empty value. This ensures that changes in + the set of output names do get reflected in the hash. */ + ne.derivation.env["out"] = ""; + ne.derivation.outputs.insert("out"); /* Determine the output path by hashing the Nix expression with no outputs to produce a unique but deterministic path name for this derivation. */ if (!outHashGiven) outHash = hashDerivation(state, ne); - Path outPath = canonPath(nixStore + "/" + - ((string) outHash).c_str() + "-" + drvName); + Path outPath = makeStorePath("output:out", + outHash, drvName); + + /* Construct the final derivation store expression. */ ne.derivation.env["out"] = outPath; + ne.derivation.outputs.clear(); ne.derivation.outputs.insert(outPath); /* Write the resulting term into the Nix store directory. */ Hash drvHash = outHashGiven ? hashString((string) outHash + outPath, htMD5) : hashDerivation(state, ne); - Path drvPath = writeTerm(unparseStoreExpr(ne), "-d-" + drvName); + Path drvPath = writeTerm(unparseStoreExpr(ne), "d-" + drvName); printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'") % drvName % drvPath); -- cgit 1.4.1