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

Add --include-build-refs to `nix path-info' command #3523

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7ccc02b
Add --include-ifd option to nix-instantiate
matthewbauer Apr 16, 2020
40674f4
Add “nix refs” command
matthewbauer Apr 22, 2020
2eb9e07
Remove --include-ifd from nix-instantiate
matthewbauer Apr 22, 2020
abe2d7f
Use toBuildables to ensure we have derivation
matthewbauer Apr 22, 2020
18182a7
Remove ‘nix refs’
matthewbauer Apr 23, 2020
4eeddcd
Add --build and --eval flag to “nix path-info”
matthewbauer Apr 23, 2020
f25f023
Merge remote-tracking branch 'origin/master' into nix-refs
matthewbauer Apr 23, 2020
93684d5
Add "what()" for Buildable
matthewbauer Apr 27, 2020
3a155a9
Use proper data type for importedDrvs
matthewbauer Jun 11, 2020
98d5a3b
Support getting build paths from output path
matthewbauer Jun 11, 2020
34fc432
Update src/nix/command.cc
matthewbauer Jun 11, 2020
240b66a
Include all paths in --eval
matthewbauer Jun 11, 2020
4e2e3fa
Rename importedPaths to realisedPaths
matthewbauer Jun 12, 2020
d52e556
Add option to path-info to skip run deps
matthewbauer Jun 12, 2020
bf02207
Only include derivers for --build
matthewbauer Jun 12, 2020
c2f0229
Add error when --no-run and --build are combined
matthewbauer Jun 12, 2020
0ddf019
Merge remote-tracking branch 'origin/master' into nix-refs
matthewbauer Jun 26, 2020
6c591a8
Remove --eval support
matthewbauer Jun 26, 2020
7582950
Merge branch 'master' into nix-refs
matthewbauer Aug 28, 2020
141dfb0
Merge remote-tracking branch 'origin/master' into nix-refs
matthewbauer Jan 29, 2021
1012ab2
Rename --build to --include-build-refs
matthewbauer Jan 29, 2021
86b65fc
Try to fix build error
matthewbauer Jan 30, 2021
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
35 changes: 33 additions & 2 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "local-fs-store.hh"
#include "derivations.hh"
#include "nixexpr.hh"
#include "eval.hh"
#include "profiles.hh"

#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -79,6 +80,13 @@ StorePathsCommand::StorePathsCommand(bool recursive)
.category = installablesCategory,
.handler = {&all, true},
});

addFlag({
.longName = "include-build-refs",
.description = "Include build-time references of specified path closure.",
.category = installablesCategory,
.handler = {&includeBuildRefs, true},
});
}

void StorePathsCommand::run(ref<Store> store)
Expand All @@ -93,15 +101,38 @@ void StorePathsCommand::run(ref<Store> store)
}

else {
if (!recursive && includeBuildRefs)
throw UsageError("--include-build-refs requires --recursive");

for (auto & p : toStorePaths(store, realiseMode, operateOn, installables))
storePaths.push_back(p);

if (recursive) {
if (includeBuildRefs) {
for (auto & i : installables) {
for (auto & b : i->toBuildables()) {
std::visit(overloaded {
[&](BuildableOpaque bo) {
auto info = store->queryPathInfo(bo.path);
if (info->deriver)
storePaths.push_back(*info->deriver);
else
throw UsageError("Cannot find build references for '%s' without a derivation path", store->printStorePath(bo.path));
},
[&](BuildableFromDrv bfd) {
storePaths.push_back(bfd.drvPath);
},
}, b);
}
}
}

StorePathSet closure;
store->computeFSClosure(StorePathSet(storePaths.begin(), storePaths.end()), closure, false, false);
store->computeFSClosure(StorePathSet(storePaths.begin(), storePaths.end()), closure, false, includeBuildRefs);
storePaths.clear();
for (auto & p : closure)
storePaths.push_back(p);
if (!p.isDerivation())
storePaths.push_back(p);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ private:
bool recursive = false;
bool all = false;

bool includeBuildRefs = false;

protected:

Realise realiseMode = Realise::Derivation;
Expand Down
4 changes: 4 additions & 0 deletions src/libcmd/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ struct BuildableFromDrv {
StorePath drvPath;
std::map<std::string, std::optional<StorePath>> outputs;
nlohmann::json toJSON(ref<Store> store) const;

std::string what() {
return fmt("%s", outputs.at("out") ? outputs.at("out")->name() : "unknown");
}
};

typedef std::variant<
Expand Down