2005-01-19 18:39:47 +02:00
|
|
|
#include "derivations.hh"
|
2006-11-30 19:43:04 +02:00
|
|
|
#include "store-api.hh"
|
2006-12-01 23:00:39 +02:00
|
|
|
#include "globals.hh"
|
2008-08-25 16:31:57 +03: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 18:57:40 +03:00
|
|
|
#include "worker-protocol.hh"
|
2016-06-02 19:43:36 +03:00
|
|
|
#include "fs-accessor.hh"
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
|
|
|
|
2020-07-09 02:11:39 +03:00
|
|
|
// FIXME Put this somewhere?
|
|
|
|
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
|
|
|
|
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
|
|
|
|
|
2020-07-12 18:02:36 +03:00
|
|
|
StorePath DerivationOutput::path(const Store & store, std::string_view drvName) const
|
2020-07-09 02:11:39 +03:00
|
|
|
{
|
|
|
|
return std::visit(overloaded {
|
2020-07-12 18:56:20 +03:00
|
|
|
[](DerivationOutputInputAddressed doi) {
|
2020-07-09 02:11:39 +03:00
|
|
|
return doi.path;
|
|
|
|
},
|
|
|
|
[&](DerivationOutputFixed dof) {
|
|
|
|
return store.makeFixedOutputPath(dof.hash.method, dof.hash.hash, drvName);
|
|
|
|
}
|
|
|
|
}, output);
|
|
|
|
}
|
|
|
|
|
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 15:28:26 +02:00
|
|
|
|
|
|
|
bool BasicDerivation::isBuiltin() const
|
|
|
|
{
|
|
|
|
return string(builder, 0, 8) == "builtin:";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePath writeDerivation(ref<Store> store,
|
2020-02-17 16:53:59 +02:00
|
|
|
const Derivation & drv, std::string_view name, RepairFlag repair)
|
2003-07-04 15:18:06 +03:00
|
|
|
{
|
2020-06-16 23:20:18 +03:00
|
|
|
auto references = drv.inputSrcs;
|
2015-07-17 20:24:28 +03:00
|
|
|
for (auto & i : drv.inputDrvs)
|
2020-06-16 23:20:18 +03:00
|
|
|
references.insert(i.first);
|
2005-01-25 23:28:25 +02: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). */
|
2020-02-17 16:53:59 +02:00
|
|
|
auto suffix = std::string(name) + drvExtension;
|
|
|
|
auto contents = drv.unparse(*store, false);
|
2012-07-31 02:55:41 +03:00
|
|
|
return settings.readOnlyMode
|
2016-06-01 15:49:12 +03: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 15:28:26 +02:00
|
|
|
: store->addTextToStore(suffix, contents, references, repair);
|
2003-07-04 15:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-14 11:54:57 +03: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)
|
2020-04-22 02:07:07 +03:00
|
|
|
throw FormatError("expected string '%1%'", s);
|
2016-09-14 11:54:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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 16:46:58 +03: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 18:55:19 +02:00
|
|
|
{
|
2010-04-19 16:46:58 +03: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 18:55:19 +02:00
|
|
|
if (s.size() == 0 || s[0] != '/')
|
2020-04-22 02:07:07 +03:00
|
|
|
throw FormatError("bad path '%1%' in derivation", s);
|
2010-04-19 16:46:58 +03: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 18:55:19 +02:00
|
|
|
}
|
2012-07-31 02:55:41 +03: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 18:55:19 +02:00
|
|
|
|
2016-09-14 11:54:57 +03: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 16:46:58 +03:00
|
|
|
static StringSet parseStrings(std::istream & str, bool arePaths)
|
2003-07-15 19:28:54 +03:00
|
|
|
{
|
2010-04-19 16:46:58 +03:00
|
|
|
StringSet res;
|
|
|
|
while (!endOfList(str))
|
|
|
|
res.insert(arePaths ? parsePath(str) : parseString(str));
|
|
|
|
return res;
|
2003-07-15 19:28:54 +03:00
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2020-07-13 19:22:56 +03:00
|
|
|
static DerivationOutput parseDerivationOutput(const Store & store, std::istringstream & str)
|
2020-03-23 05:43:07 +02:00
|
|
|
{
|
|
|
|
expect(str, ","); auto path = store.parseStorePath(parsePath(str));
|
|
|
|
expect(str, ","); auto hashAlgo = parseString(str);
|
|
|
|
expect(str, ","); const auto hash = parseString(str);
|
|
|
|
expect(str, ")");
|
|
|
|
|
|
|
|
if (hashAlgo != "") {
|
2020-06-17 07:55:47 +03:00
|
|
|
auto method = FileIngestionMethod::Flat;
|
2020-03-23 05:43:07 +02:00
|
|
|
if (string(hashAlgo, 0, 2) == "r:") {
|
|
|
|
method = FileIngestionMethod::Recursive;
|
|
|
|
hashAlgo = string(hashAlgo, 2);
|
|
|
|
}
|
|
|
|
const HashType hashType = parseHashType(hashAlgo);
|
|
|
|
|
2020-07-09 02:11:39 +03:00
|
|
|
return DerivationOutput {
|
|
|
|
.output = DerivationOutputFixed {
|
|
|
|
.hash = FixedOutputHash {
|
|
|
|
.method = std::move(method),
|
|
|
|
.hash = Hash(hash, hashType),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else
|
|
|
|
return DerivationOutput {
|
2020-07-12 18:56:20 +03:00
|
|
|
.output = DerivationOutputInputAddressed {
|
2020-07-09 02:11:39 +03:00
|
|
|
.path = std::move(path),
|
|
|
|
}
|
|
|
|
};
|
2020-03-23 05:43:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-16 20:32:28 +03:00
|
|
|
static Derivation parseDerivation(const Store & store, std::string && s, std::string_view name)
|
2003-07-16 00:24:05 +03:00
|
|
|
{
|
2005-01-19 13:16:11 +02:00
|
|
|
Derivation drv;
|
2020-07-08 22:38:01 +03:00
|
|
|
drv.name = name;
|
|
|
|
|
2020-07-13 19:22:56 +03:00
|
|
|
std::istringstream str(std::move(s));
|
2010-04-19 16:46:58 +03:00
|
|
|
expect(str, "Derive([");
|
2003-11-16 19:46:31 +02:00
|
|
|
|
2010-04-19 16:46:58 +03:00
|
|
|
/* Parse the list of outputs. */
|
|
|
|
while (!endOfList(str)) {
|
2019-12-05 20:11:09 +02:00
|
|
|
expect(str, "("); std::string id = parseString(str);
|
2020-06-17 07:55:47 +03:00
|
|
|
auto output = parseDerivationOutput(store, str);
|
|
|
|
drv.outputs.emplace(std::move(id), std::move(output));
|
* 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 18:55:19 +02:00
|
|
|
}
|
|
|
|
|
2010-04-19 16:46:58 +03:00
|
|
|
/* Parse the list of input derivations. */
|
|
|
|
expect(str, ",[");
|
|
|
|
while (!endOfList(str)) {
|
|
|
|
expect(str, "(");
|
|
|
|
Path drvPath = parsePath(str);
|
|
|
|
expect(str, ",[");
|
2019-12-05 20:11:09 +02:00
|
|
|
drv.inputDrvs.insert_or_assign(store.parseStorePath(drvPath), parseStrings(str, false));
|
2010-04-19 16:46:58 +03:00
|
|
|
expect(str, ")");
|
2005-01-20 16:10:19 +02:00
|
|
|
}
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
expect(str, ",["); drv.inputSrcs = store.parseStorePathSet(parseStrings(str, true));
|
2010-04-19 16:46:58 +03:00
|
|
|
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 15:32:37 +03:00
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2010-04-19 16:46:58 +03:00
|
|
|
expect(str, ")");
|
|
|
|
return drv;
|
|
|
|
}
|
2003-08-15 15:32:37 +03:00
|
|
|
|
2003-07-15 19:28:54 +03:00
|
|
|
|
2020-07-12 18:02:36 +03:00
|
|
|
Derivation readDerivation(const Store & store, const Path & drvPath, std::string_view name)
|
2014-04-08 20:24:29 +03:00
|
|
|
{
|
|
|
|
try {
|
2020-07-08 22:38:01 +03:00
|
|
|
return parseDerivation(store, readFile(drvPath), name);
|
2014-04-08 20:24:29 +03:00
|
|
|
} catch (FormatError & e) {
|
2020-04-22 02:07:07 +03:00
|
|
|
throw Error("error parsing derivation '%1%': %2%", drvPath, e.msg());
|
2014-04-08 20:24:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
Derivation Store::derivationFromPath(const StorePath & drvPath)
|
2016-06-02 19:43:36 +03:00
|
|
|
{
|
|
|
|
ensurePath(drvPath);
|
2020-06-12 14:04:52 +03:00
|
|
|
return readDerivation(drvPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Derivation Store::readDerivation(const StorePath & drvPath)
|
|
|
|
{
|
2016-06-02 19:43:36 +03:00
|
|
|
auto accessor = getFSAccessor();
|
|
|
|
try {
|
2020-07-12 18:26:30 +03:00
|
|
|
return parseDerivation(*this, accessor->readFile(printStorePath(drvPath)), Derivation::nameFromPath(drvPath));
|
2016-06-02 19:43:36 +03:00
|
|
|
} catch (FormatError & e) {
|
2019-12-05 20:11:09 +02:00
|
|
|
throw Error("error parsing derivation '%s': %s", printStorePath(drvPath), e.msg());
|
2016-06-02 19:43:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-23 17:36:19 +02:00
|
|
|
static void printString(string & res, std::string_view s)
|
|
|
|
{
|
|
|
|
char buf[s.size() * 2 + 2];
|
|
|
|
char * p = buf;
|
|
|
|
*p++ = '"';
|
|
|
|
for (auto c : s)
|
|
|
|
if (c == '\"' || c == '\\') { *p++ = '\\'; *p++ = c; }
|
|
|
|
else if (c == '\n') { *p++ = '\\'; *p++ = 'n'; }
|
|
|
|
else if (c == '\r') { *p++ = '\\'; *p++ = 'r'; }
|
|
|
|
else if (c == '\t') { *p++ = '\\'; *p++ = 't'; }
|
|
|
|
else *p++ = c;
|
|
|
|
*p++ = '"';
|
|
|
|
res.append(buf, p - buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void printUnquotedString(string & res, std::string_view s)
|
2010-04-19 16:46:58 +03:00
|
|
|
{
|
2010-04-21 22:25:50 +03:00
|
|
|
res += '"';
|
2020-02-23 17:36:19 +02:00
|
|
|
res.append(s);
|
2010-04-21 22:25:50 +03:00
|
|
|
res += '"';
|
2003-07-16 14:05:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-19 16:46:58 +03:00
|
|
|
template<class ForwardIterator>
|
2010-04-21 22:25:50 +03:00
|
|
|
static void printStrings(string & res, ForwardIterator i, ForwardIterator j)
|
2003-07-16 01:28:27 +03:00
|
|
|
{
|
2010-04-21 22:25:50 +03:00
|
|
|
res += '[';
|
2010-04-19 16:46:58 +03:00
|
|
|
bool first = true;
|
|
|
|
for ( ; i != j; ++i) {
|
2010-04-21 22:25:50 +03:00
|
|
|
if (first) first = false; else res += ',';
|
|
|
|
printString(res, *i);
|
2010-04-19 16:46:58 +03:00
|
|
|
}
|
2010-04-21 22:25:50 +03:00
|
|
|
res += ']';
|
2010-04-19 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-23 17:36:19 +02:00
|
|
|
template<class ForwardIterator>
|
|
|
|
static void printUnquotedStrings(string & res, ForwardIterator i, ForwardIterator j)
|
|
|
|
{
|
|
|
|
res += '[';
|
|
|
|
bool first = true;
|
|
|
|
for ( ; i != j; ++i) {
|
|
|
|
if (first) first = false; else res += ',';
|
|
|
|
printUnquotedString(res, *i);
|
|
|
|
}
|
|
|
|
res += ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
string Derivation::unparse(const Store & store, bool maskOutputs,
|
|
|
|
std::map<std::string, StringSet> * actualInputs) const
|
2010-04-19 16:46:58 +03:00
|
|
|
{
|
2010-04-21 22:25:50 +03:00
|
|
|
string s;
|
|
|
|
s.reserve(65536);
|
|
|
|
s += "Derive([";
|
2010-04-19 16:46:58 +03:00
|
|
|
|
2020-01-21 22:14:13 +02:00
|
|
|
bool first = true;
|
|
|
|
for (auto & i : outputs) {
|
|
|
|
if (first) first = false; else s += ',';
|
2020-02-23 17:36:19 +02:00
|
|
|
s += '('; printUnquotedString(s, i.first);
|
2020-07-09 02:11:39 +03:00
|
|
|
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(i.second.path(store, name)));
|
|
|
|
if (auto hash = std::get_if<DerivationOutputFixed>(&i.second.output)) {
|
|
|
|
s += ','; printUnquotedString(s, hash->hash.printMethodAlgo());
|
|
|
|
s += ','; printUnquotedString(s, hash->hash.hash.to_string(Base16, false));
|
|
|
|
} else {
|
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
}
|
2020-01-21 22:14:13 +02:00
|
|
|
s += ')';
|
2010-04-19 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
2010-04-21 22:25:50 +03:00
|
|
|
s += "],[";
|
2020-01-21 22:14:13 +02:00
|
|
|
first = true;
|
2019-12-05 20:11:09 +02:00
|
|
|
if (actualInputs) {
|
|
|
|
for (auto & i : *actualInputs) {
|
|
|
|
if (first) first = false; else s += ',';
|
2020-02-23 17:36:19 +02:00
|
|
|
s += '('; printUnquotedString(s, i.first);
|
|
|
|
s += ','; printUnquotedStrings(s, i.second.begin(), i.second.end());
|
2019-12-05 20:11:09 +02:00
|
|
|
s += ')';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (auto & i : inputDrvs) {
|
|
|
|
if (first) first = false; else s += ',';
|
2020-02-23 17:36:19 +02:00
|
|
|
s += '('; printUnquotedString(s, store.printStorePath(i.first));
|
|
|
|
s += ','; printUnquotedStrings(s, i.second.begin(), i.second.end());
|
2019-12-05 20:11:09 +02:00
|
|
|
s += ')';
|
|
|
|
}
|
2010-04-19 16:46:58 +03:00
|
|
|
}
|
|
|
|
|
2010-04-21 22:25:50 +03:00
|
|
|
s += "],";
|
2019-12-05 20:11:09 +02:00
|
|
|
auto paths = store.printStorePathSet(inputSrcs); // FIXME: slow
|
2020-02-23 17:36:19 +02:00
|
|
|
printUnquotedStrings(s, paths.begin(), paths.end());
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2020-02-23 17:36:19 +02:00
|
|
|
s += ','; printUnquotedString(s, platform);
|
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 15:28:26 +02:00
|
|
|
s += ','; printString(s, builder);
|
|
|
|
s += ','; printStrings(s, args.begin(), args.end());
|
2010-04-19 16:46:58 +03:00
|
|
|
|
2010-04-21 22:25:50 +03:00
|
|
|
s += ",[";
|
2010-04-19 16:46:58 +03: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 15:28:26 +02:00
|
|
|
for (auto & i : env) {
|
2010-04-21 22:25:50 +03:00
|
|
|
if (first) first = false; else s += ',';
|
2015-07-17 20:24:28 +03:00
|
|
|
s += '('; printString(s, i.first);
|
2020-01-21 22:14:13 +02:00
|
|
|
s += ','; printString(s, maskOutputs && outputs.count(i.first) ? "" : i.second);
|
2010-04-21 22:25:50 +03:00
|
|
|
s += ')';
|
2010-04-19 16:46:58 +03:00
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2010-04-21 22:25:50 +03:00
|
|
|
s += "])";
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2010-04-21 22:25:50 +03:00
|
|
|
return s;
|
2003-07-16 01:28:27 +03:00
|
|
|
}
|
2005-01-19 16:36:00 +02:00
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
// FIXME: remove
|
2005-01-19 16:36:00 +02:00
|
|
|
bool isDerivation(const string & fileName)
|
|
|
|
{
|
2008-08-25 16:31:57 +03:00
|
|
|
return hasSuffix(fileName, drvExtension);
|
2005-01-19 16:36:00 +02:00
|
|
|
}
|
2006-09-05 00:06:23 +03:00
|
|
|
|
2012-07-31 02:55:41 +03: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 15:28:26 +02:00
|
|
|
bool BasicDerivation::isFixedOutput() const
|
2011-07-20 21:10:47 +03: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 15:28:26 +02:00
|
|
|
return outputs.size() == 1 &&
|
|
|
|
outputs.begin()->first == "out" &&
|
2020-07-09 02:11:39 +03:00
|
|
|
std::holds_alternative<DerivationOutputFixed>(outputs.begin()->second.output);
|
2011-07-20 21:10:47 +03: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. */
|
2019-12-05 20:11:09 +02:00
|
|
|
Hash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutputs)
|
2011-07-20 21:10:47 +03: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 15:28:26 +02:00
|
|
|
if (drv.isFixedOutput()) {
|
2011-07-20 21:10:47 +03:00
|
|
|
DerivationOutputs::const_iterator i = drv.outputs.begin();
|
2020-07-09 02:11:39 +03:00
|
|
|
auto hash = std::get<DerivationOutputFixed>(i->second.output);
|
2011-07-20 21:10:47 +03:00
|
|
|
return hashString(htSHA256, "fixed:out:"
|
2020-07-09 02:11:39 +03:00
|
|
|
+ hash.hash.printMethodAlgo() + ":"
|
|
|
|
+ hash.hash.hash.to_string(Base16, false) + ":"
|
|
|
|
+ store.printStorePath(i->second.path(store, drv.name)));
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* For other derivations, replace the inputs paths with recursive
|
|
|
|
calls to this function.*/
|
2019-12-05 20:11:09 +02:00
|
|
|
std::map<std::string, StringSet> inputs2;
|
2015-07-17 20:24:28 +03:00
|
|
|
for (auto & i : drv.inputDrvs) {
|
2019-12-05 20:11:09 +02:00
|
|
|
auto h = drvHashes.find(i.first);
|
|
|
|
if (h == drvHashes.end()) {
|
2015-07-17 20:24:28 +03:00
|
|
|
assert(store.isValidPath(i.first));
|
2020-06-16 23:20:18 +03:00
|
|
|
h = drvHashes.insert_or_assign(i.first, hashDerivationModulo(store,
|
2020-07-12 18:54:12 +03:00
|
|
|
store.readDerivation(i.first), false)).first;
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
2019-12-05 20:11:09 +02:00
|
|
|
inputs2.insert_or_assign(h->second.to_string(Base16, false), i.second);
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
return hashString(htSHA256, drv.unparse(store, maskOutputs, &inputs2));
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
std::string StorePathWithOutputs::to_string(const Store & store) const
|
2012-11-26 16:39:10 +02:00
|
|
|
{
|
|
|
|
return outputs.empty()
|
2019-12-05 20:11:09 +02:00
|
|
|
? store.printStorePath(path)
|
|
|
|
: store.printStorePath(path) + "!" + concatStringsSep(",", outputs);
|
2012-11-26 16:39:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-26 18:15:09 +02:00
|
|
|
bool wantOutput(const string & output, const std::set<string> & wanted)
|
|
|
|
{
|
|
|
|
return wanted.empty() || wanted.find(output) != wanted.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-09 02:11:39 +03:00
|
|
|
StorePathSet BasicDerivation::outputPaths(const Store & store) const
|
2015-06-10 17:17:06 +03:00
|
|
|
{
|
2019-12-05 20:11:09 +02:00
|
|
|
StorePathSet 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 15:28:26 +02:00
|
|
|
for (auto & i : outputs)
|
2020-07-09 02:11:39 +03:00
|
|
|
paths.insert(i.second.path(store, name));
|
2015-06-10 17:17:06 +03:00
|
|
|
return paths;
|
|
|
|
}
|
|
|
|
|
2020-03-23 05:43:07 +02:00
|
|
|
static DerivationOutput readDerivationOutput(Source & in, const Store & store)
|
|
|
|
{
|
|
|
|
auto path = store.parseStorePath(readString(in));
|
|
|
|
auto hashAlgo = readString(in);
|
2020-06-25 16:50:30 +03:00
|
|
|
auto hash = readString(in);
|
2020-03-23 05:43:07 +02:00
|
|
|
|
|
|
|
if (hashAlgo != "") {
|
2020-06-17 07:55:47 +03:00
|
|
|
auto method = FileIngestionMethod::Flat;
|
2020-03-23 05:43:07 +02:00
|
|
|
if (string(hashAlgo, 0, 2) == "r:") {
|
|
|
|
method = FileIngestionMethod::Recursive;
|
|
|
|
hashAlgo = string(hashAlgo, 2);
|
|
|
|
}
|
2020-06-25 16:50:30 +03:00
|
|
|
auto hashType = parseHashType(hashAlgo);
|
2020-07-09 02:11:39 +03:00
|
|
|
return DerivationOutput {
|
|
|
|
.output = DerivationOutputFixed {
|
|
|
|
.hash = FixedOutputHash {
|
|
|
|
.method = std::move(method),
|
|
|
|
.hash = Hash(hash, hashType),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else
|
|
|
|
return DerivationOutput {
|
2020-07-12 18:56:20 +03:00
|
|
|
.output = DerivationOutputInputAddressed {
|
2020-07-09 02:11:39 +03:00
|
|
|
.path = std::move(path),
|
|
|
|
}
|
2020-03-23 05:43:07 +02:00
|
|
|
};
|
|
|
|
}
|
2015-06-10 17:17:06 +03:00
|
|
|
|
2020-06-12 13:46:33 +03:00
|
|
|
StringSet BasicDerivation::outputNames() const
|
|
|
|
{
|
|
|
|
StringSet names;
|
|
|
|
for (auto & i : outputs)
|
|
|
|
names.insert(i.first);
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 18:26:30 +03:00
|
|
|
std::string_view BasicDerivation::nameFromPath(const StorePath & drvPath) {
|
|
|
|
auto nameWithSuffix = drvPath.name();
|
|
|
|
constexpr std::string_view extension = ".drv";
|
|
|
|
assert(hasSuffix(nameWithSuffix, extension));
|
|
|
|
nameWithSuffix.remove_suffix(extension.size());
|
|
|
|
return nameWithSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-12 18:02:36 +03:00
|
|
|
Source & readDerivation(Source & in, const Store & store, BasicDerivation & drv, std::string_view name)
|
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 18:57:40 +03:00
|
|
|
{
|
2020-07-08 22:38:01 +03:00
|
|
|
drv.name = name;
|
|
|
|
|
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 18:57:40 +03:00
|
|
|
drv.outputs.clear();
|
2017-03-01 14:52:54 +02:00
|
|
|
auto nr = readNum<size_t>(in);
|
|
|
|
for (size_t n = 0; n < nr; n++) {
|
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 18:57:40 +03:00
|
|
|
auto name = readString(in);
|
2020-03-23 05:43:07 +02:00
|
|
|
auto output = readDerivationOutput(in, store);
|
2020-06-17 07:55:47 +03:00
|
|
|
drv.outputs.emplace(std::move(name), std::move(output));
|
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 18:57:40 +03:00
|
|
|
}
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
drv.inputSrcs = readStorePaths<StorePathSet>(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 18:57:40 +03:00
|
|
|
in >> drv.platform >> drv.builder;
|
|
|
|
drv.args = readStrings<Strings>(in);
|
|
|
|
|
2017-03-01 14:52:54 +02:00
|
|
|
nr = readNum<size_t>(in);
|
|
|
|
for (size_t n = 0; n < nr; n++) {
|
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 18:57:40 +03:00
|
|
|
auto key = readString(in);
|
|
|
|
auto value = readString(in);
|
|
|
|
drv.env[key] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-05 20:11:09 +02:00
|
|
|
void writeDerivation(Sink & out, const Store & store, const 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 18:57:40 +03:00
|
|
|
{
|
|
|
|
out << drv.outputs.size();
|
2020-06-25 16:50:30 +03:00
|
|
|
for (auto & i : drv.outputs) {
|
2020-03-23 05:43:07 +02:00
|
|
|
out << i.first
|
2020-07-09 02:11:39 +03:00
|
|
|
<< store.printStorePath(i.second.path(store, drv.name));
|
|
|
|
if (auto hash = std::get_if<DerivationOutputFixed>(&i.second.output)) {
|
|
|
|
out << hash->hash.printMethodAlgo()
|
|
|
|
<< hash->hash.hash.to_string(Base16, false);
|
2020-06-25 16:50:30 +03:00
|
|
|
} else {
|
|
|
|
out << "" << "";
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 20:11:09 +02:00
|
|
|
writeStorePaths(store, out, drv.inputSrcs);
|
|
|
|
out << drv.platform << drv.builder << drv.args;
|
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 18:57:40 +03:00
|
|
|
out << drv.env.size();
|
|
|
|
for (auto & i : drv.env)
|
|
|
|
out << i.first << i.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-17 16:12:54 +03:00
|
|
|
std::string hashPlaceholder(const std::string & outputName)
|
|
|
|
{
|
|
|
|
// FIXME: memoize?
|
2017-07-04 15:47:59 +03:00
|
|
|
return "/" + hashString(htSHA256, "nix-output:" + outputName).to_string(Base32, false);
|
2016-08-17 16:12:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|