2005-01-19 17:39:47 +01:00
|
|
|
|
#include "derivations.hh"
|
2006-11-30 18:43:04 +01:00
|
|
|
|
#include "store-api.hh"
|
2006-12-01 22:00:39 +01:00
|
|
|
|
#include "globals.hh"
|
2008-08-25 15:31:57 +02:00
|
|
|
|
#include "util.hh"
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
#include "worker-protocol.hh"
|
2016-06-02 18:43:36 +02:00
|
|
|
|
#include "fs-accessor.hh"
|
2003-06-16 15:33:38 +02:00
|
|
|
|
|
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
|
|
|
2016-07-26 21:25:52 +02:00
|
|
|
|
void DerivationOutput::parseHashInfo(bool & recursive, Hash & hash) const
|
2011-07-20 20:10:47 +02:00
|
|
|
|
{
|
|
|
|
|
recursive = false;
|
|
|
|
|
string algo = hashAlgo;
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2011-07-20 20:10:47 +02:00
|
|
|
|
if (string(algo, 0, 2) == "r:") {
|
|
|
|
|
recursive = true;
|
|
|
|
|
algo = string(algo, 2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-26 21:25:52 +02:00
|
|
|
|
HashType hashType = parseHashType(algo);
|
2011-07-20 20:10:47 +02:00
|
|
|
|
if (hashType == htUnknown)
|
2014-08-20 17:00:17 +02:00
|
|
|
|
throw Error(format("unknown hash algorithm ‘%1%’") % algo);
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2011-07-20 20:10:47 +02:00
|
|
|
|
hash = parseHash(hashType, this->hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
Path BasicDerivation::findOutput(const string & id) const
|
|
|
|
|
{
|
|
|
|
|
auto i = outputs.find(id);
|
|
|
|
|
if (i == outputs.end())
|
|
|
|
|
throw Error(format("derivation has no output ‘%1%’") % id);
|
|
|
|
|
return i->second.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BasicDerivation::willBuildLocally() const
|
|
|
|
|
{
|
|
|
|
|
return get(env, "preferLocalBuild") == "1" && canBuildLocally();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BasicDerivation::substitutesAllowed() const
|
|
|
|
|
{
|
|
|
|
|
return get(env, "allowSubstitutes", "1") == "1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BasicDerivation::isBuiltin() const
|
|
|
|
|
{
|
|
|
|
|
return string(builder, 0, 8) == "builtin:";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool BasicDerivation::canBuildLocally() const
|
|
|
|
|
{
|
|
|
|
|
return platform == settings.thisSystem
|
|
|
|
|
|| isBuiltin()
|
|
|
|
|
#if __linux__
|
|
|
|
|
|| (platform == "i686-linux" && settings.thisSystem == "x86_64-linux")
|
|
|
|
|
|| (platform == "armv6l-linux" && settings.thisSystem == "armv7l-linux")
|
2016-09-16 22:03:34 +02:00
|
|
|
|
|| (platform == "armv5tel-linux" && (settings.thisSystem == "armv7l-linux" || settings.thisSystem == "armv6l-linux"))
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
#elif __FreeBSD__
|
|
|
|
|
|| (platform == "i686-linux" && settings.thisSystem == "x86_64-freebsd")
|
|
|
|
|
|| (platform == "i686-linux" && settings.thisSystem == "i686-freebsd")
|
|
|
|
|
#endif
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 14:48:42 +01:00
|
|
|
|
Path writeDerivation(ref<Store> store,
|
2012-10-03 21:09:18 +02:00
|
|
|
|
const Derivation & drv, const string & name, bool repair)
|
2003-07-04 14:18:06 +02:00
|
|
|
|
{
|
2005-01-25 22:28:25 +01:00
|
|
|
|
PathSet references;
|
|
|
|
|
references.insert(drv.inputSrcs.begin(), drv.inputSrcs.end());
|
2015-07-17 19:24:28 +02:00
|
|
|
|
for (auto & i : drv.inputDrvs)
|
|
|
|
|
references.insert(i.first);
|
2005-01-25 22:28:25 +01:00
|
|
|
|
/* 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). */
|
2006-12-01 22:00:39 +01:00
|
|
|
|
string suffix = name + drvExtension;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
string contents = drv.unparse();
|
2012-07-31 01:55:41 +02:00
|
|
|
|
return settings.readOnlyMode
|
2016-06-01 14:49:12 +02:00
|
|
|
|
? store->computeStorePathForText(suffix, contents, references)
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
: store->addTextToStore(suffix, contents, references, repair);
|
2003-07-04 14:18:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-09-14 10:54:57 +02:00
|
|
|
|
/* Read string `s' from stream `str'. */
|
|
|
|
|
static void expect(std::istream & str, const string & s)
|
|
|
|
|
{
|
|
|
|
|
char s2[s.size()];
|
|
|
|
|
str.read(s2, s.size());
|
|
|
|
|
if (string(s2, s.size()) != s)
|
|
|
|
|
throw FormatError(format("expected string ‘%1%’") % s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Read a C-style string from stream `str'. */
|
|
|
|
|
static string parseString(std::istream & str)
|
|
|
|
|
{
|
|
|
|
|
string res;
|
|
|
|
|
expect(str, "\"");
|
|
|
|
|
int c;
|
|
|
|
|
while ((c = str.get()) != '"')
|
|
|
|
|
if (c == '\\') {
|
|
|
|
|
c = str.get();
|
|
|
|
|
if (c == 'n') res += '\n';
|
|
|
|
|
else if (c == 'r') res += '\r';
|
|
|
|
|
else if (c == 't') res += '\t';
|
|
|
|
|
else res += c;
|
|
|
|
|
}
|
|
|
|
|
else res += c;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
static Path parsePath(std::istream & str)
|
* 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
|
|
|
|
{
|
2010-04-19 15:46:58 +02:00
|
|
|
|
string s = parseString(str);
|
* 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
|
|
|
|
if (s.size() == 0 || s[0] != '/')
|
2014-08-20 17:00:17 +02:00
|
|
|
|
throw FormatError(format("bad path ‘%1%’ in derivation") % s);
|
2010-04-19 15:46:58 +02:00
|
|
|
|
return 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 17:55:19 +01:00
|
|
|
|
}
|
2012-07-31 01:55:41 +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
|
|
|
|
|
2016-09-14 10:54:57 +02:00
|
|
|
|
static bool endOfList(std::istream & str)
|
|
|
|
|
{
|
|
|
|
|
if (str.peek() == ',') {
|
|
|
|
|
str.get();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (str.peek() == ']') {
|
|
|
|
|
str.get();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
static StringSet parseStrings(std::istream & str, bool arePaths)
|
2003-07-15 18:28:54 +02:00
|
|
|
|
{
|
2010-04-19 15:46:58 +02:00
|
|
|
|
StringSet res;
|
|
|
|
|
while (!endOfList(str))
|
|
|
|
|
res.insert(arePaths ? parsePath(str) : parseString(str));
|
|
|
|
|
return res;
|
2003-07-15 18:28:54 +02:00
|
|
|
|
}
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
|
|
2014-04-08 19:24:29 +02:00
|
|
|
|
static Derivation parseDerivation(const string & s)
|
2003-07-15 23:24:05 +02:00
|
|
|
|
{
|
2005-01-19 12:16:11 +01:00
|
|
|
|
Derivation drv;
|
2010-04-19 15:46:58 +02:00
|
|
|
|
std::istringstream str(s);
|
|
|
|
|
expect(str, "Derive([");
|
2003-11-16 18:46:31 +01:00
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
/* Parse the list of outputs. */
|
|
|
|
|
while (!endOfList(str)) {
|
* 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
|
|
|
|
DerivationOutput out;
|
2010-04-19 15:46:58 +02:00
|
|
|
|
expect(str, "("); string id = parseString(str);
|
|
|
|
|
expect(str, ","); out.path = parsePath(str);
|
|
|
|
|
expect(str, ","); out.hashAlgo = parseString(str);
|
|
|
|
|
expect(str, ","); out.hash = parseString(str);
|
|
|
|
|
expect(str, ")");
|
|
|
|
|
drv.outputs[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 17:55:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
/* Parse the list of input derivations. */
|
|
|
|
|
expect(str, ",[");
|
|
|
|
|
while (!endOfList(str)) {
|
|
|
|
|
expect(str, "(");
|
|
|
|
|
Path drvPath = parsePath(str);
|
|
|
|
|
expect(str, ",[");
|
|
|
|
|
drv.inputDrvs[drvPath] = parseStrings(str, false);
|
|
|
|
|
expect(str, ")");
|
2005-01-20 15:10:19 +01:00
|
|
|
|
}
|
2003-07-15 18:28:54 +02:00
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
expect(str, ",["); drv.inputSrcs = parseStrings(str, true);
|
|
|
|
|
expect(str, ","); drv.platform = parseString(str);
|
|
|
|
|
expect(str, ","); drv.builder = parseString(str);
|
|
|
|
|
|
|
|
|
|
/* Parse the builder arguments. */
|
|
|
|
|
expect(str, ",[");
|
|
|
|
|
while (!endOfList(str))
|
|
|
|
|
drv.args.push_back(parseString(str));
|
|
|
|
|
|
|
|
|
|
/* Parse the environment variables. */
|
|
|
|
|
expect(str, ",[");
|
|
|
|
|
while (!endOfList(str)) {
|
|
|
|
|
expect(str, "("); string name = parseString(str);
|
|
|
|
|
expect(str, ","); string value = parseString(str);
|
|
|
|
|
expect(str, ")");
|
|
|
|
|
drv.env[name] = value;
|
2003-08-15 14:32:37 +02:00
|
|
|
|
}
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
expect(str, ")");
|
|
|
|
|
return drv;
|
|
|
|
|
}
|
2003-08-15 14:32:37 +02:00
|
|
|
|
|
2003-07-15 18:28:54 +02:00
|
|
|
|
|
2014-04-08 19:24:29 +02:00
|
|
|
|
Derivation readDerivation(const Path & drvPath)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
return parseDerivation(readFile(drvPath));
|
|
|
|
|
} catch (FormatError & e) {
|
2014-08-20 17:00:17 +02:00
|
|
|
|
throw Error(format("error parsing derivation ‘%1%’: %2%") % drvPath % e.msg());
|
2014-04-08 19:24:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-06-02 18:43:36 +02:00
|
|
|
|
Derivation Store::derivationFromPath(const Path & drvPath)
|
|
|
|
|
{
|
|
|
|
|
assertStorePath(drvPath);
|
|
|
|
|
ensurePath(drvPath);
|
|
|
|
|
auto accessor = getFSAccessor();
|
|
|
|
|
try {
|
|
|
|
|
return parseDerivation(accessor->readFile(drvPath));
|
|
|
|
|
} catch (FormatError & e) {
|
|
|
|
|
throw Error(format("error parsing derivation ‘%1%’: %2%") % drvPath % e.msg());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
static void printString(string & res, const string & s)
|
2010-04-19 15:46:58 +02:00
|
|
|
|
{
|
2010-04-21 21:25:50 +02:00
|
|
|
|
res += '"';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
for (const char * i = s.c_str(); *i; i++)
|
2010-04-21 21:25:50 +02:00
|
|
|
|
if (*i == '\"' || *i == '\\') { res += "\\"; res += *i; }
|
|
|
|
|
else if (*i == '\n') res += "\\n";
|
|
|
|
|
else if (*i == '\r') res += "\\r";
|
|
|
|
|
else if (*i == '\t') res += "\\t";
|
|
|
|
|
else res += *i;
|
|
|
|
|
res += '"';
|
2003-07-16 13:05:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-04-19 15:46:58 +02:00
|
|
|
|
template<class ForwardIterator>
|
2010-04-21 21:25:50 +02:00
|
|
|
|
static void printStrings(string & res, ForwardIterator i, ForwardIterator j)
|
2003-07-16 00:28:27 +02:00
|
|
|
|
{
|
2010-04-21 21:25:50 +02:00
|
|
|
|
res += '[';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
bool first = true;
|
|
|
|
|
for ( ; i != j; ++i) {
|
2010-04-21 21:25:50 +02:00
|
|
|
|
if (first) first = false; else res += ',';
|
|
|
|
|
printString(res, *i);
|
2010-04-19 15:46:58 +02:00
|
|
|
|
}
|
2010-04-21 21:25:50 +02:00
|
|
|
|
res += ']';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
string Derivation::unparse() const
|
2010-04-19 15:46:58 +02:00
|
|
|
|
{
|
2010-04-21 21:25:50 +02:00
|
|
|
|
string s;
|
|
|
|
|
s.reserve(65536);
|
|
|
|
|
s += "Derive([";
|
2010-04-19 15:46:58 +02:00
|
|
|
|
|
|
|
|
|
bool first = true;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
for (auto & i : outputs) {
|
2010-04-21 21:25:50 +02:00
|
|
|
|
if (first) first = false; else s += ',';
|
2015-07-17 19:24:28 +02:00
|
|
|
|
s += '('; printString(s, i.first);
|
|
|
|
|
s += ','; printString(s, i.second.path);
|
|
|
|
|
s += ','; printString(s, i.second.hashAlgo);
|
|
|
|
|
s += ','; printString(s, i.second.hash);
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += ')';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += "],[";
|
2010-04-19 15:46:58 +02:00
|
|
|
|
first = true;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
for (auto & i : inputDrvs) {
|
2010-04-21 21:25:50 +02:00
|
|
|
|
if (first) first = false; else s += ',';
|
2015-07-17 19:24:28 +02:00
|
|
|
|
s += '('; printString(s, i.first);
|
|
|
|
|
s += ','; printStrings(s, i.second.begin(), i.second.end());
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += ')';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += "],";
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
printStrings(s, inputSrcs.begin(), inputSrcs.end());
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
s += ','; printString(s, platform);
|
|
|
|
|
s += ','; printString(s, builder);
|
|
|
|
|
s += ','; printStrings(s, args.begin(), args.end());
|
2010-04-19 15:46:58 +02:00
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += ",[";
|
2010-04-19 15:46:58 +02:00
|
|
|
|
first = true;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
for (auto & i : env) {
|
2010-04-21 21:25:50 +02:00
|
|
|
|
if (first) first = false; else s += ',';
|
2015-07-17 19:24:28 +02:00
|
|
|
|
s += '('; printString(s, i.first);
|
|
|
|
|
s += ','; printString(s, i.second);
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += ')';
|
2010-04-19 15:46:58 +02:00
|
|
|
|
}
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
s += "])";
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
2010-04-21 21:25:50 +02:00
|
|
|
|
return s;
|
2003-07-16 00:28:27 +02:00
|
|
|
|
}
|
2005-01-19 15:36:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool isDerivation(const string & fileName)
|
|
|
|
|
{
|
2008-08-25 15:31:57 +02:00
|
|
|
|
return hasSuffix(fileName, drvExtension);
|
2005-01-19 15:36:00 +01:00
|
|
|
|
}
|
2006-09-04 23:06:23 +02:00
|
|
|
|
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
bool BasicDerivation::isFixedOutput() const
|
2011-07-20 20:10:47 +02:00
|
|
|
|
{
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
return outputs.size() == 1 &&
|
|
|
|
|
outputs.begin()->first == "out" &&
|
|
|
|
|
outputs.begin()->second.hash != "";
|
2011-07-20 20:10:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Add basic impure derivations
Impure derivations are derivations that can produce a different result
every time they're built. Example:
stdenv.mkDerivation {
name = "impure";
__impure = true; # marks this derivation as impure
buildCommand = "date > $out";
};
Some important characteristics:
* Impure derivations are not "cached". Thus, running "nix-build" on
the example above multiple times will cause a rebuild every time. In
the future, we could implement some mechanism for reusing impure
builds across invocations.
* The outputs of impure derivations are moved to a content-addressed
location after the build (i.e., the resulting store path will
correspond to the hash of the contents of the path). This way,
multiple builds of the same impure derivation do not collide.
* Because of content-addressability, the output paths of an impure
derivation recorded in its .drv file are "virtual" placeholders for
the actual outputs which are not known in advance. This also means
that "nix-store -q bla.drv" gives a meaningless path.
* Pure derivations are not allowed to depend on impure
derivations. The only exception is fixed-output derivations. Because
the latter always produce a known output, they can depend on impure
shenanigans just fine. Also, repeatedly running "nix-build" on such
a fixed-output derivation will *not* cause a rebuild of the impure
dependency. After all, if the fixed output exists, its dependencies
are no longer relevant. Thus, fixed-output derivations form an
"impurity barrier" in the dependency graph.
* When sandboxing is enabled, impure derivations can access the
network in the same way as fixed-output derivations. In relaxed
sandboxing mode, they can access the local filesystem.
* Currently, the output of an impure derivation must have no
references. This is because the content-addressing scheme must be
extended to handle references, in particular self-references (as
described in the ASE-2005 paper.)
* Currently, impure derivations can only have a single output. No real
reason for this.
* "nix-build" on an impure derivation currently creates a result
symlink to the incorrect, virtual output.
A motivating example is the problem of using "fetchurl" on a
dynamically generated tarball whose contents are deterministic, but
where the tarball does not have a canonical form. Previously, this
required "fetchurl" to do the unpacking in the same
derivation. (That's what "fetchzip" does.) But now we can say:
tarball = stdenv.mkDerivation {
__impure = true;
name = "tarball";
buildInputs = [ curl ];
buildCommand =
"curl --fail -Lk https://github.com/NixOS/patchelf/tarball/c1f89c077e44a495c62ed0dcfaeca21510df93ef > $out";
};
unpacked = stdenv.mkDerivation {
name = "unpacked";
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = "1jl8n1n36w63wffkm56slcfa7vj9fxkv4ax0fr0mcfah55qj5l8s";
buildCommand =
"mkdir $out; tar xvf ${tarball} -C $out";
};
I needed this because <nix/fetchurl.nix> does not support unpacking,
and adding untar/unzip functionality would be annoying (especially
since we can't just call "tar" or "unzip" in a sandbox).
https://github.com/NixOS/nix/issues/520
2017-02-24 19:03:53 +01:00
|
|
|
|
bool BasicDerivation::isImpure() const
|
|
|
|
|
{
|
|
|
|
|
// FIXME: drop single output restriction
|
|
|
|
|
return outputs.size() == 1 &&
|
|
|
|
|
outputs.begin()->first == "out" &&
|
|
|
|
|
get(env, "__impure", "") == "1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-07-20 20:10:47 +02:00
|
|
|
|
DrvHashes drvHashes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns the hash of a derivation modulo fixed-output
|
|
|
|
|
subderivations. A fixed-output derivation is a derivation with one
|
|
|
|
|
output (`out') for which an expected hash and hash algorithm are
|
|
|
|
|
specified (using the `outputHash' and `outputHashAlgo'
|
|
|
|
|
attributes). We don't want changes to such derivations to
|
|
|
|
|
propagate upwards through the dependency graph, changing output
|
|
|
|
|
paths everywhere.
|
|
|
|
|
|
|
|
|
|
For instance, if we change the url in a call to the `fetchurl'
|
|
|
|
|
function, we do not want to rebuild everything depending on it
|
|
|
|
|
(after all, (the hash of) the file being downloaded is unchanged).
|
|
|
|
|
So the *output paths* should not change. On the other hand, the
|
|
|
|
|
*derivation paths* should change to reflect the new dependency
|
|
|
|
|
graph.
|
|
|
|
|
|
|
|
|
|
That's what this function does: it returns a hash which is just the
|
|
|
|
|
hash of the derivation ATerm, except that any input derivation
|
|
|
|
|
paths have been replaced by the result of a recursive call to this
|
|
|
|
|
function, and that for fixed-output derivations we return a hash of
|
|
|
|
|
its output path. */
|
2016-02-04 14:48:42 +01:00
|
|
|
|
Hash hashDerivationModulo(Store & store, Derivation drv)
|
2011-07-20 20:10:47 +02:00
|
|
|
|
{
|
|
|
|
|
/* Return a fixed hash for fixed-output derivations. */
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
if (drv.isFixedOutput()) {
|
2011-07-20 20:10:47 +02:00
|
|
|
|
DerivationOutputs::const_iterator i = drv.outputs.begin();
|
|
|
|
|
return hashString(htSHA256, "fixed:out:"
|
|
|
|
|
+ i->second.hashAlgo + ":"
|
|
|
|
|
+ i->second.hash + ":"
|
|
|
|
|
+ i->second.path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For other derivations, replace the inputs paths with recursive
|
|
|
|
|
calls to this function.*/
|
|
|
|
|
DerivationInputs inputs2;
|
2015-07-17 19:24:28 +02:00
|
|
|
|
for (auto & i : drv.inputDrvs) {
|
|
|
|
|
Hash h = drvHashes[i.first];
|
2016-04-20 14:12:38 +02:00
|
|
|
|
if (!h) {
|
2015-07-17 19:24:28 +02:00
|
|
|
|
assert(store.isValidPath(i.first));
|
|
|
|
|
Derivation drv2 = readDerivation(i.first);
|
2011-08-31 23:11:50 +02:00
|
|
|
|
h = hashDerivationModulo(store, drv2);
|
2015-07-17 19:24:28 +02:00
|
|
|
|
drvHashes[i.first] = h;
|
2011-07-20 20:10:47 +02:00
|
|
|
|
}
|
2015-07-17 19:24:28 +02:00
|
|
|
|
inputs2[printHash(h)] = i.second;
|
2011-07-20 20:10:47 +02:00
|
|
|
|
}
|
|
|
|
|
drv.inputDrvs = inputs2;
|
2012-07-31 01:55:41 +02:00
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
return hashString(htSHA256, drv.unparse());
|
2011-07-20 20:10:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 15:39:10 +01:00
|
|
|
|
DrvPathWithOutputs parseDrvPathWithOutputs(const string & s)
|
|
|
|
|
{
|
|
|
|
|
size_t n = s.find("!");
|
|
|
|
|
return n == s.npos
|
|
|
|
|
? DrvPathWithOutputs(s, std::set<string>())
|
|
|
|
|
: DrvPathWithOutputs(string(s, 0, n), tokenizeString<std::set<string> >(string(s, n + 1), ","));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 17:15:09 +01:00
|
|
|
|
Path makeDrvPathWithOutputs(const Path & drvPath, const std::set<string> & outputs)
|
2012-11-26 15:39:10 +01:00
|
|
|
|
{
|
|
|
|
|
return outputs.empty()
|
|
|
|
|
? drvPath
|
|
|
|
|
: drvPath + "!" + concatStringsSep(",", outputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 17:15:09 +01:00
|
|
|
|
bool wantOutput(const string & output, const std::set<string> & wanted)
|
|
|
|
|
{
|
|
|
|
|
return wanted.empty() || wanted.find(output) != wanted.end();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
PathSet BasicDerivation::outputPaths() const
|
2015-06-10 16:17:06 +02:00
|
|
|
|
{
|
|
|
|
|
PathSet paths;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 14:28:26 +01:00
|
|
|
|
for (auto & i : outputs)
|
2015-06-10 16:17:06 +02:00
|
|
|
|
paths.insert(i.second.path);
|
|
|
|
|
return paths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
|
Source & readDerivation(Source & in, Store & store, BasicDerivation & drv)
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
{
|
|
|
|
|
drv.outputs.clear();
|
|
|
|
|
auto nr = readInt(in);
|
|
|
|
|
for (unsigned int n = 0; n < nr; n++) {
|
|
|
|
|
auto name = readString(in);
|
|
|
|
|
DerivationOutput o;
|
|
|
|
|
in >> o.path >> o.hashAlgo >> o.hash;
|
2016-06-01 14:49:12 +02:00
|
|
|
|
store.assertStorePath(o.path);
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
drv.outputs[name] = o;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 14:49:12 +02:00
|
|
|
|
drv.inputSrcs = readStorePaths<PathSet>(store, in);
|
Allow remote builds without sending the derivation closure
Previously, to build a derivation remotely, we had to copy the entire
closure of the .drv file to the remote machine, even though we only
need the top-level derivation. This is very wasteful: the closure can
contain thousands of store paths, and in some Hydra use cases, include
source paths that are very large (e.g. Git/Mercurial checkouts).
So now there is a new operation, StoreAPI::buildDerivation(), that
performs a build from an in-memory representation of a derivation
(BasicDerivation) rather than from a on-disk .drv file. The only files
that need to be in the Nix store are the sources of the derivation
(drv.inputSrcs), and the needed output paths of the dependencies (as
described by drv.inputDrvs). "nix-store --serve" exposes this
interface.
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
Fixes #173.
2015-07-17 17:57:40 +02:00
|
|
|
|
in >> drv.platform >> drv.builder;
|
|
|
|
|
drv.args = readStrings<Strings>(in);
|
|
|
|
|
|
|
|
|
|
nr = readInt(in);
|
|
|
|
|
for (unsigned int n = 0; n < nr; n++) {
|
|
|
|
|
auto key = readString(in);
|
|
|
|
|
auto value = readString(in);
|
|
|
|
|
drv.env[key] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sink & operator << (Sink & out, const BasicDerivation & drv)
|
|
|
|
|
{
|
|
|
|
|
out << drv.outputs.size();
|
|
|
|
|
for (auto & i : drv.outputs)
|
|
|
|
|
out << i.first << i.second.path << i.second.hashAlgo << i.second.hash;
|
|
|
|
|
out << drv.inputSrcs << drv.platform << drv.builder << drv.args;
|
|
|
|
|
out << drv.env.size();
|
|
|
|
|
for (auto & i : drv.env)
|
|
|
|
|
out << i.first << i.second;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-08-17 15:12:54 +02:00
|
|
|
|
std::string hashPlaceholder(const std::string & outputName)
|
|
|
|
|
{
|
|
|
|
|
// FIXME: memoize?
|
|
|
|
|
return "/" + printHash32(hashString(htSHA256, "nix-output:" + outputName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-04 23:06:23 +02:00
|
|
|
|
}
|