* Validate derivation names. In particular don't allow spaces.

* Drop support for the outPath attribute in derivations.
This commit is contained in:
Eelco Dolstra 2004-08-24 11:46:05 +00:00
parent 8f58733ef1
commit 9994c1dd9f

View file

@ -181,7 +181,6 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
ne.type = StoreExpr::neDerivation; ne.type = StoreExpr::neDerivation;
string drvName; string drvName;
Path outPath;
Hash outHash; Hash outHash;
bool outHashGiven = false; bool outHashGiven = false;
@ -217,7 +216,6 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
if (key == "builder") ne.derivation.builder = s; if (key == "builder") ne.derivation.builder = s;
else if (key == "system") ne.derivation.platform = s; else if (key == "system") ne.derivation.platform = s;
else if (key == "name") drvName = s; else if (key == "name") drvName = s;
else if (key == "outPath") outPath = s;
else if (key == "id") { else if (key == "id") {
outHash = parseHash(s); outHash = parseHash(s);
outHashGiven = true; outHashGiven = true;
@ -232,14 +230,27 @@ static Expr primDerivation(EvalState & state, const ATermVector & _args)
throw Error("required attribute `system' missing"); throw Error("required attribute `system' missing");
if (drvName == "") if (drvName == "")
throw Error("required attribute `name' missing"); throw Error("required attribute `name' missing");
/* Check the derivation name. It shouldn't contain whitespace,
but we are conservative here: we check whether only
alphanumerics and some other characters appear. */
string validChars = "+-._?=";
for (string::iterator i = drvName.begin(); i != drvName.end(); ++i)
if (!((*i >= 'A' && *i <= 'Z') ||
(*i >= 'a' && *i <= 'z') ||
(*i >= '0' && *i <= '9') ||
validChars.find(*i) != string::npos))
{
throw Error(format("invalid character `%1%' in derivation name `%2%'")
% *i % drvName);
}
/* Determine the output path. */ /* 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); if (!outHashGiven) outHash = hashDerivation(state, ne);
if (outPath == "") Path outPath = canonPath(nixStore + "/" +
/* Hash the Nix expression with no outputs to produce a ((string) outHash).c_str() + "-" + drvName);
unique but deterministic path name for this derivation. */
outPath = canonPath(nixStore + "/" +
((string) outHash).c_str() + "-" + drvName);
ne.derivation.env["out"] = outPath; ne.derivation.env["out"] = outPath;
ne.derivation.outputs.insert(outPath); ne.derivation.outputs.insert(outPath);