Skip to content

Commit

Permalink
Get rid of the --derivation flag
Browse files Browse the repository at this point in the history
Since PR NixOS#7601, we've had enough flexibility in our types of
installables that it is no longer needed.

Progress towards NixOS#7261
  • Loading branch information
Ericson2314 committed Jun 27, 2023
1 parent 3438db9 commit 2f3e9e9
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 67 deletions.
12 changes: 1 addition & 11 deletions src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ ref<EvalState> EvalCommand::getEvalState()
return ref<EvalState>(evalState);
}

MixOperateOnOptions::MixOperateOnOptions()
{
addFlag({
.longName = "derivation",
.description = "Operate on the [store derivation](../../glossary.md#gloss-store-derivation) rather than its outputs.",
.category = installablesCategory,
.handler = {&operateOn, OperateOn::Derivation},
});
}

BuiltPathsCommand::BuiltPathsCommand(bool recursive)
: recursive(recursive)
{
Expand Down Expand Up @@ -177,7 +167,7 @@ void BuiltPathsCommand::run(ref<Store> store, Installables && installables)
for (auto & p : store->queryAllValidPaths())
paths.push_back(BuiltPath::Opaque{p});
} else {
paths = Installable::toBuiltPaths(getEvalStore(), store, realiseMode, operateOn, installables);
paths = Installable::toBuiltPaths(getEvalStore(), store, realiseMode, installables);
if (recursive) {
// XXX: This only computes the store path closure, ignoring
// intermediate realisations
Expand Down
9 changes: 1 addition & 8 deletions src/libcmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,8 @@ private:
std::string _installable{"."};
};

struct MixOperateOnOptions : virtual Args
{
OperateOn operateOn = OperateOn::Output;

MixOperateOnOptions();
};

/* A command that operates on zero or more store paths. */
struct BuiltPathsCommand : InstallablesCommand, virtual MixOperateOnOptions
struct BuiltPathsCommand : InstallablesCommand
{
private:

Expand Down
27 changes: 8 additions & 19 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -624,33 +624,22 @@ BuiltPaths Installable::toBuiltPaths(
ref<Store> evalStore,
ref<Store> store,
Realise mode,
OperateOn operateOn,
const Installables & installables)
{
if (operateOn == OperateOn::Output) {
BuiltPaths res;
for (auto & p : Installable::build(evalStore, store, mode, installables))
res.push_back(p.path);
return res;
} else {
if (mode == Realise::Nothing)
settings.readOnlyMode = true;

BuiltPaths res;
for (auto & drvPath : Installable::toDerivations(store, installables, true))
res.push_back(BuiltPath::Opaque{drvPath});
return res;
}
BuiltPaths res;
for (auto & p : Installable::build(evalStore, store, mode, installables))
res.push_back(p.path);
return res;
}

StorePathSet Installable::toStorePaths(
ref<Store> evalStore,
ref<Store> store,
Realise mode, OperateOn operateOn,
Realise mode,
const Installables & installables)
{
StorePathSet outPaths;
for (auto & path : toBuiltPaths(evalStore, store, mode, operateOn, installables)) {
for (auto & path : toBuiltPaths(evalStore, store, mode, installables)) {
auto thisOutPaths = path.outPaths();
outPaths.insert(thisOutPaths.begin(), thisOutPaths.end());
}
Expand All @@ -660,10 +649,10 @@ StorePathSet Installable::toStorePaths(
StorePath Installable::toStorePath(
ref<Store> evalStore,
ref<Store> store,
Realise mode, OperateOn operateOn,
Realise mode,
ref<Installable> installable)
{
auto paths = toStorePaths(evalStore, store, mode, operateOn, {installable});
auto paths = toStorePaths(evalStore, store, mode, {installable});

if (paths.size() != 1)
throw Error("argument '%s' should evaluate to one store path", installable->what());
Expand Down
17 changes: 0 additions & 17 deletions src/libcmd/installables.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ enum class Realise {
Nothing
};

/**
* How to handle derivations in commands that operate on store paths.
*/
enum class OperateOn {
/**
* Operate on the output path.
*/
Output,
/**
* Operate on the .drv path.
*/
Derivation
};

/**
* Extra info about a DerivedPath
*
Expand Down Expand Up @@ -169,14 +155,12 @@ struct Installable
ref<Store> evalStore,
ref<Store> store,
Realise mode,
OperateOn operateOn,
const Installables & installables);

static StorePath toStorePath(
ref<Store> evalStore,
ref<Store> store,
Realise mode,
OperateOn operateOn,
ref<Installable> installable);

static std::set<StorePath> toDerivations(
Expand All @@ -188,7 +172,6 @@ struct Installable
ref<Store> evalStore,
ref<Store> store,
Realise mode,
OperateOn operateOn,
const Installables & installables);
};

Expand Down
4 changes: 2 additions & 2 deletions src/nix/develop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ struct Common : InstallableCommand, MixProfile
auto dir = absPath(dir_);
auto installable = parseInstallable(store, installable_);
auto builtPaths = Installable::toStorePaths(
getEvalStore(), store, Realise::Nothing, OperateOn::Output, {installable});
getEvalStore(), store, Realise::Nothing, {installable});
for (auto & path: builtPaths) {
auto from = store->printStorePath(path);
if (script.find(from) == std::string::npos)
Expand Down Expand Up @@ -554,7 +554,7 @@ struct CmdDevelop : Common, MixEnvironment

bool found = false;

for (auto & path : Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, {bashInstallable})) {
for (auto & path : Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, {bashInstallable})) {
auto s = store->printStorePath(path) + "/bin/bash";
if (pathExists(s)) {
shell = s;
Expand Down
6 changes: 3 additions & 3 deletions src/nix/diff-closures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void printClosureDiff(

using namespace nix;

struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions
struct CmdDiffClosures : SourceExprCommand
{
std::string _before, _after;

Expand All @@ -131,9 +131,9 @@ struct CmdDiffClosures : SourceExprCommand, MixOperateOnOptions
void run(ref<Store> store) override
{
auto before = parseInstallable(store, _before);
auto beforePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, before);
auto beforePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, before);
auto after = parseInstallable(store, _after);
auto afterPath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, after);
auto afterPath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, after);
printClosureDiff(store, beforePath, afterPath, "");
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/nix/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment

void run(ref<Store> store, Installables && installables) override
{
auto outPaths = Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, OperateOn::Output, installables);
auto outPaths = Installable::toStorePaths(getEvalStore(), store, Realise::Outputs, installables);

auto accessor = store->getFSAccessor();

Expand Down
6 changes: 3 additions & 3 deletions src/nix/why-depends.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static std::string filterPrintable(const std::string & s)
return res;
}

struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
struct CmdWhyDepends : SourceExprCommand
{
std::string _package, _dependency;
bool all = false;
Expand Down Expand Up @@ -82,7 +82,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
void run(ref<Store> store) override
{
auto package = parseInstallable(store, _package);
auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, operateOn, package);
auto packagePath = Installable::toStorePath(getEvalStore(), store, Realise::Outputs, package);

/* We don't need to build `dependency`. We try to get the store
* path if it's already known, and if not, then it's not a dependency.
Expand All @@ -97,7 +97,7 @@ struct CmdWhyDepends : SourceExprCommand, MixOperateOnOptions
auto dependency = parseInstallable(store, _dependency);
auto optDependencyPath = [&]() -> std::optional<StorePath> {
try {
return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, operateOn, dependency)};
return {Installable::toStorePath(getEvalStore(), store, Realise::Derivation, dependency)};
} catch (MissingRealisation &) {
return std::nullopt;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/dyn-drv/text-hashed-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ nix show-derivation "$drvProducingDrv"

out1=$(nix-build ./text-hashed-output.nix -A producingDrv --no-out-link)

nix path-info $drv --derivation --json | jq
nix path-info $out1 --derivation --json | jq
nix path-info $drv --json | jq
nix path-info $drvProducingDrv --json | jq

test $out1 == $drv
2 changes: 1 addition & 1 deletion tests/why-depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME

cd $TEST_HOME

nix why-depends --derivation --file ./dependencies.nix input2_drv input1_drv
nix why-depends --file ./dependencies.nix input2_drv.drvPath input1_drv.drvPath
nix why-depends --file ./dependencies.nix input2_drv input1_drv

nix-build ./dependencies.nix -A input0_drv -o dep
Expand Down

0 comments on commit 2f3e9e9

Please sign in to comment.