aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/manual/src/release-notes/rl-next.md3
-rw-r--r--src/libcmd/installables.cc34
-rw-r--r--src/libutil/experimental-features.cc1
-rw-r--r--src/libutil/experimental-features.hh1
-rw-r--r--src/nix/nix.md12
-rw-r--r--tests/build-explicit-output.sh18
-rw-r--r--tests/build.sh12
-rw-r--r--tests/local.mk1
8 files changed, 77 insertions, 5 deletions
diff --git a/doc/manual/src/release-notes/rl-next.md b/doc/manual/src/release-notes/rl-next.md
index c869b5e2f..3bb12c013 100644
--- a/doc/manual/src/release-notes/rl-next.md
+++ b/doc/manual/src/release-notes/rl-next.md
@@ -1 +1,4 @@
# Release X.Y (202?-??-??)
+
+* Add experimental *indexed store derivations* installable syntax, part of the
+ the `computed-derivations` experimental feature.
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index 74c8a6df5..483bc1421 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -431,6 +431,26 @@ struct InstallableStorePath : Installable
}
};
+struct InstallableIndexedStorePath : Installable
+{
+ ref<Store> store;
+ DerivedPath::Built req;
+
+ InstallableIndexedStorePath(ref<Store> store, DerivedPath::Built && req)
+ : store(store), req(std::move(req))
+ { }
+
+ std::string what() const override
+ {
+ return req.to_string(*store);
+ }
+
+ DerivedPaths toDerivedPaths() override
+ {
+ return { req };
+ }
+};
+
DerivedPaths InstallableValue::toDerivedPaths()
{
DerivedPaths res;
@@ -731,6 +751,20 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
for (auto & s : ss) {
std::exception_ptr ex;
+ if (s.rfind('!') != std::string::npos) {
+ try {
+ result.push_back(std::make_shared<InstallableIndexedStorePath>(
+ store,
+ DerivedPath::Built::parse(*store, s)));
+ settings.requireExperimentalFeature(Xp::ComputedDerivations);
+ continue;
+ } catch (BadStorePath &) {
+ } catch (...) {
+ if (!ex)
+ ex = std::current_exception();
+ }
+ }
+
if (s.find('/') != std::string::npos) {
try {
result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
diff --git a/src/libutil/experimental-features.cc b/src/libutil/experimental-features.cc
index e033a4116..c1e574c0d 100644
--- a/src/libutil/experimental-features.cc
+++ b/src/libutil/experimental-features.cc
@@ -13,6 +13,7 @@ std::map<ExperimentalFeature, std::string> stringifiedXpFeatures = {
{ Xp::RecursiveNix, "recursive-nix" },
{ Xp::NoUrlLiterals, "no-url-literals" },
{ Xp::FetchClosure, "fetch-closure" },
+ { Xp::ComputedDerivations, "computed-derivations" },
};
const std::optional<ExperimentalFeature> parseExperimentalFeature(const std::string_view & name)
diff --git a/src/libutil/experimental-features.hh b/src/libutil/experimental-features.hh
index 266e41a22..e6213bf86 100644
--- a/src/libutil/experimental-features.hh
+++ b/src/libutil/experimental-features.hh
@@ -22,6 +22,7 @@ enum struct ExperimentalFeature
RecursiveNix,
NoUrlLiterals,
FetchClosure,
+ ComputedDerivations, // RFC 92
};
/**
diff --git a/src/nix/nix.md b/src/nix/nix.md
index 0dacadee6..691aa137b 100644
--- a/src/nix/nix.md
+++ b/src/nix/nix.md
@@ -130,6 +130,18 @@ the Nix store. Here are the recognised types of installables:
If you want to operate on the store derivation itself, pass the
`--derivation` flag.
+* **Indexed store derivations**: `/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv!out`
+
+ *(Experimental, part of by the `computed-derivations` experimental feature.)*
+
+ Store derivations can be indexed with a specific output name. This
+ allows finer control versus just specifying a derivation (without
+ `--derivation`) and getting all the outputs.
+
+ This is especially useful for (currently unstable) floating content
+ addressed derivations, which do not have precomputed output paths that
+ can be used instead.
+
* **Nix attributes**: `--file /path/to/nixpkgs hello`
When the `-f` / `--file` *path* option is given, installables are
diff --git a/tests/build-explicit-output.sh b/tests/build-explicit-output.sh
new file mode 100644
index 000000000..0f2f428db
--- /dev/null
+++ b/tests/build-explicit-output.sh
@@ -0,0 +1,18 @@
+source common.sh
+
+enableFeatures "computed-derivations"
+restartDaemon
+
+drv=$(nix eval -f multiple-outputs.nix --raw a.drvPath)
+if nix build "$drv!not-an-output" --json; then
+ fail "'not-an-output' should fail to build"
+fi
+
+nix build "$drv!first" --json | jq --exit-status '
+ (.[0] |
+ (.drvPath | match(".*multiple-outputs-a.drv")) and
+ (.outputs |
+ (keys | length == 1) and
+ (.first | match(".*multiple-outputs-a-first")) and
+ (has("second") | not)))
+'
diff --git a/tests/build.sh b/tests/build.sh
index 13a0f42be..5757ca73f 100644
--- a/tests/build.sh
+++ b/tests/build.sh
@@ -13,13 +13,15 @@ nix build -f multiple-outputs.nix --json a --no-link | jq --exit-status '
nix build -f multiple-outputs.nix --json a.all b.all --no-link | jq --exit-status '
(.[0] |
(.drvPath | match(".*multiple-outputs-a.drv")) and
- (.outputs | keys | length == 2) and
- (.outputs.first | match(".*multiple-outputs-a-first")) and
- (.outputs.second | match(".*multiple-outputs-a-second")))
+ (.outputs |
+ (keys | length == 2) and
+ (.first | match(".*multiple-outputs-a-first")) and
+ (.second | match(".*multiple-outputs-a-second"))))
and (.[1] |
(.drvPath | match(".*multiple-outputs-b.drv")) and
- (.outputs | keys | length == 1) and
- (.outputs.out | match(".*multiple-outputs-b")))
+ (.outputs |
+ (keys | length == 1) and
+ (.out | match(".*multiple-outputs-b"))))
'
testNormalization () {
diff --git a/tests/local.mk b/tests/local.mk
index cb869f32e..852da096f 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -91,6 +91,7 @@ nix_tests = \
ssh-relay.sh \
plugins.sh \
build.sh \
+ build-explicit-output.sh \
ca/nix-run.sh \
db-migration.sh \
bash-profile.sh \