2023-05-11 22:01:41 +00:00
|
|
|
#include "downstream-placeholder.hh"
|
|
|
|
#include "derivations.hh"
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
std::string DownstreamPlaceholder::render() const
|
|
|
|
{
|
2024-08-01 20:42:02 +00:00
|
|
|
return "/" + hash.to_string(Base::Base32, false);
|
2023-05-11 22:01:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::unknownCaOutput(
|
|
|
|
const StorePath & drvPath,
|
2023-08-25 13:53:12 +00:00
|
|
|
OutputNameView outputName,
|
2023-07-13 03:33:43 +00:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
2023-05-11 22:01:41 +00:00
|
|
|
{
|
2023-07-13 03:33:43 +00:00
|
|
|
xpSettings.require(Xp::CaDerivations);
|
2023-05-11 22:01:41 +00: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 {
|
2024-08-01 20:42:02 +00:00
|
|
|
hashString(HashType::SHA256, clearText)
|
2023-05-11 22:01:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::unknownDerivation(
|
|
|
|
const DownstreamPlaceholder & placeholder,
|
2023-08-25 13:53:12 +00:00
|
|
|
OutputNameView outputName,
|
2023-05-11 22:01:41 +00:00
|
|
|
const ExperimentalFeatureSettings & xpSettings)
|
|
|
|
{
|
|
|
|
xpSettings.require(Xp::DynamicDerivations);
|
|
|
|
auto compressed = compressHash(placeholder.hash, 20);
|
|
|
|
auto clearText = "nix-computed-output:"
|
2024-08-01 20:42:02 +00:00
|
|
|
+ compressed.to_string(Base::Base32, false)
|
2023-05-11 22:01:41 +00:00
|
|
|
+ ":" + std::string { outputName };
|
|
|
|
return DownstreamPlaceholder {
|
2024-08-01 20:42:02 +00:00
|
|
|
hashString(HashType::SHA256, clearText)
|
2023-05-11 22:01:41 +00: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-15 22:39:04 +00:00
|
|
|
DownstreamPlaceholder DownstreamPlaceholder::fromSingleDerivedPathBuilt(
|
2021-03-10 04:22:56 +00: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-15 22:39:04 +00:00
|
|
|
{
|
|
|
|
return std::visit(overloaded {
|
|
|
|
[&](const SingleDerivedPath::Opaque & o) {
|
2021-03-10 04:22:56 +00: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-15 22:39:04 +00:00
|
|
|
},
|
|
|
|
[&](const SingleDerivedPath::Built & b2) {
|
|
|
|
return DownstreamPlaceholder::unknownDerivation(
|
2021-03-10 04:22:56 +00: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-15 22:39:04 +00:00
|
|
|
},
|
|
|
|
}, b.drvPath->raw());
|
|
|
|
}
|
|
|
|
|
2023-05-11 22:01:41 +00:00
|
|
|
}
|