2023-05-12 01:01:41 +03:00
|
|
|
#include "downstream-placeholder.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::string DownstreamPlaceholder::render() const
|
|
|
|
{
|
2023-11-28 16:38:15 +02:00
|
|
|
return "/" + hash.to_string(HashFormat::Nix32, false);
|
2023-05-12 01:01:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::unknownCaOutput(
|
|
|
|
const StorePath & drvPath,
|
2023-08-25 16:53:12 +03:00
|
|
|
OutputNameView outputName,
|
2023-07-13 06:33:43 +03:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2023-05-12 01:01:41 +03:00
|
|
|
{
|
2023-07-13 06:33:43 +03:00
|
|
|
xpSettings.require(Xp::CaDerivations);
|
2023-05-12 01:01:41 +03:00
|
|
|
auto drvNameWithExtension = drvPath.name();
|
|
|
|
auto drvName = drvNameWithExtension.substr(0, drvNameWithExtension.size() - 4);
|
|
|
|
auto clearText = "nix-upstream-output:" + std::string { drvPath.hashPart() } + ":" + outputPathName(drvName, outputName);
|
|
|
|
return DownstreamPlaceholder {
|
2023-11-28 15:20:27 +02:00
|
|
|
hashString(HashAlgorithm::SHA256, clearText)
|
2023-05-12 01:01:41 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::unknownDerivation(
|
|
|
|
const DownstreamPlaceholder & placeholder,
|
2023-08-25 16:53:12 +03:00
|
|
|
OutputNameView outputName,
|
2023-05-12 01:01:41 +03:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
{
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
|
|
|
auto compressed = compressHash(placeholder.hash, 20);
|
|
|
|
auto clearText = "nix-computed-output:"
|
2023-11-28 16:38:15 +02:00
|
|
|
+ compressed.to_string(HashFormat::Nix32, false)
|
2023-05-12 01:01:41 +03:00
|
|
|
+ ":" + std::string { outputName };
|
|
|
|
return DownstreamPlaceholder {
|
2023-11-28 15:20:27 +02:00
|
|
|
hashString(HashAlgorithm::SHA256, clearText)
|
2023-05-12 01:01:41 +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
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::fromSingleDerivedPathBuilt(
|
2021-03-10 06:22:56 +02:00
|
|
|
const SingleDerivedPath::Built & b,
|
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
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(overloaded {
|
|
|
|
[&](const SingleDerivedPath::Opaque & o) {
|
2021-03-10 06:22:56 +02:00
|
|
|
return DownstreamPlaceholder::unknownCaOutput(o.path, b.output, xpSettings);
|
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 & b2) {
|
|
|
|
return DownstreamPlaceholder::unknownDerivation(
|
2021-03-10 06:22:56 +02:00
|
|
|
DownstreamPlaceholder::fromSingleDerivedPathBuilt(b2, xpSettings),
|
|
|
|
b.output,
|
|
|
|
xpSettings);
|
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
|
|
|
},
|
|
|
|
}, b.drvPath->raw());
|
|
|
|
}
|
|
|
|
|
2023-05-12 01:01:41 +03:00
|
|
|
}
|