2005-01-19 16:39:47 +00:00
|
|
|
#include "derivations.hh"
|
2003-07-07 07:43:58 +00:00
|
|
|
#include "store.hh"
|
2006-09-04 22:08:40 +00:00
|
|
|
#include "aterm.hh"
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2005-01-19 16:39:47 +00:00
|
|
|
#include "derivations-ast.hh"
|
|
|
|
#include "derivations-ast.cc"
|
2004-10-29 11:22:49 +00:00
|
|
|
|
2003-06-16 13:33:38 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
2003-06-27 13:55:12 +00:00
|
|
|
Hash hashTerm(ATerm t)
|
2003-06-16 13:33:38 +00:00
|
|
|
{
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
return hashString(htSHA256, atPrint(t));
|
2003-06-16 13:33:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 14:36:00 +00:00
|
|
|
Path writeDerivation(const Derivation & drv, const string & name)
|
2003-07-04 12:18:06 +00:00
|
|
|
{
|
2005-01-25 21:28:25 +00:00
|
|
|
PathSet references;
|
|
|
|
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
|
|
|
for (DerivationInputs::const_iterator i = drv.inputDrvs.begin();
|
|
|
|
i != drv.inputDrvs.end(); ++i)
|
|
|
|
references.insert(i->first);
|
|
|
|
/* Note that the outputs of a derivation are *not* references
|
|
|
|
(that can be missing (of course) and should not necessarily be
|
|
|
|
held during a garbage collection). */
|
2005-01-19 14:36:00 +00:00
|
|
|
return addTextToStore(name + drvExtension,
|
2005-01-25 21:28:25 +00:00
|
|
|
atPrint(unparseDerivation(drv)), references);
|
2003-07-04 12:18:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
static void checkPath(const string & s)
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
{
|
|
|
|
if (s.size() == 0 || s[0] != '/')
|
2005-01-20 16:01:07 +00:00
|
|
|
throw Error(format("bad path `%1%' in derivation") % s);
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-20 14:10:19 +00:00
|
|
|
static void parseStrings(ATermList paths, StringSet & out, bool arePaths)
|
2003-07-15 16:28:54 +00:00
|
|
|
{
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(paths); i; ++i) {
|
2004-10-29 11:22:49 +00:00
|
|
|
if (ATgetType(*i) != AT_APPL)
|
|
|
|
throw badTerm("not a path", *i);
|
|
|
|
string s = aterm2String(*i);
|
2005-01-20 14:10:19 +00:00
|
|
|
if (arePaths) checkPath(s);
|
2003-08-20 14:11:40 +00:00
|
|
|
out.insert(s);
|
2003-07-15 16:28:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-02 17:51:50 +00:00
|
|
|
/* Shut up warnings. */
|
|
|
|
void throwBadDrv(ATerm t) __attribute__ ((noreturn));
|
|
|
|
|
|
|
|
void throwBadDrv(ATerm t)
|
2003-07-20 19:29:38 +00:00
|
|
|
{
|
2005-01-19 11:16:11 +00:00
|
|
|
throw badTerm("not a valid derivation", t);
|
2003-07-15 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
Derivation parseDerivation(ATerm t)
|
2003-07-15 21:24:05 +00:00
|
|
|
{
|
2005-01-19 11:16:11 +00:00
|
|
|
Derivation drv;
|
|
|
|
ATermList outs, inDrvs, inSrcs, args, bnds;
|
2004-10-29 11:22:49 +00:00
|
|
|
ATerm builder, platform;
|
2003-11-16 17:46:31 +00:00
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
if (!matchDerive(t, outs, inDrvs, inSrcs, platform, builder, args, bnds))
|
|
|
|
throwBadDrv(t);
|
2003-07-15 16:28:54 +00:00
|
|
|
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
for (ATermIterator i(outs); i; ++i) {
|
|
|
|
ATerm id, path, hashAlgo, hash;
|
|
|
|
if (!matchDerivationOutput(*i, id, path, hashAlgo, hash))
|
2005-01-19 11:16:11 +00:00
|
|
|
throwBadDrv(t);
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
DerivationOutput out;
|
|
|
|
out.path = aterm2String(path);
|
|
|
|
checkPath(out.path);
|
|
|
|
out.hashAlgo = aterm2String(hashAlgo);
|
|
|
|
out.hash = aterm2String(hash);
|
2005-01-19 11:16:11 +00:00
|
|
|
drv.outputs[aterm2String(id)] = out;
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
}
|
|
|
|
|
2005-01-20 14:10:19 +00:00
|
|
|
for (ATermIterator i(inDrvs); i; ++i) {
|
|
|
|
ATerm drvPath;
|
|
|
|
ATermList ids;
|
|
|
|
if (!matchDerivationInput(*i, drvPath, ids))
|
|
|
|
throwBadDrv(t);
|
|
|
|
Path drvPath2 = aterm2String(drvPath);
|
|
|
|
checkPath(drvPath2);
|
|
|
|
StringSet ids2;
|
|
|
|
parseStrings(ids, ids2, false);
|
|
|
|
drv.inputDrvs[drvPath2] = ids2;
|
|
|
|
}
|
|
|
|
|
|
|
|
parseStrings(inSrcs, drv.inputSrcs, true);
|
2003-07-15 16:28:54 +00:00
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
drv.builder = aterm2String(builder);
|
|
|
|
drv.platform = aterm2String(platform);
|
2003-07-20 19:29:38 +00:00
|
|
|
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(args); i; ++i) {
|
2004-10-29 11:22:49 +00:00
|
|
|
if (ATgetType(*i) != AT_APPL)
|
2003-11-16 18:31:29 +00:00
|
|
|
throw badTerm("string expected", *i);
|
2005-01-19 11:16:11 +00:00
|
|
|
drv.args.push_back(aterm2String(*i));
|
2003-08-15 12:32:37 +00:00
|
|
|
}
|
|
|
|
|
2003-11-16 18:31:29 +00:00
|
|
|
for (ATermIterator i(bnds); i; ++i) {
|
2004-10-29 11:22:49 +00:00
|
|
|
ATerm s1, s2;
|
|
|
|
if (!matchEnvBinding(*i, s1, s2))
|
2003-11-16 18:31:29 +00:00
|
|
|
throw badTerm("tuple of strings expected", *i);
|
2005-01-19 11:16:11 +00:00
|
|
|
drv.env[aterm2String(s1)] = aterm2String(s2);
|
2003-07-15 16:28:54 +00:00
|
|
|
}
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
return drv;
|
2003-07-16 11:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-19 11:16:11 +00:00
|
|
|
ATerm unparseDerivation(const Derivation & drv)
|
2003-07-15 22:28:27 +00:00
|
|
|
{
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
ATermList outputs = ATempty;
|
2006-05-02 17:51:50 +00:00
|
|
|
for (DerivationOutputs::const_reverse_iterator i = drv.outputs.rbegin();
|
|
|
|
i != drv.outputs.rend(); ++i)
|
* Removed the `id' attribute hack.
* Formalise the notion of fixed-output derivations, i.e., derivations
for which a cryptographic hash of the output is known in advance.
Changes to such derivations should not propagate upwards through the
dependency graph. Previously this was done by specifying the hash
component of the output path through the `id' attribute, but this is
insecure since you can lie about it (i.e., you can specify any hash
and then produce a completely different output). Now the
responsibility for checking the output is moved from the builder to
Nix itself.
A fixed-output derivation can be created by specifying the
`outputHash' and `outputHashAlgo' attributes, the latter taking
values `md5', `sha1', and `sha256', and the former specifying the
actual hash in hexadecimal or in base-32 (auto-detected by looking
at the length of the attribute value). MD5 is included for
compatibility but should be considered deprecated.
* Removed the `drvPath' pseudo-attribute in derivation results. It's
no longer necessary.
* Cleaned up the support for multiple output paths in derivation store
expressions. Each output now has a unique identifier (e.g., `out',
`devel', `docs'). Previously there was no way to tell output paths
apart at the store expression level.
* `nix-hash' now has a flag `--base32' to specify that the hash should
be printed in base-32 notation.
* `fetchurl' accepts parameters `sha256' and `sha1' in addition to
`md5'.
* `nix-prefetch-url' now prints out a SHA-1 hash in base-32. (TODO: a
flag to specify the hash.)
2005-01-17 16:55:19 +00:00
|
|
|
outputs = ATinsert(outputs,
|
|
|
|
makeDerivationOutput(
|
|
|
|
toATerm(i->first),
|
|
|
|
toATerm(i->second.path),
|
|
|
|
toATerm(i->second.hashAlgo),
|
|
|
|
toATerm(i->second.hash)));
|
|
|
|
|
2005-01-20 14:10:19 +00:00
|
|
|
ATermList inDrvs = ATempty;
|
2006-05-02 17:51:50 +00:00
|
|
|
for (DerivationInputs::const_reverse_iterator i = drv.inputDrvs.rbegin();
|
|
|
|
i != drv.inputDrvs.rend(); ++i)
|
2005-01-20 14:10:19 +00:00
|
|
|
inDrvs = ATinsert(inDrvs,
|
|
|
|
makeDerivationInput(
|
|
|
|
toATerm(i->first),
|
2006-10-16 15:55:34 +00:00
|
|
|
toATermList(i->second)));
|
2005-01-20 14:10:19 +00:00
|
|
|
|
2003-08-15 12:32:37 +00:00
|
|
|
ATermList args = ATempty;
|
2006-05-02 17:51:50 +00:00
|
|
|
for (Strings::const_reverse_iterator i = drv.args.rbegin();
|
|
|
|
i != drv.args.rend(); ++i)
|
2004-11-03 18:12:03 +00:00
|
|
|
args = ATinsert(args, toATerm(*i));
|
2003-08-15 12:32:37 +00:00
|
|
|
|
2003-07-20 19:29:38 +00:00
|
|
|
ATermList env = ATempty;
|
2006-05-02 17:51:50 +00:00
|
|
|
for (StringPairs::const_reverse_iterator i = drv.env.rbegin();
|
|
|
|
i != drv.env.rend(); ++i)
|
2003-07-20 19:29:38 +00:00
|
|
|
env = ATinsert(env,
|
2004-10-29 11:22:49 +00:00
|
|
|
makeEnvBinding(
|
2004-11-03 18:12:03 +00:00
|
|
|
toATerm(i->first),
|
|
|
|
toATerm(i->second)));
|
2003-07-15 22:28:27 +00:00
|
|
|
|
2004-10-29 11:22:49 +00:00
|
|
|
return makeDerive(
|
2006-05-02 17:51:50 +00:00
|
|
|
outputs,
|
|
|
|
inDrvs,
|
2006-10-16 15:55:34 +00:00
|
|
|
toATermList(drv.inputSrcs),
|
2005-01-19 11:16:11 +00:00
|
|
|
toATerm(drv.platform),
|
|
|
|
toATerm(drv.builder),
|
2006-05-02 17:51:50 +00:00
|
|
|
args,
|
|
|
|
env);
|
2003-07-15 22:28:27 +00:00
|
|
|
}
|
2005-01-19 14:36:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool isDerivation(const string & fileName)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
fileName.size() >= drvExtension.size() &&
|
|
|
|
string(fileName, fileName.size() - drvExtension.size()) == drvExtension;
|
|
|
|
}
|
2006-09-04 21:06:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|