2021-04-05 17:33:28 +03:00
|
|
|
|
#include "derived-path.hh"
|
2021-03-01 07:48:01 +02:00
|
|
|
|
#include "store-api.hh"
|
|
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
2022-05-04 08:44:32 +03:00
|
|
|
|
#include <optional>
|
|
|
|
|
|
2021-03-01 07:48:01 +02:00
|
|
|
|
namespace nix {
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
#define CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, COMPARATOR) \
|
|
|
|
|
bool MY_TYPE ::operator COMPARATOR (const MY_TYPE & other) const \
|
|
|
|
|
{ \
|
|
|
|
|
const MY_TYPE* me = this; \
|
|
|
|
|
auto fields1 = std::make_tuple<const CHILD_TYPE &, const FIELD_TYPE &>(*me->drvPath, me->FIELD); \
|
|
|
|
|
me = &other; \
|
|
|
|
|
auto fields2 = std::make_tuple<const CHILD_TYPE &, const FIELD_TYPE &>(*me->drvPath, me->FIELD); \
|
|
|
|
|
return fields1 COMPARATOR fields2; \
|
|
|
|
|
}
|
|
|
|
|
#define CMP(CHILD_TYPE, MY_TYPE, FIELD) \
|
|
|
|
|
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, ==) \
|
|
|
|
|
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, !=) \
|
|
|
|
|
CMP_ONE(CHILD_TYPE, MY_TYPE, FIELD, <)
|
|
|
|
|
|
|
|
|
|
#define FIELD_TYPE std::string
|
|
|
|
|
CMP(SingleDerivedPath, SingleDerivedPathBuilt, output)
|
|
|
|
|
#undef FIELD_TYPE
|
|
|
|
|
|
|
|
|
|
#define FIELD_TYPE OutputsSpec
|
|
|
|
|
CMP(SingleDerivedPath, DerivedPathBuilt, outputs)
|
|
|
|
|
#undef FIELD_TYPE
|
|
|
|
|
|
|
|
|
|
#undef CMP
|
|
|
|
|
#undef CMP_ONE
|
|
|
|
|
|
|
|
|
|
nlohmann::json DerivedPath::Opaque::toJSON(const Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return store.printStorePath(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlohmann::json SingleDerivedPath::Built::toJSON(Store & store) const {
|
2021-03-01 07:48:01 +02:00
|
|
|
|
nlohmann::json res;
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
res["drvPath"] = drvPath->toJSON(store);
|
|
|
|
|
// Fallback for the input-addressed derivation case: We expect to always be
|
|
|
|
|
// able to print the output paths, so let’s do it
|
|
|
|
|
// FIXME try-resolve on drvPath
|
|
|
|
|
const auto outputMap = store.queryPartialDerivationOutputMap(resolveDerivedPath(store, *drvPath));
|
|
|
|
|
res["output"] = output;
|
|
|
|
|
auto outputPathIter = outputMap.find(output);
|
|
|
|
|
if (outputPathIter == outputMap.end())
|
|
|
|
|
res["outputPath"] = nullptr;
|
|
|
|
|
else if (std::optional p = outputPathIter->second)
|
|
|
|
|
res["outputPath"] = store.printStorePath(*p);
|
|
|
|
|
else
|
|
|
|
|
res["outputPath"] = nullptr;
|
2021-03-01 07:48:01 +02:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
nlohmann::json DerivedPath::Built::toJSON(Store & store) const {
|
2022-03-17 12:34:31 +02:00
|
|
|
|
nlohmann::json res;
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
res["drvPath"] = drvPath->toJSON(store);
|
2022-03-17 12:34:31 +02:00
|
|
|
|
// Fallback for the input-addressed derivation case: We expect to always be
|
|
|
|
|
// able to print the output paths, so let’s do it
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
// FIXME try-resolve on drvPath
|
|
|
|
|
const auto outputMap = store.queryPartialDerivationOutputMap(resolveDerivedPath(store, *drvPath));
|
2023-01-12 01:57:18 +02:00
|
|
|
|
for (const auto & [output, outputPathOpt] : outputMap) {
|
|
|
|
|
if (!outputs.contains(output)) continue;
|
|
|
|
|
if (outputPathOpt)
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
res["outputs"][output] = store.printStorePath(*outputPathOpt);
|
2022-12-15 17:00:46 +02:00
|
|
|
|
else
|
|
|
|
|
res["outputs"][output] = nullptr;
|
2022-03-17 12:34:31 +02:00
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
nlohmann::json SingleDerivedPath::toJSON(Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return std::visit([&](const auto & buildable) {
|
|
|
|
|
return buildable.toJSON(store);
|
|
|
|
|
}, raw());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nlohmann::json DerivedPath::toJSON(Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return std::visit([&](const auto & buildable) {
|
|
|
|
|
return buildable.toJSON(store);
|
|
|
|
|
}, raw());
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 11:49:01 +02:00
|
|
|
|
std::string DerivedPath::Opaque::to_string(const Store & store) const
|
|
|
|
|
{
|
2021-03-02 05:50:41 +02:00
|
|
|
|
return store.printStorePath(path);
|
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
std::string SingleDerivedPath::Built::to_string(const Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return drvPath->to_string(store) + "^" + output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SingleDerivedPath::Built::to_string_legacy(const Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return drvPath->to_string(store) + "!" + output;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 03:45:11 +03:00
|
|
|
|
std::string DerivedPath::Built::to_string(const Store & store) const
|
2022-11-21 11:49:01 +02:00
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
return drvPath->to_string(store)
|
2023-04-15 03:45:11 +03:00
|
|
|
|
+ '^'
|
2023-01-12 01:57:18 +02:00
|
|
|
|
+ outputs.to_string();
|
2021-03-02 05:50:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 03:45:11 +03:00
|
|
|
|
std::string DerivedPath::Built::to_string_legacy(const Store & store) const
|
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
return drvPath->to_string_legacy(store)
|
|
|
|
|
+ "!"
|
2023-04-15 03:45:11 +03:00
|
|
|
|
+ outputs.to_string();
|
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
std::string SingleDerivedPath::to_string(const Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return std::visit(
|
|
|
|
|
[&](const auto & req) { return req.to_string(store); },
|
|
|
|
|
raw());
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 03:45:11 +03:00
|
|
|
|
std::string DerivedPath::to_string(const Store & store) const
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
{
|
|
|
|
|
return std::visit(
|
|
|
|
|
[&](const auto & req) { return req.to_string(store); },
|
|
|
|
|
raw());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SingleDerivedPath::to_string_legacy(const Store & store) const
|
2021-03-02 05:50:41 +02:00
|
|
|
|
{
|
2023-04-13 17:22:45 +03:00
|
|
|
|
return std::visit(overloaded {
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
[&](const SingleDerivedPath::Built & req) { return req.to_string_legacy(store); },
|
|
|
|
|
[&](const SingleDerivedPath::Opaque & req) { return req.to_string(store); },
|
2023-04-15 03:45:11 +03:00
|
|
|
|
}, this->raw());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string DerivedPath::to_string_legacy(const Store & store) const
|
|
|
|
|
{
|
|
|
|
|
return std::visit(overloaded {
|
|
|
|
|
[&](const DerivedPath::Built & req) { return req.to_string_legacy(store); },
|
2023-04-13 17:22:45 +03:00
|
|
|
|
[&](const DerivedPath::Opaque & req) { return req.to_string(store); },
|
|
|
|
|
}, this->raw());
|
2021-03-02 05:50:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-05 16:48:18 +03:00
|
|
|
|
DerivedPath::Opaque DerivedPath::Opaque::parse(const Store & store, std::string_view s)
|
2021-03-02 05:50:41 +02:00
|
|
|
|
{
|
|
|
|
|
return {store.parseStorePath(s)};
|
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
void drvRequireExperiment(
|
|
|
|
|
const SingleDerivedPath & drv,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
std::visit(overloaded {
|
|
|
|
|
[&](const SingleDerivedPath::Opaque &) {
|
|
|
|
|
// plain drv path; no experimental features required.
|
|
|
|
|
},
|
|
|
|
|
[&](const SingleDerivedPath::Built &) {
|
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
|
|
|
|
},
|
|
|
|
|
}, drv.raw());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SingleDerivedPath::Built SingleDerivedPath::Built::parse(
|
|
|
|
|
const Store & store, ref<SingleDerivedPath> drv,
|
|
|
|
|
std::string_view output,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
drvRequireExperiment(*drv, xpSettings);
|
|
|
|
|
return {
|
|
|
|
|
.drvPath = drv,
|
|
|
|
|
.output = std::string { output },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DerivedPath::Built DerivedPath::Built::parse(
|
|
|
|
|
const Store & store, ref<SingleDerivedPath> drv,
|
|
|
|
|
std::string_view outputsS,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2021-03-02 05:50:41 +02:00
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
drvRequireExperiment(*drv, xpSettings);
|
2023-01-12 01:57:18 +02:00
|
|
|
|
return {
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
.drvPath = drv,
|
2023-01-12 01:57:18 +02:00
|
|
|
|
.outputs = OutputsSpec::parse(outputsS),
|
|
|
|
|
};
|
2021-03-02 05:50:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
static SingleDerivedPath parseWithSingle(
|
|
|
|
|
const Store & store, std::string_view s, std::string_view separator,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2021-03-02 05:50:41 +02:00
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
size_t n = s.rfind(separator);
|
|
|
|
|
return n == s.npos
|
|
|
|
|
? (SingleDerivedPath) SingleDerivedPath::Opaque::parse(store, s)
|
|
|
|
|
: (SingleDerivedPath) SingleDerivedPath::Built::parse(store,
|
|
|
|
|
make_ref<SingleDerivedPath>(parseWithSingle(
|
|
|
|
|
store,
|
|
|
|
|
s.substr(0, n),
|
|
|
|
|
separator,
|
|
|
|
|
xpSettings)),
|
|
|
|
|
s.substr(n + 1),
|
|
|
|
|
xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SingleDerivedPath SingleDerivedPath::parse(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::string_view s,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
return parseWithSingle(store, s, "^", xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SingleDerivedPath SingleDerivedPath::parseLegacy(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::string_view s,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
return parseWithSingle(store, s, "!", xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DerivedPath parseWith(
|
|
|
|
|
const Store & store, std::string_view s, std::string_view separator,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
size_t n = s.rfind(separator);
|
2021-03-02 05:50:41 +02:00
|
|
|
|
return n == s.npos
|
2021-04-05 16:48:18 +03:00
|
|
|
|
? (DerivedPath) DerivedPath::Opaque::parse(store, s)
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
: (DerivedPath) DerivedPath::Built::parse(store,
|
|
|
|
|
make_ref<SingleDerivedPath>(parseWithSingle(
|
|
|
|
|
store,
|
|
|
|
|
s.substr(0, n),
|
|
|
|
|
separator,
|
|
|
|
|
xpSettings)),
|
|
|
|
|
s.substr(n + 1),
|
|
|
|
|
xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DerivedPath DerivedPath::parse(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::string_view s,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
return parseWith(store, s, "^", xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DerivedPath DerivedPath::parseLegacy(
|
|
|
|
|
const Store & store,
|
|
|
|
|
std::string_view s,
|
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
|
{
|
|
|
|
|
return parseWith(store, s, "!", xpSettings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DerivedPath DerivedPath::fromSingle(const SingleDerivedPath & req)
|
|
|
|
|
{
|
|
|
|
|
return std::visit(overloaded {
|
|
|
|
|
[&](const SingleDerivedPath::Opaque & o) -> DerivedPath {
|
|
|
|
|
return o;
|
|
|
|
|
},
|
|
|
|
|
[&](const SingleDerivedPath::Built & b) -> DerivedPath {
|
|
|
|
|
return DerivedPath::Built {
|
|
|
|
|
.drvPath = b.drvPath,
|
|
|
|
|
.outputs = OutputsSpec::Names { b.output },
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
}, req.raw());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StorePath & SingleDerivedPath::Built::getBaseStorePath() const
|
|
|
|
|
{
|
|
|
|
|
return drvPath->getBaseStorePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const StorePath & DerivedPath::Built::getBaseStorePath() const
|
|
|
|
|
{
|
|
|
|
|
return drvPath->getBaseStorePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename DP>
|
|
|
|
|
static inline const StorePath & getBaseStorePath_(const DP & derivedPath)
|
|
|
|
|
{
|
|
|
|
|
return std::visit(overloaded {
|
|
|
|
|
[&](const typename DP::Built & bfd) -> auto & {
|
|
|
|
|
return bfd.drvPath->getBaseStorePath();
|
|
|
|
|
},
|
|
|
|
|
[&](const typename DP::Opaque & bo) -> auto & {
|
|
|
|
|
return bo.path;
|
|
|
|
|
},
|
|
|
|
|
}, derivedPath.raw());
|
2021-03-02 05:50:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
const StorePath & SingleDerivedPath::getBaseStorePath() const
|
2023-04-15 03:45:11 +03:00
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
return getBaseStorePath_(*this);
|
2023-04-15 03:45:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
const StorePath & DerivedPath::getBaseStorePath() const
|
2023-04-15 03:45:11 +03:00
|
|
|
|
{
|
Make the Derived Path family of types inductive for dynamic derivations
We want to be able to write down `foo.drv^bar.drv^baz`:
`foo.drv^bar.drv` is the dynamic derivation (since it is itself a
derivation output, `bar.drv` from `foo.drv`).
To that end, we create `Single{Derivation,BuiltPath}` types, that are
very similar except instead of having multiple outputs (in a set or
map), they have a single one. This is for everything to the left of the
rightmost `^`.
`NixStringContextElem` has an analogous change, and now can reuse
`SingleDerivedPath` at the top level. In fact, if we ever get rid of
`DrvDeep`, `NixStringContextElem` could be replaced with
`SingleDerivedPath` entirely!
Important note: some JSON formats have changed.
We already can *produce* dynamic derivations, but we can't refer to them
directly. Today, we can merely express building or example at the top
imperatively over time by building `foo.drv^bar.drv`, and then with a
second nix invocation doing `<result-from-first>^baz`, but this is not
declarative. The ethos of Nix of being able to write down the full plan
everything you want to do, and then execute than plan with a single
command, and for that we need the new inductive form of these types.
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-01-16 00:39:04 +02:00
|
|
|
|
return getBaseStorePath_(*this);
|
2023-04-15 03:45:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-01 07:48:01 +02:00
|
|
|
|
}
|