mirror of
https://github.com/NixOS/nix.git
synced 2025-11-25 11:49:35 +01:00
* Substitutes now should produce a path with the same id as they are
substituting for (obvious, really). * For greater efficiency, nix-pull/unnar will place the output in a path that is probably the same as what is actually needed, thus preventing a path copy. * Even if a output id is given in a Fix package expression, ensure that the resulting Nix derive expression has a different id. This is because Nix expressions that are semantically equivalent (i.e., build the same result) might be different w.r.t. efficiency or divergence. It is absolutely vital for the substitute mechanism that such expressions are not used interchangeably.
This commit is contained in:
parent
df648c4967
commit
e877c69d78
8 changed files with 86 additions and 50 deletions
33
src/store.cc
33
src/store.cc
|
|
@ -165,8 +165,11 @@ bool isInPrefix(const string & path, const string & _prefix)
|
|||
|
||||
|
||||
string expandId(const FSId & id, const string & target,
|
||||
const string & prefix)
|
||||
const string & prefix, FSIdSet pending)
|
||||
{
|
||||
debug(format("expanding %1%") % (string) id);
|
||||
Nest nest(true);
|
||||
|
||||
Strings paths;
|
||||
|
||||
if (!target.empty() && !isInPrefix(target, prefix))
|
||||
|
|
@ -203,30 +206,24 @@ string expandId(const FSId & id, const string & target,
|
|||
}
|
||||
}
|
||||
|
||||
/* Try to realise the substitutes. */
|
||||
if (pending.find(id) != pending.end())
|
||||
throw Error(format("id %1% already being expanded") % (string) id);
|
||||
pending.insert(id);
|
||||
|
||||
/* Try to realise the substitutes, but only if this id is not
|
||||
already being realised by a substitute. */
|
||||
Strings subs;
|
||||
queryListDB(nixDB, dbSubstitutes, id, subs); /* non-existence = ok */
|
||||
|
||||
for (Strings::iterator it = subs.begin(); it != subs.end(); it++) {
|
||||
FSId subId = parseHash(*it);
|
||||
Slice slice = normaliseFState(subId);
|
||||
realiseSlice(slice);
|
||||
|
||||
Strings paths = fstatePaths(subId, true);
|
||||
if (paths.size() != 1)
|
||||
throw Error("substitute created more than 1 path");
|
||||
string path = *(paths.begin());
|
||||
|
||||
if (target.empty())
|
||||
return path; /* !!! prefix */
|
||||
else {
|
||||
if (path != target) {
|
||||
copyPath(path, target);
|
||||
registerPath(target, id);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
debug(format("trying substitute %1%") % (string) subId);
|
||||
|
||||
Slice slice = normaliseFState(subId, pending);
|
||||
realiseSlice(slice, pending);
|
||||
|
||||
return expandId(id, target, prefix, pending);
|
||||
}
|
||||
|
||||
throw Error(format("cannot expand id `%1%'") % (string) id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue