2005-01-19 18:39:47 +02:00
|
|
|
#include "derivations.hh"
|
2023-05-12 01:01:41 +03:00
|
|
|
#include "downstream-placeholder.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"
|
2020-10-13 02:51:23 +03:00
|
|
|
#include "split.hh"
|
2022-03-25 06:39:57 +02:00
|
|
|
#include "common-protocol.hh"
|
|
|
|
#include "common-protocol-impl.hh"
|
2022-01-19 16:20:46 +02:00
|
|
|
#include <boost/container/small_vector.hpp>
|
2023-02-18 01:37:35 +02:00
|
|
|
#include <nlohmann/json.hpp>
|
2003-06-16 16:33:38 +03:00
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
namespace nix {
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
std::optional<StorePath> DerivationOutput::path(const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName) const
|
2020-07-09 02:11:39 +03:00
|
|
|
{
|
|
|
|
return std::visit(overloaded {
|
2022-03-18 00:29:15 +02:00
|
|
|
[](const DerivationOutput::InputAddressed & doi) -> std::optional<StorePath> {
|
2020-07-12 19:12:21 +03:00
|
|
|
return { doi.path };
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFixed & dof) -> std::optional<StorePath> {
|
2020-07-12 19:12:21 +03:00
|
|
|
return {
|
2020-08-14 20:00:13 +03:00
|
|
|
dof.path(store, drvName, outputName)
|
2020-07-12 19:12:21 +03:00
|
|
|
};
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[](const DerivationOutput::CAFloating & dof) -> std::optional<StorePath> {
|
2020-07-12 19:12:21 +03:00
|
|
|
return std::nullopt;
|
2020-07-09 02:11:39 +03:00
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[](const DerivationOutput::Deferred &) -> std::optional<StorePath> {
|
2020-09-23 17:30:42 +03:00
|
|
|
return std::nullopt;
|
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[](const DerivationOutput::Impure &) -> std::optional<StorePath> {
|
|
|
|
return std::nullopt;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2020-07-09 02:11:39 +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
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
StorePath DerivationOutput::CAFixed::path(const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName) const
|
2022-03-30 17:31:01 +03:00
|
|
|
{
|
2023-01-23 23:54:45 +02:00
|
|
|
return store.makeFixedOutputPathFromCA(
|
2020-10-07 16:52:20 +03:00
|
|
|
outputPathName(drvName, outputName),
|
2023-04-19 21:48:53 +03:00
|
|
|
ContentAddressWithReferences::withoutRefs(ca));
|
2020-08-07 22:09:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
bool DerivationType::isCA() const
|
|
|
|
{
|
2022-03-18 02:36:52 +02:00
|
|
|
/* Normally we do the full `std::visit` to make sure we have
|
|
|
|
exhaustively handled all variants, but so long as there is a
|
|
|
|
variant called `ContentAddressed`, it must be the only one for
|
|
|
|
which `isCA` is true for this to make sense!. */
|
2022-03-30 17:31:01 +03:00
|
|
|
return std::visit(overloaded {
|
|
|
|
[](const InputAddressed & ia) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
[](const ContentAddressed & ca) {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
[](const Impure &) {
|
|
|
|
return true;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2020-06-03 20:38:54 +03:00
|
|
|
}
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
bool DerivationType::isFixed() const
|
|
|
|
{
|
2022-03-18 02:36:52 +02:00
|
|
|
return std::visit(overloaded {
|
|
|
|
[](const InputAddressed & ia) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
[](const ContentAddressed & ca) {
|
|
|
|
return ca.fixed;
|
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[](const Impure &) {
|
|
|
|
return false;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2020-06-03 20:38:54 +03:00
|
|
|
}
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
bool DerivationType::hasKnownOutputPaths() const
|
|
|
|
{
|
2022-03-18 02:36:52 +02:00
|
|
|
return std::visit(overloaded {
|
|
|
|
[](const InputAddressed & ia) {
|
|
|
|
return !ia.deferred;
|
|
|
|
},
|
|
|
|
[](const ContentAddressed & ca) {
|
|
|
|
return ca.fixed;
|
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[](const Impure &) {
|
|
|
|
return false;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2021-02-26 17:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-31 17:06:40 +03:00
|
|
|
bool DerivationType::isSandboxed() const
|
2022-03-30 17:31:01 +03:00
|
|
|
{
|
2022-03-18 02:36:52 +02:00
|
|
|
return std::visit(overloaded {
|
|
|
|
[](const InputAddressed & ia) {
|
2022-03-31 17:06:40 +03:00
|
|
|
return true;
|
2022-03-18 02:36:52 +02:00
|
|
|
},
|
|
|
|
[](const ContentAddressed & ca) {
|
2022-03-31 17:12:25 +03:00
|
|
|
return ca.sandboxed;
|
2022-03-18 02:36:52 +02:00
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[](const Impure &) {
|
2022-03-18 02:36:52 +02:00
|
|
|
return false;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2022-03-30 17:31:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DerivationType::isPure() const
|
|
|
|
{
|
|
|
|
return std::visit(overloaded {
|
|
|
|
[](const InputAddressed & ia) {
|
|
|
|
return true;
|
|
|
|
},
|
2022-03-18 02:36:52 +02:00
|
|
|
[](const ContentAddressed & ca) {
|
2022-03-30 17:31:01 +03:00
|
|
|
return true;
|
|
|
|
},
|
|
|
|
[](const Impure &) {
|
|
|
|
return false;
|
2022-03-18 02:36:52 +02:00
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2020-06-03 20:38:54 +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::isBuiltin() const
|
|
|
|
{
|
2022-02-25 17:00:00 +02:00
|
|
|
return builder.substr(0, 8) == "builtin:";
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-23 18:00:25 +03:00
|
|
|
StorePath writeDerivation(Store & store,
|
2020-09-04 21:33:58 +03:00
|
|
|
const Derivation & drv, RepairFlag repair, bool readOnly)
|
2003-07-04 15:18:06 +03:00
|
|
|
{
|
2020-06-16 23:20:18 +03:00
|
|
|
auto references = drv.inputSrcs;
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & i : drv.inputDrvs.map)
|
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-08-09 23:32:35 +03:00
|
|
|
auto suffix = std::string(drv.name) + drvExtension;
|
2020-08-23 18:00:25 +03:00
|
|
|
auto contents = drv.unparse(store, false);
|
2020-09-04 21:33:58 +03:00
|
|
|
return readOnly || settings.readOnlyMode
|
2023-11-09 04:11:48 +02:00
|
|
|
? store.makeFixedOutputPathFromCA(suffix, TextInfo {
|
|
|
|
.hash = hashString(HashAlgorithm::SHA256, contents),
|
|
|
|
.references = std::move(references),
|
|
|
|
})
|
|
|
|
: ({
|
|
|
|
StringSource s { contents };
|
|
|
|
store.addToStoreFromDump(s, suffix, TextIngestionMethod {}, HashAlgorithm::SHA256, references, repair);
|
|
|
|
});
|
2003-07-04 15:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-14 11:54:57 +03:00
|
|
|
/* Read string `s' from stream `str'. */
|
2022-02-25 17:00:00 +02:00
|
|
|
static void expect(std::istream & str, std::string_view s)
|
2016-09-14 11:54:57 +03:00
|
|
|
{
|
2022-11-18 14:02:06 +02:00
|
|
|
for (auto & c : s) {
|
|
|
|
if (str.get() != c)
|
|
|
|
throw FormatError("expected string '%1%'", s);
|
|
|
|
}
|
2016-09-14 11:54:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read a C-style string from stream `str'. */
|
2022-02-25 17:00:00 +02:00
|
|
|
static std::string parseString(std::istream & str)
|
2016-09-14 11:54:57 +03:00
|
|
|
{
|
2022-02-25 17:00:00 +02:00
|
|
|
std::string res;
|
2016-09-14 11:54:57 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-07 22:09:26 +03:00
|
|
|
static void validatePath(std::string_view s) {
|
|
|
|
if (s.size() == 0 || s[0] != '/')
|
|
|
|
throw FormatError("bad path '%1%' in derivation", s);
|
|
|
|
}
|
2016-09-14 11:54:57 +03:00
|
|
|
|
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
|
|
|
{
|
2020-08-07 22:09:26 +03:00
|
|
|
auto s = parseString(str);
|
|
|
|
validatePath(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;
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
expect(str, "[");
|
2010-04-19 16:46:58 +03:00
|
|
|
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
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
static DerivationOutput parseDerivationOutput(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store,
|
2023-11-28 15:20:27 +02:00
|
|
|
std::string_view pathS, std::string_view hashAlgoStr, std::string_view hashS,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2020-03-23 05:43:07 +02:00
|
|
|
{
|
2023-11-28 15:20:27 +02:00
|
|
|
if (hashAlgoStr != "") {
|
|
|
|
ContentAddressMethod method = ContentAddressMethod::parsePrefix(hashAlgoStr);
|
2023-04-18 02:02:45 +03:00
|
|
|
if (method == TextIngestionMethod {})
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
2023-11-28 15:20:27 +02:00
|
|
|
const auto hashAlgo = parseHashAlgo(hashAlgoStr);
|
2022-04-20 01:39:57 +03:00
|
|
|
if (hashS == "impure") {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
xpSettings.require(Xp::ImpureDerivations);
|
2023-09-06 18:35:01 +03:00
|
|
|
if (pathS != "")
|
|
|
|
throw FormatError("impure derivation output should not specify output path");
|
2022-03-31 17:39:18 +03:00
|
|
|
return DerivationOutput::Impure {
|
|
|
|
.method = std::move(method),
|
2023-11-28 15:20:27 +02:00
|
|
|
.hashAlgo = std::move(hashAlgo),
|
2022-03-30 17:31:01 +03:00
|
|
|
};
|
2022-04-20 01:39:57 +03:00
|
|
|
} else if (hashS != "") {
|
2020-08-07 22:09:26 +03:00
|
|
|
validatePath(pathS);
|
2023-11-28 15:20:27 +02:00
|
|
|
auto hash = Hash::parseNonSRIUnprefixed(hashS, hashAlgo);
|
2022-03-18 00:29:15 +02:00
|
|
|
return DerivationOutput::CAFixed {
|
2023-07-06 01:53:44 +03:00
|
|
|
.ca = ContentAddress {
|
|
|
|
.method = std::move(method),
|
|
|
|
.hash = std::move(hash),
|
|
|
|
},
|
2020-08-07 22:09:26 +03:00
|
|
|
};
|
|
|
|
} else {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
xpSettings.require(Xp::CaDerivations);
|
2023-09-06 18:35:01 +03:00
|
|
|
if (pathS != "")
|
|
|
|
throw FormatError("content-addressed derivation output should not specify output path");
|
2022-03-18 00:29:15 +02:00
|
|
|
return DerivationOutput::CAFloating {
|
|
|
|
.method = std::move(method),
|
2023-11-28 15:20:27 +02:00
|
|
|
.hashAlgo = std::move(hashAlgo),
|
2020-08-07 22:09:26 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-23 17:30:42 +03:00
|
|
|
if (pathS == "") {
|
2022-03-18 00:29:15 +02:00
|
|
|
return DerivationOutput::Deferred { };
|
2020-09-23 17:30:42 +03:00
|
|
|
}
|
2020-08-07 22:09:26 +03:00
|
|
|
validatePath(pathS);
|
2022-03-18 00:29:15 +02:00
|
|
|
return DerivationOutput::InputAddressed {
|
|
|
|
.path = store.parseStorePath(pathS),
|
2020-07-09 02:11:39 +03:00
|
|
|
};
|
2020-08-07 22:09:26 +03:00
|
|
|
}
|
2020-03-23 05:43:07 +02:00
|
|
|
}
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
static DerivationOutput parseDerivationOutput(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store, std::istringstream & str,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings)
|
2020-08-09 23:51:34 +03:00
|
|
|
{
|
2020-08-11 03:12:54 +03:00
|
|
|
expect(str, ","); const auto pathS = parseString(str);
|
2020-08-09 23:51:34 +03:00
|
|
|
expect(str, ","); const auto hashAlgo = parseString(str);
|
|
|
|
expect(str, ","); const auto hash = parseString(str);
|
|
|
|
expect(str, ")");
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
return parseDerivationOutput(store, pathS, hashAlgo, hash, xpSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All ATerm Derivation format versions currently known.
|
|
|
|
*
|
|
|
|
* Unknown versions are rejected at the parsing stage.
|
|
|
|
*/
|
|
|
|
enum struct DerivationATermVersion {
|
|
|
|
/**
|
|
|
|
* Older unversioned form
|
|
|
|
*/
|
|
|
|
Traditional,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Newer versioned form; only this version so far.
|
|
|
|
*/
|
|
|
|
DynamicDerivations,
|
|
|
|
};
|
|
|
|
|
|
|
|
static DerivedPathMap<StringSet>::ChildNode parseDerivedPathMapNode(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
std::istringstream & str,
|
|
|
|
DerivationATermVersion version)
|
|
|
|
{
|
|
|
|
DerivedPathMap<StringSet>::ChildNode node;
|
|
|
|
|
|
|
|
auto parseNonDynamic = [&]() {
|
|
|
|
node.value = parseStrings(str, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Older derivation should never use new form, but newer
|
|
|
|
// derivaiton can use old form.
|
|
|
|
switch (version) {
|
|
|
|
case DerivationATermVersion::Traditional:
|
|
|
|
parseNonDynamic();
|
|
|
|
break;
|
|
|
|
case DerivationATermVersion::DynamicDerivations:
|
|
|
|
switch (str.peek()) {
|
|
|
|
case '[':
|
|
|
|
parseNonDynamic();
|
|
|
|
break;
|
|
|
|
case '(':
|
|
|
|
expect(str, "(");
|
|
|
|
node.value = parseStrings(str, false);
|
|
|
|
expect(str, ",[");
|
|
|
|
while (!endOfList(str)) {
|
|
|
|
expect(str, "(");
|
|
|
|
auto outputName = parseString(str);
|
|
|
|
expect(str, ",");
|
|
|
|
node.childMap.insert_or_assign(outputName, parseDerivedPathMapNode(store, str, version));
|
|
|
|
expect(str, ")");
|
|
|
|
}
|
|
|
|
expect(str, ")");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw FormatError("invalid inputDrvs entry in derivation");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// invalid format, not a parse error but internal error
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
return node;
|
2020-08-09 23:51:34 +03:00
|
|
|
}
|
|
|
|
|
2020-03-23 05:43:07 +02:00
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
Derivation parseDerivation(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store, std::string && s, std::string_view name,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
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));
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
expect(str, "D");
|
|
|
|
DerivationATermVersion version;
|
|
|
|
switch (str.peek()) {
|
|
|
|
case 'e':
|
|
|
|
expect(str, "erive(");
|
|
|
|
version = DerivationATermVersion::Traditional;
|
|
|
|
break;
|
2023-11-03 12:39:50 +02:00
|
|
|
case 'r': {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
expect(str, "rvWithVersion(");
|
|
|
|
auto versionS = parseString(str);
|
|
|
|
if (versionS == "xp-dyn-drv") {
|
|
|
|
// Only verison we have so far
|
|
|
|
version = DerivationATermVersion::DynamicDerivations;
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
|
|
|
} else {
|
|
|
|
throw FormatError("Unknown derivation ATerm format version '%s'", versionS);
|
|
|
|
}
|
|
|
|
expect(str, ",");
|
|
|
|
break;
|
|
|
|
}
|
2023-11-03 12:39:50 +02:00
|
|
|
default:
|
|
|
|
throw Error("derivation does not start with 'Derive' or 'DrvWithVersion'");
|
|
|
|
}
|
2003-11-16 19:46:31 +02:00
|
|
|
|
2010-04-19 16:46:58 +03:00
|
|
|
/* Parse the list of outputs. */
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
expect(str, "[");
|
2010-04-19 16:46:58 +03:00
|
|
|
while (!endOfList(str)) {
|
2019-12-05 20:11:09 +02:00
|
|
|
expect(str, "("); std::string id = parseString(str);
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
auto output = parseDerivationOutput(store, str, xpSettings);
|
2020-06-17 07:55:47 +03:00
|
|
|
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);
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
expect(str, ",");
|
|
|
|
drv.inputDrvs.map.insert_or_assign(store.parseStorePath(drvPath), parseDerivedPathMapNode(store, str, version));
|
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
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03: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)) {
|
2022-02-25 17:00:00 +02:00
|
|
|
expect(str, "("); auto name = parseString(str);
|
|
|
|
expect(str, ","); auto value = parseString(str);
|
2010-04-19 16:46:58 +03:00
|
|
|
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
|
|
|
|
2023-04-09 23:42:20 +03:00
|
|
|
/**
|
2023-04-15 21:56:51 +03:00
|
|
|
* Print a derivation string literal to an `std::string`.
|
2023-04-09 23:42:20 +03:00
|
|
|
*
|
|
|
|
* This syntax does not generalize to the expression language, which needs to
|
|
|
|
* escape `$`.
|
|
|
|
*
|
|
|
|
* @param res Where to print to
|
|
|
|
* @param s Which logical string to print
|
|
|
|
*/
|
2022-02-25 17:00:00 +02:00
|
|
|
static void printString(std::string & res, std::string_view s)
|
2020-02-23 17:36:19 +02:00
|
|
|
{
|
2022-01-21 18:25:37 +02:00
|
|
|
boost::container::small_vector<char, 64 * 1024> buffer;
|
2022-01-19 16:20:46 +02:00
|
|
|
buffer.reserve(s.size() * 2 + 2);
|
|
|
|
char * buf = buffer.data();
|
2020-02-23 17:36:19 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-25 17:00:00 +02:00
|
|
|
static void printUnquotedString(std::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>
|
2022-02-25 17:00:00 +02:00
|
|
|
static void printStrings(std::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>
|
2022-02-25 17:00:00 +02:00
|
|
|
static void printUnquotedStrings(std::string & res, ForwardIterator i, ForwardIterator j)
|
2020-02-23 17:36:19 +02:00
|
|
|
{
|
|
|
|
res += '[';
|
|
|
|
bool first = true;
|
|
|
|
for ( ; i != j; ++i) {
|
|
|
|
if (first) first = false; else res += ',';
|
|
|
|
printUnquotedString(res, *i);
|
|
|
|
}
|
|
|
|
res += ']';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
static void unparseDerivedPathMapNode(const StoreDirConfig & store, std::string & s, const DerivedPathMap<StringSet>::ChildNode & node)
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
{
|
|
|
|
s += ',';
|
|
|
|
if (node.childMap.empty()) {
|
|
|
|
printUnquotedStrings(s, node.value.begin(), node.value.end());
|
|
|
|
} else {
|
|
|
|
s += "(";
|
|
|
|
printUnquotedStrings(s, node.value.begin(), node.value.end());
|
|
|
|
s += ",[";
|
|
|
|
bool first = true;
|
|
|
|
for (auto & [outputName, childNode] : node.childMap) {
|
|
|
|
if (first) first = false; else s += ',';
|
|
|
|
s += '('; printUnquotedString(s, outputName);
|
|
|
|
unparseDerivedPathMapNode(store, s, childNode);
|
|
|
|
s += ')';
|
|
|
|
}
|
|
|
|
s += "])";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the derivation have a dependency on the output of a dynamic
|
|
|
|
* derivation?
|
|
|
|
*
|
|
|
|
* In other words, does it on the output of derivation that is itself an
|
|
|
|
* ouput of a derivation? This corresponds to a dependency that is an
|
|
|
|
* inductive derived path with more than one layer of
|
|
|
|
* `DerivedPath::Built`.
|
|
|
|
*/
|
|
|
|
static bool hasDynamicDrvDep(const Derivation & drv)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
std::find_if(
|
|
|
|
drv.inputDrvs.map.begin(),
|
|
|
|
drv.inputDrvs.map.end(),
|
|
|
|
[](auto & kv) { return !kv.second.childMap.empty(); })
|
|
|
|
!= drv.inputDrvs.map.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
std::string Derivation::unparse(const StoreDirConfig & store, bool maskOutputs,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
DerivedPathMap<StringSet>::ChildNode::Map * actualInputs) const
|
2010-04-19 16:46:58 +03:00
|
|
|
{
|
2022-02-25 17:00:00 +02:00
|
|
|
std::string s;
|
2010-04-21 22:25:50 +03:00
|
|
|
s.reserve(65536);
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
|
|
|
|
/* Use older unversioned form if possible, for wider compat. Use
|
|
|
|
newer form only if we need it, which we do for
|
|
|
|
`Xp::DynamicDerivations`. */
|
|
|
|
if (hasDynamicDrvDep(*this)) {
|
|
|
|
s += "DrvWithVersion(";
|
|
|
|
// Only version we have so far
|
|
|
|
printUnquotedString(s, "xp-dyn-drv");
|
|
|
|
s += ",";
|
|
|
|
} else {
|
|
|
|
s += "Derive(";
|
|
|
|
}
|
2010-04-19 16:46:58 +03:00
|
|
|
|
2020-01-21 22:14:13 +02:00
|
|
|
bool first = true;
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
s += "[";
|
2020-01-21 22:14:13 +02:00
|
|
|
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-12 19:12:21 +03:00
|
|
|
std::visit(overloaded {
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::InputAddressed & doi) {
|
2020-08-07 22:09:26 +03:00
|
|
|
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(doi.path));
|
2020-07-12 19:12:21 +03:00
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFixed & dof) {
|
2020-08-07 22:09:26 +03:00
|
|
|
s += ','; printUnquotedString(s, maskOutputs ? "" : store.printStorePath(dof.path(store, name, i.first)));
|
2023-04-01 23:40:32 +03:00
|
|
|
s += ','; printUnquotedString(s, dof.ca.printMethodAlgo());
|
2023-10-13 04:48:15 +03:00
|
|
|
s += ','; printUnquotedString(s, dof.ca.hash.to_string(HashFormat::Base16, false));
|
2020-07-12 19:12:21 +03:00
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFloating & dof) {
|
2020-08-07 22:09:26 +03:00
|
|
|
s += ','; printUnquotedString(s, "");
|
2023-11-28 15:20:27 +02:00
|
|
|
s += ','; printUnquotedString(s, dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo));
|
2020-07-12 19:12:21 +03:00
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::Deferred &) {
|
2020-09-23 17:30:42 +03:00
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
s += ','; printUnquotedString(s, "");
|
|
|
|
s += ','; printUnquotedString(s, "");
|
2022-03-30 17:31:01 +03:00
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
[&](const DerivationOutput::Impure & doi) {
|
2022-03-30 17:31:01 +03:00
|
|
|
// FIXME
|
|
|
|
s += ','; printUnquotedString(s, "");
|
2023-11-28 15:20:27 +02:00
|
|
|
s += ','; printUnquotedString(s, doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo));
|
2022-03-30 17:31:01 +03:00
|
|
|
s += ','; printUnquotedString(s, "impure");
|
2020-09-23 17:30:42 +03:00
|
|
|
}
|
2023-08-16 19:29:23 +03:00
|
|
|
}, i.second.raw);
|
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) {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & [drvHashModulo, childMap] : *actualInputs) {
|
2019-12-05 20:11:09 +02:00
|
|
|
if (first) first = false; else s += ',';
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
s += '('; printUnquotedString(s, drvHashModulo);
|
|
|
|
unparseDerivedPathMapNode(store, s, childMap);
|
2019-12-05 20:11:09 +02:00
|
|
|
s += ')';
|
|
|
|
}
|
|
|
|
} else {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & [drvPath, childMap] : inputDrvs.map) {
|
2019-12-05 20:11:09 +02:00
|
|
|
if (first) first = false; else s += ',';
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
s += '('; printUnquotedString(s, store.printStorePath(drvPath));
|
|
|
|
unparseDerivedPathMapNode(store, s, childMap);
|
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
|
2022-12-07 13:58:58 +02:00
|
|
|
bool isDerivation(std::string_view fileName)
|
2005-01-19 16:36:00 +02:00
|
|
|
{
|
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
|
|
|
|
2023-08-25 16:53:12 +03:00
|
|
|
std::string outputPathName(std::string_view drvName, OutputNameView outputName) {
|
2020-08-07 22:09:26 +03:00
|
|
|
std::string res { drvName };
|
|
|
|
if (outputName != "out") {
|
|
|
|
res += "-";
|
|
|
|
res += outputName;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-15 08:23:17 +02:00
|
|
|
DerivationType BasicDerivation::type() const
|
2011-07-20 21:10:47 +03:00
|
|
|
{
|
2022-03-30 17:31:01 +03:00
|
|
|
std::set<std::string_view>
|
|
|
|
inputAddressedOutputs,
|
|
|
|
fixedCAOutputs,
|
|
|
|
floatingCAOutputs,
|
|
|
|
deferredIAOutputs,
|
|
|
|
impureOutputs;
|
2023-11-28 15:20:27 +02:00
|
|
|
std::optional<HashAlgorithm> floatingHashAlgo;
|
2022-03-30 17:31:01 +03:00
|
|
|
|
2020-07-17 18:33:27 +03:00
|
|
|
for (auto & i : outputs) {
|
|
|
|
std::visit(overloaded {
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::InputAddressed &) {
|
2020-07-17 18:33:27 +03:00
|
|
|
inputAddressedOutputs.insert(i.first);
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFixed &) {
|
2020-07-17 18:33:27 +03:00
|
|
|
fixedCAOutputs.insert(i.first);
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFloating & dof) {
|
2020-07-17 22:55:41 +03:00
|
|
|
floatingCAOutputs.insert(i.first);
|
2023-11-28 15:20:27 +02:00
|
|
|
if (!floatingHashAlgo) {
|
|
|
|
floatingHashAlgo = dof.hashAlgo;
|
2020-07-17 22:55:41 +03:00
|
|
|
} else {
|
2023-11-28 15:20:27 +02:00
|
|
|
if (*floatingHashAlgo != dof.hashAlgo)
|
2022-03-30 17:31:01 +03:00
|
|
|
throw Error("all floating outputs must use the same hash type");
|
2020-07-17 22:55:41 +03:00
|
|
|
}
|
2020-07-17 18:33:27 +03:00
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::Deferred &) {
|
2022-03-30 17:31:01 +03:00
|
|
|
deferredIAOutputs.insert(i.first);
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::Impure &) {
|
|
|
|
impureOutputs.insert(i.first);
|
2020-09-23 17:30:42 +03:00
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, i.second.raw);
|
2020-07-17 18:33:27 +03:00
|
|
|
}
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
if (inputAddressedOutputs.empty()
|
|
|
|
&& fixedCAOutputs.empty()
|
|
|
|
&& floatingCAOutputs.empty()
|
|
|
|
&& deferredIAOutputs.empty()
|
|
|
|
&& impureOutputs.empty())
|
|
|
|
throw Error("must have at least one output");
|
|
|
|
|
|
|
|
if (!inputAddressedOutputs.empty()
|
|
|
|
&& fixedCAOutputs.empty()
|
|
|
|
&& floatingCAOutputs.empty()
|
|
|
|
&& deferredIAOutputs.empty()
|
|
|
|
&& impureOutputs.empty())
|
2022-03-18 02:36:52 +02:00
|
|
|
return DerivationType::InputAddressed {
|
|
|
|
.deferred = false,
|
|
|
|
};
|
2022-03-30 17:31:01 +03:00
|
|
|
|
|
|
|
if (inputAddressedOutputs.empty()
|
|
|
|
&& !fixedCAOutputs.empty()
|
|
|
|
&& floatingCAOutputs.empty()
|
|
|
|
&& deferredIAOutputs.empty()
|
|
|
|
&& impureOutputs.empty())
|
|
|
|
{
|
2020-07-17 18:33:27 +03:00
|
|
|
if (fixedCAOutputs.size() > 1)
|
|
|
|
// FIXME: Experimental feature?
|
2022-03-30 17:31:01 +03:00
|
|
|
throw Error("only one fixed output is allowed for now");
|
2020-07-17 18:33:27 +03:00
|
|
|
if (*fixedCAOutputs.begin() != "out")
|
2022-03-30 17:31:01 +03:00
|
|
|
throw Error("single fixed output must be named \"out\"");
|
2022-03-18 02:36:52 +02:00
|
|
|
return DerivationType::ContentAddressed {
|
2022-03-31 17:12:25 +03:00
|
|
|
.sandboxed = false,
|
2022-03-18 02:36:52 +02:00
|
|
|
.fixed = true,
|
|
|
|
};
|
2022-03-30 17:31:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inputAddressedOutputs.empty()
|
|
|
|
&& fixedCAOutputs.empty()
|
|
|
|
&& !floatingCAOutputs.empty()
|
|
|
|
&& deferredIAOutputs.empty()
|
|
|
|
&& impureOutputs.empty())
|
2022-03-18 02:36:52 +02:00
|
|
|
return DerivationType::ContentAddressed {
|
2022-03-31 17:12:25 +03:00
|
|
|
.sandboxed = true,
|
2022-03-18 02:36:52 +02:00
|
|
|
.fixed = false,
|
|
|
|
};
|
2022-03-30 17:31:01 +03:00
|
|
|
|
|
|
|
if (inputAddressedOutputs.empty()
|
|
|
|
&& fixedCAOutputs.empty()
|
|
|
|
&& floatingCAOutputs.empty()
|
|
|
|
&& !deferredIAOutputs.empty()
|
|
|
|
&& impureOutputs.empty())
|
2022-03-18 02:36:52 +02:00
|
|
|
return DerivationType::InputAddressed {
|
|
|
|
.deferred = true,
|
|
|
|
};
|
2022-03-30 17:31:01 +03:00
|
|
|
|
|
|
|
if (inputAddressedOutputs.empty()
|
|
|
|
&& fixedCAOutputs.empty()
|
|
|
|
&& floatingCAOutputs.empty()
|
|
|
|
&& deferredIAOutputs.empty()
|
|
|
|
&& !impureOutputs.empty())
|
|
|
|
return DerivationType::Impure { };
|
|
|
|
|
|
|
|
throw Error("can't mix derivation output types");
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-19 18:50:06 +02:00
|
|
|
Sync<DrvHashes> drvHashes;
|
2011-07-20 21:10:47 +03:00
|
|
|
|
2020-03-19 06:37:57 +02:00
|
|
|
/* pathDerivationModulo and hashDerivationModulo are mutually recursive
|
|
|
|
*/
|
2011-07-20 21:10:47 +03:00
|
|
|
|
2020-03-19 06:37:57 +02:00
|
|
|
/* Look up the derivation by value and memoize the
|
|
|
|
`hashDerivationModulo` call.
|
|
|
|
*/
|
2022-03-16 15:21:09 +02:00
|
|
|
static const DrvHash pathDerivationModulo(Store & store, const StorePath & drvPath)
|
2020-03-19 06:37:57 +02:00
|
|
|
{
|
2020-11-19 18:50:06 +02:00
|
|
|
{
|
|
|
|
auto hashes = drvHashes.lock();
|
|
|
|
auto h = hashes->find(drvPath);
|
|
|
|
if (h != hashes->end()) {
|
|
|
|
return h->second;
|
|
|
|
}
|
2020-03-19 06:37:57 +02:00
|
|
|
}
|
2020-11-19 18:50:06 +02:00
|
|
|
auto h = hashDerivationModulo(
|
|
|
|
store,
|
|
|
|
store.readInvalidDerivation(drvPath),
|
|
|
|
false);
|
|
|
|
// Cache it
|
|
|
|
drvHashes.lock()->insert_or_assign(drvPath, h);
|
|
|
|
return h;
|
2020-03-19 06:37:57 +02:00
|
|
|
}
|
2011-07-20 21:10:47 +03:00
|
|
|
|
2020-03-19 06:37:57 +02:00
|
|
|
/* See the header for interface details. These are the implementation details.
|
|
|
|
|
2020-03-20 05:37:52 +02:00
|
|
|
For fixed-output derivations, each hash in the map is not the
|
2020-03-19 06:37:57 +02:00
|
|
|
corresponding output's content hash, but a hash of that hash along
|
|
|
|
with other constant data. The key point is that the value is a pure
|
|
|
|
function of the output's contents, and there are no preimage attacks
|
2020-03-20 05:37:52 +02:00
|
|
|
either spoofing an output's contents for a derivation, or
|
|
|
|
spoofing a derivation for an output's contents.
|
2020-03-19 06:37:57 +02:00
|
|
|
|
|
|
|
For regular derivations, it looks up each subderivation from its hash
|
|
|
|
and recurs. If the subderivation is also regular, it simply
|
|
|
|
substitutes the derivation path with its hash. If the subderivation
|
|
|
|
is fixed-output, however, it takes each output hash and pretends it
|
|
|
|
is a derivation hash producing a single "out" output. This is so we
|
|
|
|
don't leak the provenance of fixed outputs, reducing pointless cache
|
|
|
|
misses as the build itself won't know this.
|
|
|
|
*/
|
2022-03-16 15:21:09 +02:00
|
|
|
DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOutputs)
|
2011-07-20 21:10:47 +03:00
|
|
|
{
|
2022-03-18 02:36:52 +02:00
|
|
|
auto type = drv.type();
|
|
|
|
|
2011-07-20 21:10:47 +03:00
|
|
|
/* Return a fixed hash for fixed-output derivations. */
|
2022-03-18 02:36:52 +02:00
|
|
|
if (type.isFixed()) {
|
2020-03-19 06:37:57 +02:00
|
|
|
std::map<std::string, Hash> outputHashes;
|
|
|
|
for (const auto & i : drv.outputs) {
|
2023-08-16 19:29:23 +03:00
|
|
|
auto & dof = std::get<DerivationOutput::CAFixed>(i.second.raw);
|
2023-11-28 15:20:27 +02:00
|
|
|
auto hash = hashString(HashAlgorithm::SHA256, "fixed:out:"
|
2023-04-01 23:40:32 +03:00
|
|
|
+ dof.ca.printMethodAlgo() + ":"
|
2023-10-13 04:48:15 +03:00
|
|
|
+ dof.ca.hash.to_string(HashFormat::Base16, false) + ":"
|
2020-08-07 22:09:26 +03:00
|
|
|
+ store.printStorePath(dof.path(store, drv.name, i.first)));
|
2020-07-17 17:28:33 +03:00
|
|
|
outputHashes.insert_or_assign(i.first, std::move(hash));
|
2020-03-19 06:37:57 +02:00
|
|
|
}
|
2022-03-30 17:31:01 +03:00
|
|
|
return DrvHash {
|
2022-03-16 15:21:09 +02:00
|
|
|
.hashes = outputHashes,
|
|
|
|
.kind = DrvHash::Kind::Regular,
|
|
|
|
};
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
2022-03-18 02:36:52 +02:00
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
if (!type.isPure()) {
|
|
|
|
std::map<std::string, Hash> outputHashes;
|
|
|
|
for (const auto & [outputName, _] : drv.outputs)
|
|
|
|
outputHashes.insert_or_assign(outputName, impureOutputHash);
|
|
|
|
return DrvHash {
|
|
|
|
.hashes = outputHashes,
|
|
|
|
.kind = DrvHash::Kind::Deferred,
|
|
|
|
};
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
2022-03-18 02:36:52 +02:00
|
|
|
|
|
|
|
auto kind = std::visit(overloaded {
|
|
|
|
[](const DerivationType::InputAddressed & ia) {
|
|
|
|
/* This might be a "pesimistically" deferred output, so we don't
|
|
|
|
"taint" the kind yet. */
|
|
|
|
return DrvHash::Kind::Regular;
|
|
|
|
},
|
|
|
|
[](const DerivationType::ContentAddressed & ca) {
|
|
|
|
return ca.fixed
|
|
|
|
? DrvHash::Kind::Regular
|
|
|
|
: DrvHash::Kind::Deferred;
|
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[](const DerivationType::Impure &) -> DrvHash::Kind {
|
|
|
|
assert(false);
|
|
|
|
}
|
2023-08-16 19:29:23 +03:00
|
|
|
}, drv.type().raw);
|
2011-07-20 21:10:47 +03:00
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
DerivedPathMap<StringSet>::ChildNode::Map inputs2;
|
|
|
|
for (auto & [drvPath, node] : drv.inputDrvs.map) {
|
2021-10-01 21:05:53 +03:00
|
|
|
const auto & res = pathDerivationModulo(store, drvPath);
|
2022-03-16 15:21:09 +02:00
|
|
|
if (res.kind == DrvHash::Kind::Deferred)
|
|
|
|
kind = DrvHash::Kind::Deferred;
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & outputName : node.value) {
|
2022-05-04 08:44:32 +03:00
|
|
|
const auto h = get(res.hashes, outputName);
|
|
|
|
if (!h)
|
|
|
|
throw Error("no hash for output '%s' of derivation '%s'", outputName, drv.name);
|
2023-10-13 04:48:15 +03:00
|
|
|
inputs2[h->to_string(HashFormat::Base16, false)].value.insert(outputName);
|
2022-03-16 15:21:09 +02:00
|
|
|
}
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
2023-11-28 15:20:27 +02:00
|
|
|
auto hash = hashString(HashAlgorithm::SHA256, drv.unparse(store, maskOutputs, &inputs2));
|
2020-12-09 17:56:56 +02:00
|
|
|
|
2022-03-16 15:21:09 +02:00
|
|
|
std::map<std::string, Hash> outputHashes;
|
|
|
|
for (const auto & [outputName, _] : drv.outputs) {
|
|
|
|
outputHashes.insert_or_assign(outputName, hash);
|
2021-10-01 21:05:53 +03:00
|
|
|
}
|
2022-03-16 15:21:09 +02:00
|
|
|
|
|
|
|
return DrvHash {
|
|
|
|
.hashes = outputHashes,
|
|
|
|
.kind = kind,
|
|
|
|
};
|
2020-12-09 17:56:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-16 17:04:47 +03:00
|
|
|
std::map<std::string, Hash> staticOutputHashes(Store & store, const Derivation & drv)
|
2020-12-09 17:56:56 +02:00
|
|
|
{
|
2022-03-16 15:21:09 +02:00
|
|
|
return hashDerivationModulo(store, drv, true).hashes;
|
2011-07-20 21:10:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
static DerivationOutput readDerivationOutput(Source & in, const StoreDirConfig & store)
|
2020-03-23 05:43:07 +02:00
|
|
|
{
|
2020-08-10 04:57:54 +03:00
|
|
|
const auto pathS = readString(in);
|
2020-08-09 23:51:34 +03:00
|
|
|
const auto hashAlgo = readString(in);
|
|
|
|
const auto hash = readString(in);
|
2020-03-23 05:43:07 +02:00
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
return parseDerivationOutput(store, pathS, hashAlgo, hash, experimentalFeatureSettings);
|
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;
|
|
|
|
}
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
DerivationOutputsAndOptPaths BasicDerivation::outputsAndOptPaths(const StoreDirConfig & store) const
|
2022-03-30 17:31:01 +03:00
|
|
|
{
|
2020-07-27 23:42:02 +03:00
|
|
|
DerivationOutputsAndOptPaths outsAndOptPaths;
|
2023-08-16 19:29:23 +03:00
|
|
|
for (auto & [outputName, output] : outputs)
|
2020-07-27 23:42:02 +03:00
|
|
|
outsAndOptPaths.insert(std::make_pair(
|
2023-08-16 19:29:23 +03:00
|
|
|
outputName,
|
|
|
|
std::make_pair(output, output.path(store, name, outputName))
|
2020-07-27 23:42:02 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return outsAndOptPaths;
|
|
|
|
}
|
2020-06-12 13:46:33 +03:00
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
std::string_view BasicDerivation::nameFromPath(const StorePath & drvPath)
|
|
|
|
{
|
2020-07-12 18:26:30 +03:00
|
|
|
auto nameWithSuffix = drvPath.name();
|
|
|
|
constexpr std::string_view extension = ".drv";
|
|
|
|
assert(hasSuffix(nameWithSuffix, extension));
|
|
|
|
nameWithSuffix.remove_suffix(extension.size());
|
|
|
|
return nameWithSuffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
Source & readDerivation(Source & in, const StoreDirConfig & 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
|
|
|
}
|
|
|
|
|
2022-03-25 06:39:57 +02:00
|
|
|
drv.inputSrcs = CommonProto::Serialise<StorePathSet>::read(store,
|
|
|
|
CommonProto::ReadConn { .from = 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
void writeDerivation(Sink & out, const StoreDirConfig & 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-08-07 22:09:26 +03:00
|
|
|
out << i.first;
|
2020-07-12 19:12:21 +03:00
|
|
|
std::visit(overloaded {
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::InputAddressed & doi) {
|
2020-08-07 22:09:26 +03:00
|
|
|
out << store.printStorePath(doi.path)
|
|
|
|
<< ""
|
|
|
|
<< "";
|
2020-07-12 19:12:21 +03:00
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFixed & dof) {
|
2020-08-07 22:09:26 +03:00
|
|
|
out << store.printStorePath(dof.path(store, drv.name, i.first))
|
2023-04-01 23:40:32 +03:00
|
|
|
<< dof.ca.printMethodAlgo()
|
2023-10-13 04:48:15 +03:00
|
|
|
<< dof.ca.hash.to_string(HashFormat::Base16, false);
|
2020-07-12 19:12:21 +03:00
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::CAFloating & dof) {
|
2020-08-07 22:09:26 +03:00
|
|
|
out << ""
|
2023-11-28 15:20:27 +02:00
|
|
|
<< (dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo))
|
2020-07-12 19:12:21 +03:00
|
|
|
<< "";
|
|
|
|
},
|
2022-03-18 00:29:15 +02:00
|
|
|
[&](const DerivationOutput::Deferred &) {
|
2020-09-23 17:30:42 +03:00
|
|
|
out << ""
|
|
|
|
<< ""
|
|
|
|
<< "";
|
|
|
|
},
|
2022-03-30 17:31:01 +03:00
|
|
|
[&](const DerivationOutput::Impure & doi) {
|
|
|
|
out << ""
|
2023-11-28 15:20:27 +02:00
|
|
|
<< (doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo))
|
2022-03-30 17:31:01 +03:00
|
|
|
<< "impure";
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, i.second.raw);
|
2020-06-25 16:50:30 +03:00
|
|
|
}
|
2022-03-25 06:39:57 +02:00
|
|
|
CommonProto::write(store,
|
|
|
|
CommonProto::WriteConn { .to = out },
|
2023-04-17 20:40:46 +03:00
|
|
|
drv.inputSrcs);
|
2019-12-05 20:11:09 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-25 16:53:12 +03:00
|
|
|
std::string hashPlaceholder(const OutputNameView outputName)
|
2016-08-17 16:12:54 +03:00
|
|
|
{
|
|
|
|
// FIXME: memoize?
|
2023-11-28 16:38:15 +02:00
|
|
|
return "/" + hashString(HashAlgorithm::SHA256, concatStrings("nix-output:", outputName)).to_string(HashFormat::Nix32, false);
|
2016-08-17 16:12:54 +03:00
|
|
|
}
|
|
|
|
|
2023-05-12 01:01:41 +03:00
|
|
|
|
2016-08-17 16:12:54 +03:00
|
|
|
|
2020-08-22 23:44:47 +03:00
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
static void rewriteDerivation(Store & store, BasicDerivation & drv, const StringMap & rewrites)
|
|
|
|
{
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
debug("Rewriting the derivation");
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
for (auto & rewrite : rewrites) {
|
2020-08-22 23:44:47 +03:00
|
|
|
debug("rewriting %s as %s", rewrite.first, rewrite.second);
|
|
|
|
}
|
|
|
|
|
|
|
|
drv.builder = rewriteStrings(drv.builder, rewrites);
|
2022-03-30 17:31:01 +03:00
|
|
|
for (auto & arg : drv.args) {
|
2020-08-22 23:44:47 +03:00
|
|
|
arg = rewriteStrings(arg, rewrites);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringPairs newEnv;
|
2022-03-30 17:31:01 +03:00
|
|
|
for (auto & envVar : drv.env) {
|
2020-08-22 23:44:47 +03:00
|
|
|
auto envName = rewriteStrings(envVar.first, rewrites);
|
|
|
|
auto envValue = rewriteStrings(envVar.second, rewrites);
|
|
|
|
newEnv.emplace(envName, envValue);
|
|
|
|
}
|
|
|
|
drv.env = newEnv;
|
|
|
|
|
2020-09-23 17:30:42 +03:00
|
|
|
auto hashModulo = hashDerivationModulo(store, Derivation(drv), true);
|
|
|
|
for (auto & [outputName, output] : drv.outputs) {
|
2023-08-16 19:29:23 +03:00
|
|
|
if (std::holds_alternative<DerivationOutput::Deferred>(output.raw)) {
|
2022-05-04 08:44:32 +03:00
|
|
|
auto h = get(hashModulo.hashes, outputName);
|
|
|
|
if (!h)
|
|
|
|
throw Error("derivation '%s' output '%s' has no hash (derivations.cc/rewriteDerivation)",
|
|
|
|
drv.name, outputName);
|
|
|
|
auto outPath = store.makeOutputPath(outputName, *h, drv.name);
|
2020-09-23 17:30:42 +03:00
|
|
|
drv.env[outputName] = store.printStorePath(outPath);
|
2022-03-18 00:29:15 +02:00
|
|
|
output = DerivationOutput::InputAddressed {
|
|
|
|
.path = std::move(outPath),
|
2020-09-23 17:30:42 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2020-08-22 23:44:47 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-08 07:44:55 +02:00
|
|
|
std::optional<BasicDerivation> Derivation::tryResolve(Store & store, Store * evalStore) const
|
2021-10-01 21:05:53 +03:00
|
|
|
{
|
2022-03-30 17:31:01 +03:00
|
|
|
std::map<std::pair<StorePath, std::string>, StorePath> inputDrvOutputs;
|
2021-10-01 21:05:53 +03:00
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
std::function<void(const StorePath &, const DerivedPathMap<StringSet>::ChildNode &)> accum;
|
|
|
|
accum = [&](auto & inputDrv, auto & node) {
|
2023-12-08 07:44:55 +02:00
|
|
|
for (auto & [outputName, outputPath] : store.queryPartialDerivationOutputMap(inputDrv, evalStore)) {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
if (outputPath) {
|
|
|
|
inputDrvOutputs.insert_or_assign({inputDrv, outputName}, *outputPath);
|
|
|
|
if (auto p = get(node.childMap, outputName))
|
|
|
|
accum(*outputPath, *p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto & [inputDrv, node] : inputDrvs.map)
|
|
|
|
accum(inputDrv, node);
|
2021-10-01 21:05:53 +03:00
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
return tryResolve(store, inputDrvOutputs);
|
2021-10-01 21:05:53 +03:00
|
|
|
}
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
static bool tryResolveInput(
|
|
|
|
Store & store, StorePathSet & inputSrcs, StringMap & inputRewrites,
|
|
|
|
const DownstreamPlaceholder * placeholderOpt,
|
|
|
|
const StorePath & inputDrv, const DerivedPathMap<StringSet>::ChildNode & inputNode,
|
|
|
|
const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs)
|
|
|
|
{
|
|
|
|
auto getOutput = [&](const std::string & outputName) {
|
|
|
|
auto * actualPathOpt = get(inputDrvOutputs, { inputDrv, outputName });
|
|
|
|
if (!actualPathOpt)
|
|
|
|
warn("output %s of input %s missing, aborting the resolving",
|
|
|
|
outputName,
|
|
|
|
store.printStorePath(inputDrv)
|
|
|
|
);
|
|
|
|
return actualPathOpt;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto getPlaceholder = [&](const std::string & outputName) {
|
|
|
|
return placeholderOpt
|
|
|
|
? DownstreamPlaceholder::unknownDerivation(*placeholderOpt, outputName)
|
|
|
|
: DownstreamPlaceholder::unknownCaOutput(inputDrv, outputName);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto & outputName : inputNode.value) {
|
|
|
|
auto actualPathOpt = getOutput(outputName);
|
|
|
|
if (!actualPathOpt) return false;
|
|
|
|
auto actualPath = *actualPathOpt;
|
|
|
|
if (experimentalFeatureSettings.isEnabled(Xp::CaDerivations)) {
|
|
|
|
inputRewrites.emplace(
|
|
|
|
getPlaceholder(outputName).render(),
|
|
|
|
store.printStorePath(actualPath));
|
|
|
|
}
|
|
|
|
inputSrcs.insert(std::move(actualPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto & [outputName, childNode] : inputNode.childMap) {
|
|
|
|
auto actualPathOpt = getOutput(outputName);
|
|
|
|
if (!actualPathOpt) return false;
|
|
|
|
auto actualPath = *actualPathOpt;
|
|
|
|
auto nextPlaceholder = getPlaceholder(outputName);
|
|
|
|
if (!tryResolveInput(store, inputSrcs, inputRewrites,
|
|
|
|
&nextPlaceholder, actualPath, childNode,
|
|
|
|
inputDrvOutputs))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-30 17:31:01 +03:00
|
|
|
std::optional<BasicDerivation> Derivation::tryResolve(
|
|
|
|
Store & store,
|
|
|
|
const std::map<std::pair<StorePath, std::string>, StorePath> & inputDrvOutputs) const
|
|
|
|
{
|
2020-08-22 23:44:47 +03:00
|
|
|
BasicDerivation resolved { *this };
|
|
|
|
|
|
|
|
// Input paths that we'll want to rewrite in the derivation
|
|
|
|
StringMap inputRewrites;
|
|
|
|
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & [inputDrv, inputNode] : inputDrvs.map)
|
|
|
|
if (!tryResolveInput(store, resolved.inputSrcs, inputRewrites,
|
|
|
|
nullptr, inputDrv, inputNode, inputDrvOutputs))
|
|
|
|
return std::nullopt;
|
2020-08-22 23:44:47 +03:00
|
|
|
|
|
|
|
rewriteDerivation(store, resolved, inputRewrites);
|
|
|
|
|
|
|
|
return resolved;
|
|
|
|
}
|
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
|
2023-03-01 23:57:36 +02:00
|
|
|
void Derivation::checkInvariants(Store & store, const StorePath & drvPath) const
|
|
|
|
{
|
|
|
|
assert(drvPath.isDerivation());
|
|
|
|
std::string drvName(drvPath.name());
|
|
|
|
drvName = drvName.substr(0, drvName.size() - drvExtension.size());
|
|
|
|
|
|
|
|
if (drvName != name) {
|
|
|
|
throw Error("Derivation '%s' has name '%s' which does not match its path", store.printStorePath(drvPath), name);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto envHasRightPath = [&](const StorePath & actual, const std::string & varName)
|
|
|
|
{
|
|
|
|
auto j = env.find(varName);
|
|
|
|
if (j == env.end() || store.parseStorePath(j->second) != actual)
|
|
|
|
throw Error("derivation '%s' has incorrect environment variable '%s', should be '%s'",
|
|
|
|
store.printStorePath(drvPath), varName, store.printStorePath(actual));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Don't need the answer, but do this anyways to assert is proper
|
|
|
|
// combination. The code below is more general and naturally allows
|
|
|
|
// combinations that are currently prohibited.
|
|
|
|
type();
|
|
|
|
|
|
|
|
std::optional<DrvHash> hashesModulo;
|
|
|
|
for (auto & i : outputs) {
|
|
|
|
std::visit(overloaded {
|
|
|
|
[&](const DerivationOutput::InputAddressed & doia) {
|
|
|
|
if (!hashesModulo) {
|
|
|
|
// somewhat expensive so we do lazily
|
|
|
|
hashesModulo = hashDerivationModulo(store, *this, true);
|
|
|
|
}
|
|
|
|
auto currentOutputHash = get(hashesModulo->hashes, i.first);
|
|
|
|
if (!currentOutputHash)
|
|
|
|
throw Error("derivation '%s' has unexpected output '%s' (local-store / hashesModulo) named '%s'",
|
|
|
|
store.printStorePath(drvPath), store.printStorePath(doia.path), i.first);
|
|
|
|
StorePath recomputed = store.makeOutputPath(i.first, *currentOutputHash, drvName);
|
|
|
|
if (doia.path != recomputed)
|
|
|
|
throw Error("derivation '%s' has incorrect output '%s', should be '%s'",
|
|
|
|
store.printStorePath(drvPath), store.printStorePath(doia.path), store.printStorePath(recomputed));
|
|
|
|
envHasRightPath(doia.path, i.first);
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::CAFixed & dof) {
|
2023-04-17 17:16:57 +03:00
|
|
|
auto path = dof.path(store, drvName, i.first);
|
2023-03-01 23:57:36 +02:00
|
|
|
envHasRightPath(path, i.first);
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::CAFloating &) {
|
|
|
|
/* Nothing to check */
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::Deferred &) {
|
|
|
|
/* Nothing to check */
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::Impure &) {
|
|
|
|
/* Nothing to check */
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, i.second.raw);
|
2023-03-01 23:57:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-28 15:20:27 +02:00
|
|
|
const Hash impureOutputHash = hashString(HashAlgorithm::SHA256, "impure");
|
2022-03-30 17:31:01 +03:00
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
nlohmann::json DerivationOutput::toJSON(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName) const
|
2023-02-18 01:37:35 +02:00
|
|
|
{
|
|
|
|
nlohmann::json res = nlohmann::json::object();
|
|
|
|
std::visit(overloaded {
|
|
|
|
[&](const DerivationOutput::InputAddressed & doi) {
|
|
|
|
res["path"] = store.printStorePath(doi.path);
|
|
|
|
},
|
|
|
|
[&](const DerivationOutput::CAFixed & dof) {
|
|
|
|
res["path"] = store.printStorePath(dof.path(store, drvName, outputName));
|
2023-04-01 23:40:32 +03:00
|
|
|
res["hashAlgo"] = dof.ca.printMethodAlgo();
|
2023-10-13 04:48:15 +03:00
|
|
|
res["hash"] = dof.ca.hash.to_string(HashFormat::Base16, false);
|
2023-02-28 19:46:00 +02:00
|
|
|
// FIXME print refs?
|
2023-02-18 01:37:35 +02:00
|
|
|
},
|
|
|
|
[&](const DerivationOutput::CAFloating & dof) {
|
2023-11-28 15:20:27 +02:00
|
|
|
res["hashAlgo"] = dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo);
|
2023-02-18 01:37:35 +02:00
|
|
|
},
|
|
|
|
[&](const DerivationOutput::Deferred &) {},
|
|
|
|
[&](const DerivationOutput::Impure & doi) {
|
2023-11-28 15:20:27 +02:00
|
|
|
res["hashAlgo"] = doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo);
|
2023-02-18 01:37:35 +02:00
|
|
|
res["impure"] = true;
|
|
|
|
},
|
2023-08-16 19:29:23 +03:00
|
|
|
}, raw);
|
2023-02-18 01:37:35 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
|
|
|
|
DerivationOutput DerivationOutput::fromJSON(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName,
|
2023-04-17 18:22:31 +03:00
|
|
|
const nlohmann::json & _json,
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2023-02-18 01:37:35 +02:00
|
|
|
{
|
|
|
|
std::set<std::string_view> keys;
|
2023-07-28 23:23:56 +03:00
|
|
|
ensureType(_json, nlohmann::detail::value_t::object);
|
2023-02-18 01:37:35 +02:00
|
|
|
auto json = (std::map<std::string, nlohmann::json>) _json;
|
|
|
|
|
|
|
|
for (const auto & [key, _] : json)
|
|
|
|
keys.insert(key);
|
|
|
|
|
2023-11-28 15:20:27 +02:00
|
|
|
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashAlgorithm> {
|
|
|
|
std::string hashAlgoStr = json["hashAlgo"];
|
2023-04-17 17:28:54 +03:00
|
|
|
// remaining to parse, will be mutated by parsers
|
2023-11-28 15:20:27 +02:00
|
|
|
std::string_view s = hashAlgoStr;
|
2023-04-17 17:28:54 +03:00
|
|
|
ContentAddressMethod method = ContentAddressMethod::parsePrefix(s);
|
2023-04-19 18:33:48 +03:00
|
|
|
if (method == TextIngestionMethod {})
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
2023-11-28 15:20:27 +02:00
|
|
|
auto hashAlgo = parseHashAlgo(s);
|
|
|
|
return { std::move(method), std::move(hashAlgo) };
|
2023-02-18 01:37:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (keys == (std::set<std::string_view> { "path" })) {
|
|
|
|
return DerivationOutput::InputAddressed {
|
|
|
|
.path = store.parseStorePath((std::string) json["path"]),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (keys == (std::set<std::string_view> { "path", "hashAlgo", "hash" })) {
|
2023-11-28 15:20:27 +02:00
|
|
|
auto [method, hashAlgo] = methodAlgo();
|
2023-02-18 01:37:35 +02:00
|
|
|
auto dof = DerivationOutput::CAFixed {
|
2023-07-06 01:53:44 +03:00
|
|
|
.ca = ContentAddress {
|
|
|
|
.method = std::move(method),
|
2023-11-28 15:20:27 +02:00
|
|
|
.hash = Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashAlgo),
|
2023-07-06 01:53:44 +03:00
|
|
|
},
|
2023-02-18 01:37:35 +02:00
|
|
|
};
|
|
|
|
if (dof.path(store, drvName, outputName) != store.parseStorePath((std::string) json["path"]))
|
|
|
|
throw Error("Path doesn't match derivation output");
|
|
|
|
return dof;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (keys == (std::set<std::string_view> { "hashAlgo" })) {
|
2023-04-17 18:22:31 +03:00
|
|
|
xpSettings.require(Xp::CaDerivations);
|
2023-11-28 15:20:27 +02:00
|
|
|
auto [method, hashAlgo] = methodAlgo();
|
2023-02-18 01:37:35 +02:00
|
|
|
return DerivationOutput::CAFloating {
|
2023-04-17 17:28:54 +03:00
|
|
|
.method = std::move(method),
|
2023-11-28 15:20:27 +02:00
|
|
|
.hashAlgo = std::move(hashAlgo),
|
2023-02-18 01:37:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (keys == (std::set<std::string_view> { })) {
|
|
|
|
return DerivationOutput::Deferred {};
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (keys == (std::set<std::string_view> { "hashAlgo", "impure" })) {
|
2023-04-17 18:22:31 +03:00
|
|
|
xpSettings.require(Xp::ImpureDerivations);
|
2023-11-28 15:20:27 +02:00
|
|
|
auto [method, hashAlgo] = methodAlgo();
|
2023-02-18 01:37:35 +02:00
|
|
|
return DerivationOutput::Impure {
|
2023-04-17 17:28:54 +03:00
|
|
|
.method = std::move(method),
|
2023-11-28 15:20:27 +02:00
|
|
|
.hashAlgo = hashAlgo,
|
2023-02-18 01:37:35 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
throw Error("invalid JSON for derivation output");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-18 17:35:45 +02:00
|
|
|
nlohmann::json Derivation::toJSON(const StoreDirConfig & store) const
|
2023-02-18 01:37:35 +02:00
|
|
|
{
|
|
|
|
nlohmann::json res = nlohmann::json::object();
|
|
|
|
|
2023-03-30 18:06:52 +03:00
|
|
|
res["name"] = name;
|
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
{
|
|
|
|
nlohmann::json & outputsObj = res["outputs"];
|
|
|
|
outputsObj = nlohmann::json::object();
|
|
|
|
for (auto & [outputName, output] : outputs) {
|
|
|
|
outputsObj[outputName] = output.toJSON(store, name, outputName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto& inputsList = res["inputSrcs"];
|
|
|
|
inputsList = nlohmann::json ::array();
|
|
|
|
for (auto & input : inputSrcs)
|
|
|
|
inputsList.emplace_back(store.printStorePath(input));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
std::function<nlohmann::json(const DerivedPathMap<StringSet>::ChildNode &)> doInput;
|
|
|
|
doInput = [&](const auto & inputNode) {
|
|
|
|
auto value = nlohmann::json::object();
|
|
|
|
value["outputs"] = inputNode.value;
|
|
|
|
{
|
|
|
|
auto next = nlohmann::json::object();
|
|
|
|
for (auto & [outputId, childNode] : inputNode.childMap)
|
|
|
|
next[outputId] = doInput(childNode);
|
|
|
|
value["dynamicOutputs"] = std::move(next);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
};
|
|
|
|
{
|
|
|
|
auto& inputDrvsObj = res["inputDrvs"];
|
|
|
|
inputDrvsObj = nlohmann::json::object();
|
|
|
|
for (auto & [inputDrv, inputNode] : inputDrvs.map) {
|
|
|
|
inputDrvsObj[store.printStorePath(inputDrv)] = doInput(inputNode);
|
|
|
|
}
|
|
|
|
}
|
2023-02-18 01:37:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
res["system"] = platform;
|
|
|
|
res["builder"] = builder;
|
|
|
|
res["args"] = args;
|
2023-02-21 00:32:19 +02:00
|
|
|
res["env"] = env;
|
2023-02-18 01:37:35 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
|
|
|
|
Derivation Derivation::fromJSON(
|
2022-03-18 17:35:45 +02:00
|
|
|
const StoreDirConfig & store,
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
const nlohmann::json & json,
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2023-02-18 01:37:35 +02:00
|
|
|
{
|
2023-07-28 23:23:56 +03:00
|
|
|
using nlohmann::detail::value_t;
|
|
|
|
|
2023-02-18 01:37:35 +02:00
|
|
|
Derivation res;
|
|
|
|
|
2023-07-28 23:23:56 +03:00
|
|
|
ensureType(json, value_t::object);
|
2023-03-30 18:06:52 +03:00
|
|
|
|
2023-07-28 23:23:56 +03:00
|
|
|
res.name = ensureType(valueAt(json, "name"), value_t::string);
|
|
|
|
|
|
|
|
try {
|
|
|
|
auto & outputsObj = ensureType(valueAt(json, "outputs"), value_t::object);
|
2023-02-18 01:37:35 +02:00
|
|
|
for (auto & [outputName, output] : outputsObj.items()) {
|
|
|
|
res.outputs.insert_or_assign(
|
|
|
|
outputName,
|
2023-03-30 18:06:52 +03:00
|
|
|
DerivationOutput::fromJSON(store, res.name, outputName, output));
|
2023-02-18 01:37:35 +02:00
|
|
|
}
|
2023-07-28 23:23:56 +03:00
|
|
|
} catch (Error & e) {
|
|
|
|
e.addTrace({}, "while reading key 'outputs'");
|
|
|
|
throw;
|
2023-02-18 01:37:35 +02:00
|
|
|
}
|
|
|
|
|
2023-07-28 23:23:56 +03:00
|
|
|
try {
|
|
|
|
auto & inputsList = ensureType(valueAt(json, "inputSrcs"), value_t::array);
|
2023-02-18 01:37:35 +02:00
|
|
|
for (auto & input : inputsList)
|
|
|
|
res.inputSrcs.insert(store.parseStorePath(static_cast<const std::string &>(input)));
|
2023-07-28 23:23:56 +03:00
|
|
|
} catch (Error & e) {
|
|
|
|
e.addTrace({}, "while reading key 'inputSrcs'");
|
|
|
|
throw;
|
2023-02-18 01:37:35 +02:00
|
|
|
}
|
|
|
|
|
2023-07-28 23:23:56 +03:00
|
|
|
try {
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
std::function<DerivedPathMap<StringSet>::ChildNode(const nlohmann::json &)> doInput;
|
|
|
|
doInput = [&](const auto & json) {
|
|
|
|
DerivedPathMap<StringSet>::ChildNode node;
|
|
|
|
node.value = static_cast<const StringSet &>(
|
|
|
|
ensureType(valueAt(json, "outputs"), value_t::array));
|
|
|
|
for (auto & [outputId, childNode] : ensureType(valueAt(json, "dynamicOutputs"), value_t::object).items()) {
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
|
|
|
node.childMap[outputId] = doInput(childNode);
|
|
|
|
}
|
|
|
|
return node;
|
|
|
|
};
|
2023-07-28 23:23:56 +03:00
|
|
|
auto & inputDrvsObj = ensureType(valueAt(json, "inputDrvs"), value_t::object);
|
Allow dynamic derivation deps in `inputDrvs`
We use the same nested map representation we used for goals, again in
order to save space. We might someday want to combine with `inputDrvs`,
by doing `V = bool` instead of `V = std::set<OutputName>`, but we are
not doing that yet for sake of a smaller diff.
The ATerm format for Derivations also needs to be extended, in addition
to the in-memory format. To accomodate this, we added a new basic
versioning scheme, so old versions of Nix will get nice errors. (And
going forward, if the ATerm format changes again the errors will be even
better.)
`parsedStrings`, an internal function used as part of parsing
derivations in A-Term format, used to consume the final `]` but expect
the initial `[` to already be consumed. This made for what looked like
unbalanced brackets at callsites, which was confusing. Now it consumes
both which is hopefully less confusing.
As part of testing, we also created a unit test for the A-Term format for
regular non-experimental derivations too.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Apply suggestions from code review
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
2021-10-02 01:05:53 +03:00
|
|
|
for (auto & [inputDrvPath, inputOutputs] : inputDrvsObj.items())
|
|
|
|
res.inputDrvs.map[store.parseStorePath(inputDrvPath)] =
|
|
|
|
doInput(inputOutputs);
|
2023-07-28 23:23:56 +03:00
|
|
|
} catch (Error & e) {
|
|
|
|
e.addTrace({}, "while reading key 'inputDrvs'");
|
|
|
|
throw;
|
2023-02-18 01:37:35 +02:00
|
|
|
}
|
|
|
|
|
2023-07-28 23:23:56 +03:00
|
|
|
res.platform = ensureType(valueAt(json, "system"), value_t::string);
|
|
|
|
res.builder = ensureType(valueAt(json, "builder"), value_t::string);
|
|
|
|
res.args = ensureType(valueAt(json, "args"), value_t::array);
|
|
|
|
res.env = ensureType(valueAt(json, "env"), value_t::object);
|
2023-02-18 01:37:35 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
}
|