Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low level <drvPath>^<outputName> installable syntax to match existing <highLevelInstallable>^<outputNames> syntax #4543

Merged
merged 30 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8499f32
New "indexed" installable syntax: `<drvPath>!<outputName>`
Ericson2314 Feb 12, 2021
1ef88da
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Sep 30, 2021
e5c42bb
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Mar 10, 2022
0966532
Merge remote-tracking branch 'upstream' into indexed-store-path-outputs
Ericson2314 Mar 25, 2022
9c6be01
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Apr 1, 2022
6951b26
Require (new) computed-derivations experimental feature for ! install…
Ericson2314 Apr 1, 2022
5c1f2e0
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Apr 7, 2022
fda2224
Add release notes mark experimental
Ericson2314 Apr 7, 2022
41e755b
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Apr 19, 2022
6b61d77
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Apr 19, 2022
b18720e
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 May 12, 2022
49ad315
Use `^` not `!` in indexed store derivations installable syntax
Ericson2314 May 12, 2022
b585548
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Jun 2, 2022
6cafe30
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Jul 14, 2022
f3262bc
Combine `InstallableStorePath` with `InstallableIndexedStorePath`
Ericson2314 Jul 14, 2022
8735f55
Fix bug, test more, document more
Ericson2314 Jul 15, 2022
279ecf7
Remove `computed-derivations` experimental feature
Ericson2314 Jul 15, 2022
0e4ec98
Fix typo in docs
Ericson2314 Jul 15, 2022
12461e2
Leverage existing docs for new store-path^outputs syntax
Ericson2314 Jul 15, 2022
13f2a6f
Merge branch 'master' into indexed-store-path-outputs
Ericson2314 Oct 28, 2022
26534f1
Merge branch 'master' into indexed-store-path-outputs
Ericson2314 Nov 25, 2022
1879c7c
Merge branch 'master' into indexed-store-path-outputs
Ericson2314 Dec 12, 2022
dc075dc
Apply suggestions from code review
Ericson2314 Dec 12, 2022
c7cce3e
Improve release notes
Ericson2314 Dec 12, 2022
d8c1c24
Adjust docs
Ericson2314 Dec 12, 2022
c886b18
Merge new tests into `build.sh`
Ericson2314 Dec 12, 2022
dabb03b
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Dec 12, 2022
32ae715
Fix typos in the docs
Ericson2314 Dec 12, 2022
5273cf4
Merge remote-tracking branch 'upstream/master' into indexed-store-pat…
Ericson2314 Dec 12, 2022
f61d575
Merge branch 'indexed-store-path-outputs' of github.com:obsidiansyste…
Ericson2314 Dec 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Release X.Y (202?-??-??)

* Add experimental *indexed store derivations* installable syntax, part of the
the `computed-derivations` experimental feature.
34 changes: 34 additions & 0 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Ericson2314 marked this conversation as resolved.
Show resolved Hide resolved
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)));
Expand Down
1 change: 1 addition & 0 deletions src/libutil/experimental-features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/libutil/experimental-features.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum struct ExperimentalFeature
RecursiveNix,
NoUrlLiterals,
FetchClosure,
ComputedDerivations, // RFC 92
};

/**
Expand Down
12 changes: 12 additions & 0 deletions src/nix/nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)*
Ericson2314 marked this conversation as resolved.
Show resolved Hide resolved

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.

Ericson2314 marked this conversation as resolved.
Show resolved Hide resolved
* **Nix attributes**: `--file /path/to/nixpkgs hello`

When the `-f` / `--file` *path* option is given, installables are
Expand Down
18 changes: 18 additions & 0 deletions tests/build-explicit-output.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
source common.sh
Ericson2314 marked this conversation as resolved.
Show resolved Hide resolved

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)))
'
12 changes: 7 additions & 5 deletions tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions tests/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down