diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-07-15 20:22:52 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-07-15 20:25:10 +0200 |
commit | 3624c042ace05db88794e87ee37f3296bab19bc8 (patch) | |
tree | a4fc56352803236c73cd4abaa3a96cae14725809 /src/nix/installables.cc | |
parent | dfe8f3ebc6c5a3d96528794b8822536aac718046 (diff) |
nix: Add --derivation flag to operate on .drv paths
For instance, 'nix why-depends --use-derivation nixpkgs#hello
nixpkgs#glibc' shows why hello's .drv depends on glibc's .drv.
Diffstat (limited to 'src/nix/installables.cc')
-rw-r--r-- | src/nix/installables.cc | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/nix/installables.cc b/src/nix/installables.cc index d464efc35..a13e5a3df 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -128,6 +128,12 @@ SourceExprCommand::SourceExprCommand() .labels = {"expr"}, .handler = {&expr} }); + + addFlag({ + .longName ="derivation", + .description = "operate on the store derivation rather than its outputs", + .handler = {&operateOn, OperateOn::Derivation}, + }); } Strings SourceExprCommand::getDefaultFlakeAttrPaths() @@ -667,22 +673,34 @@ Buildables build(ref<Store> store, Realise mode, return buildables; } -StorePathSet toStorePaths(ref<Store> store, Realise mode, +StorePathSet toStorePaths(ref<Store> store, + Realise mode, OperateOn operateOn, std::vector<std::shared_ptr<Installable>> installables) { StorePathSet outPaths; - for (auto & b : build(store, mode, installables)) - for (auto & output : b.outputs) - outPaths.insert(output.second); + if (operateOn == OperateOn::Output) { + for (auto & b : build(store, mode, installables)) + for (auto & output : b.outputs) + outPaths.insert(output.second); + } else { + if (mode == Realise::Nothing) + settings.readOnlyMode = true; + + for (auto & i : installables) + for (auto & b : i->toBuildables()) + if (b.drvPath) + outPaths.insert(*b.drvPath); + } return outPaths; } -StorePath toStorePath(ref<Store> store, Realise mode, +StorePath toStorePath(ref<Store> store, + Realise mode, OperateOn operateOn, std::shared_ptr<Installable> installable) { - auto paths = toStorePaths(store, mode, {installable}); + auto paths = toStorePaths(store, mode, operateOn, {installable}); if (paths.size() != 1) throw Error("argument '%s' should evaluate to one store path", installable->what()); |