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 10 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
4 changes: 4 additions & 0 deletions src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace nix {
class Store;
class EvalState;
struct StorePath;
struct StorePathWithOutputs;
enum RepairFlag : bool;


Expand Down Expand Up @@ -89,6 +90,9 @@ public:

const ref<Store> store;

/* List of derivations that got imported. */
std::vector<StorePathWithOutputs> importedDrvs;

private:
SrcToStore srcToStore;

Expand Down
1 change: 1 addition & 0 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void EvalState::realiseContext(const PathSet & context)
throw InvalidPathError(store->printStorePath(ctx));
if (!decoded.second.empty() && ctx.isDerivation()) {
drvs.push_back(StorePathWithOutputs{ctx.clone(), {decoded.second}});
importedDrvs.push_back(StorePathWithOutputs{ctx.clone(), {decoded.second}});
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved

/* Add the output of this derivation to the allowed
paths. */
Expand Down
43 changes: 41 additions & 2 deletions src/nix/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "store-api.hh"
#include "derivations.hh"
#include "nixexpr.hh"
#include "eval.hh"
#include "profiles.hh"

extern char * * environ;
Expand Down Expand Up @@ -47,6 +48,10 @@ StorePathsCommand::StorePathsCommand(bool recursive)
.set(&this->recursive, true);

mkFlag(0, "all", "apply operation to the entire store", &all);

// these options only make sense when recursing
mkFlag('b', "build", "include build dependencies of specified path", &includeBuildDeps);
mkFlag('e', "eval", "include eval dependencies of specified path", &includeEvalDeps);
}

void StorePathsCommand::run(ref<Store> store)
Expand All @@ -61,15 +66,49 @@ void StorePathsCommand::run(ref<Store> store)
}

else {
if (!recursive && (includeBuildDeps || includeEvalDeps))
throw UsageError("--build and --eval require --recursive");
domenkozar marked this conversation as resolved.
Show resolved Hide resolved

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

if (recursive) {
if (includeEvalDeps)
for (auto & i : installables) {
auto state = getEvalState();

for (auto & b : i->toBuildables())
if (!b.drvPath)
throw UsageError("Cannot find eval references for '%s' without a derivation path", b.what());

// force evaluation of package argument
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved
i->toValue(*state);

for (auto & d : (*state).importedDrvs)
matthewbauer marked this conversation as resolved.
Show resolved Hide resolved
storePaths.push_back(std::move(d.path));
}

if (includeBuildDeps)
for (auto & i : installables)
for (auto & b : i->toBuildables()) {
if (!b.drvPath) {
auto info = store->queryPathInfo(b.outputs.at("out"));
if (info->deriver)
storePaths.push_back(info->deriver->clone());
else
throw UsageError("Cannot find build references for '%s' without a derivation path", b.what());
} else
storePaths.push_back(b.drvPath->clone());
}

auto includeDerivers = includeBuildDeps || includeEvalDeps;

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

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

bool includeBuildDeps = false;
bool includeEvalDeps = false;

protected:

RealiseMode realiseMode = NoBuild;
Expand Down
4 changes: 4 additions & 0 deletions src/nix/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct Buildable
{
std::optional<StorePath> drvPath;
std::map<std::string, StorePath> outputs;

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

typedef std::vector<Buildable> Buildables;
Expand Down