mirror of
https://github.com/NixOS/nix.git
synced 2024-11-25 16:23:02 +00:00
New "indexed" installable syntax: <drvPath>!<outputName>
Being conservative and only doing a single output name for now.
This commit is contained in:
parent
4bf3eb27e6
commit
8499f32fb2
@ -349,6 +349,31 @@ 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() override
|
||||||
|
{
|
||||||
|
return req.to_string(*store);
|
||||||
|
}
|
||||||
|
|
||||||
|
DerivedPathsWithHints toDerivedPathsWithHints() override
|
||||||
|
{
|
||||||
|
std::map<std::string, std::optional<StorePath>> outputs;
|
||||||
|
for (auto & output : req.outputs)
|
||||||
|
outputs.insert_or_assign(output, std::nullopt);
|
||||||
|
return {
|
||||||
|
DerivedPathWithHints { DerivedPathWithHints::Built { req.drvPath, std::move(outputs) } }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints()
|
DerivedPathsWithHints InstallableValue::toDerivedPathsWithHints()
|
||||||
{
|
{
|
||||||
DerivedPathsWithHints res;
|
DerivedPathsWithHints res;
|
||||||
@ -638,7 +663,22 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
|||||||
ex = std::current_exception();
|
ex = std::current_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.find('/') != std::string::npos) {
|
auto found = s.rfind('!');
|
||||||
|
if (found != std::string::npos) {
|
||||||
|
try {
|
||||||
|
result.push_back(std::make_shared<InstallableIndexedStorePath>(
|
||||||
|
store,
|
||||||
|
DerivedPath::Built::parse(*store, s)));
|
||||||
|
continue;
|
||||||
|
} catch (BadStorePath &) {
|
||||||
|
} catch (...) {
|
||||||
|
if (!ex)
|
||||||
|
ex = std::current_exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
found = s.find('/');
|
||||||
|
if (found != std::string::npos) {
|
||||||
try {
|
try {
|
||||||
result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
|
result.push_back(std::make_shared<InstallableStorePath>(store, store->followLinksToStorePath(s)));
|
||||||
continue;
|
continue;
|
||||||
|
@ -94,6 +94,16 @@ the Nix store. Here are the recognised types of installables:
|
|||||||
If you want to operate on the store derivation itself, pass the
|
If you want to operate on the store derivation itself, pass the
|
||||||
`--derivation` flag.
|
`--derivation` flag.
|
||||||
|
|
||||||
|
* **Indexed store derivations**: `/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv!out`
|
||||||
|
|
||||||
|
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`
|
* **Nix attributes**: `--file /path/to/nixpkgs hello`
|
||||||
|
|
||||||
When the `-f` / `--file` *path* option is given, installables are
|
When the `-f` / `--file` *path* option is given, installables are
|
||||||
|
17
tests/build-explicit-output.sh
Normal file
17
tests/build-explicit-output.sh
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
source common.sh
|
||||||
|
|
||||||
|
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 |
|
||||||
|
.first and
|
||||||
|
(has("second") | not)))
|
||||||
|
'
|
||||||
|
# TODO use
|
||||||
|
# (.first | match(".*multiple-outputs-a-first")) and
|
||||||
|
# once we make it put the result paths in the buildables.
|
@ -4,8 +4,9 @@ expectedJSONRegex='\[\{"drvPath":".*multiple-outputs-a.drv","outputs":\{"first":
|
|||||||
nix build -f multiple-outputs.nix --json a.all b.all | jq --exit-status '
|
nix build -f multiple-outputs.nix --json a.all b.all | jq --exit-status '
|
||||||
(.[0] |
|
(.[0] |
|
||||||
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
(.drvPath | match(".*multiple-outputs-a.drv")) and
|
||||||
(.outputs.first | match(".*multiple-outputs-a-first")) and
|
(.outputs |
|
||||||
(.outputs.second | match(".*multiple-outputs-a-second")))
|
(.first | match(".*multiple-outputs-a-first")) and
|
||||||
|
(.second | match(".*multiple-outputs-a-second"))))
|
||||||
and (.[1] |
|
and (.[1] |
|
||||||
(.drvPath | match(".*multiple-outputs-b.drv")) and
|
(.drvPath | match(".*multiple-outputs-b.drv")) and
|
||||||
(.outputs.out | match(".*multiple-outputs-b")))
|
(.outputs.out | match(".*multiple-outputs-b")))
|
||||||
|
@ -41,6 +41,7 @@ nix_tests = \
|
|||||||
describe-stores.sh \
|
describe-stores.sh \
|
||||||
flakes.sh \
|
flakes.sh \
|
||||||
build.sh \
|
build.sh \
|
||||||
|
build-explicit-output.sh \
|
||||||
compute-levels.sh \
|
compute-levels.sh \
|
||||||
ca/build.sh \
|
ca/build.sh \
|
||||||
ca/substitute.sh \
|
ca/substitute.sh \
|
||||||
|
Loading…
Reference in New Issue
Block a user