2012-07-18 20:59:03 +02:00
|
|
|
#pragma once
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2010-05-13 00:13:09 +02:00
|
|
|
#include "types.hh"
|
2011-07-20 20:10:47 +02:00
|
|
|
#include "hash.hh"
|
2010-05-13 00:13:09 +02:00
|
|
|
|
2012-09-11 20:45:42 +02:00
|
|
|
#include <map>
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
|
|
namespace nix {
|
2003-06-16 15:33:38 +02:00
|
|
|
|
|
|
|
|
2005-01-19 15:36:00 +01:00
|
|
|
/* Extension of derivations in the Nix store. */
|
|
|
|
const string drvExtension = ".drv";
|
2003-06-27 11:55:31 +02:00
|
|
|
|
2003-06-16 15:33:38 +02:00
|
|
|
|
2005-01-19 15:36:00 +01:00
|
|
|
/* Abstract syntax of derivations. */
|
* 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 17:55:19 +01:00
|
|
|
|
|
|
|
struct DerivationOutput
|
|
|
|
{
|
|
|
|
Path path;
|
|
|
|
string hashAlgo; /* hash used for expected hash computation */
|
|
|
|
string hash; /* expected hash, may be null */
|
|
|
|
DerivationOutput()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
DerivationOutput(Path path, string hashAlgo, string hash)
|
|
|
|
{
|
|
|
|
this->path = path;
|
|
|
|
this->hashAlgo = hashAlgo;
|
|
|
|
this->hash = hash;
|
|
|
|
}
|
2011-07-20 20:10:47 +02:00
|
|
|
void parseHashInfo(bool & recursive, HashType & hashType, Hash & hash) const;
|
* 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 17:55:19 +01:00
|
|
|
};
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
typedef std::map<string, DerivationOutput> DerivationOutputs;
|
2005-01-20 15:10:19 +01:00
|
|
|
|
|
|
|
/* For inputs that are sub-derivations, we specify exactly which
|
|
|
|
output IDs we are interested in. */
|
2006-09-04 23:06:23 +02:00
|
|
|
typedef std::map<Path, StringSet> DerivationInputs;
|
2005-01-20 15:10:19 +01:00
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
typedef std::map<string, string> StringPairs;
|
2003-07-20 21:29:38 +02:00
|
|
|
|
2003-10-07 14:27:49 +02:00
|
|
|
struct Derivation
|
2003-07-20 21:29:38 +02: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 17:55:19 +01:00
|
|
|
DerivationOutputs outputs; /* keyed on symbolic IDs */
|
2005-01-20 15:10:19 +01:00
|
|
|
DerivationInputs inputDrvs; /* inputs that are sub-derivations */
|
2005-01-19 12:16:11 +01:00
|
|
|
PathSet inputSrcs; /* inputs that are sources */
|
2003-07-20 21:29:38 +02:00
|
|
|
string platform;
|
2003-10-08 17:06:59 +02:00
|
|
|
Path builder;
|
2003-08-15 14:32:37 +02:00
|
|
|
Strings args;
|
2003-07-20 21:29:38 +02:00
|
|
|
StringPairs env;
|
|
|
|
};
|
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
|
2011-08-31 23:11:50 +02:00
|
|
|
class StoreAPI;
|
|
|
|
|
|
|
|
|
2005-01-19 15:36:00 +01:00
|
|
|
/* Write a derivation to the Nix store, and return its path. */
|
2011-08-31 23:11:50 +02:00
|
|
|
Path writeDerivation(StoreAPI & store,
|
2012-10-03 21:09:18 +02:00
|
|
|
const Derivation & drv, const string & name, bool repair = false);
|
2003-07-10 20:48:11 +02:00
|
|
|
|
2005-01-19 15:36:00 +01:00
|
|
|
/* Parse a derivation. */
|
2010-04-19 15:46:58 +02:00
|
|
|
Derivation parseDerivation(const string & s);
|
2003-07-16 13:05:59 +02:00
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
/* Print a derivation. */
|
|
|
|
string unparseDerivation(const Derivation & drv);
|
2003-07-16 00:28:27 +02:00
|
|
|
|
2005-01-19 15:36:00 +01:00
|
|
|
/* Check whether a file name ends with the extensions for
|
|
|
|
derivations. */
|
|
|
|
bool isDerivation(const string & fileName);
|
|
|
|
|
2011-07-20 20:10:47 +02:00
|
|
|
/* Return true iff this is a fixed-output derivation. */
|
|
|
|
bool isFixedOutputDrv(const Derivation & drv);
|
|
|
|
|
2011-08-31 23:11:50 +02:00
|
|
|
Hash hashDerivationModulo(StoreAPI & store, Derivation drv);
|
2011-07-20 20:10:47 +02:00
|
|
|
|
|
|
|
/* Memoisation of hashDerivationModulo(). */
|
|
|
|
typedef std::map<Path, Hash> DrvHashes;
|
|
|
|
|
|
|
|
extern DrvHashes drvHashes;
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
}
|