diff options
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/command.cc | 16 | ||||
-rw-r--r-- | src/nix/command.hh | 6 | ||||
-rw-r--r-- | src/nix/copy.cc | 1 | ||||
-rw-r--r-- | src/nix/installables.cc | 28 | ||||
-rw-r--r-- | src/nix/progress-bar.cc | 2 | ||||
-rw-r--r-- | src/nix/run.cc | 2 | ||||
-rw-r--r-- | src/nix/show-derivation.cc | 119 | ||||
-rw-r--r-- | src/nix/why-depends.cc | 6 |
8 files changed, 172 insertions, 8 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc index f69c56896567..0f6bb294b38c 100644 --- a/src/nix/command.cc +++ b/src/nix/command.cc @@ -100,9 +100,21 @@ void StoreCommand::run() run(getStore()); } -StorePathsCommand::StorePathsCommand() +StorePathsCommand::StorePathsCommand(bool recursive) + : recursive(recursive) { - mkFlag('r', "recursive", "apply operation to closure of the specified paths", &recursive); + if (recursive) + mkFlag() + .longName("no-recursive") + .description("apply operation to specified paths only") + .set(&this->recursive, false); + else + mkFlag() + .longName("recursive") + .shortName('r') + .description("apply operation to closure of the specified paths") + .set(&this->recursive, true); + mkFlag(0, "all", "apply operation to the entire store", &all); } diff --git a/src/nix/command.hh b/src/nix/command.hh index 182b01ef92e3..bf897f620db6 100644 --- a/src/nix/command.hh +++ b/src/nix/command.hh @@ -141,7 +141,7 @@ private: public: - StorePathsCommand(); + StorePathsCommand(bool recursive = false); using StoreCommand::run; @@ -207,4 +207,8 @@ PathSet toStorePaths(ref<Store> store, RealiseMode mode, Path toStorePath(ref<Store> store, RealiseMode mode, std::shared_ptr<Installable> installable); +PathSet toDerivations(ref<Store> store, + std::vector<std::shared_ptr<Installable>> installables, + bool useDeriver = false); + } diff --git a/src/nix/copy.cc b/src/nix/copy.cc index 8d7c6a0e8e4c..071ac3890aa9 100644 --- a/src/nix/copy.cc +++ b/src/nix/copy.cc @@ -17,6 +17,7 @@ struct CmdCopy : StorePathsCommand SubstituteFlag substitute = NoSubstitute; CmdCopy() + : StorePathsCommand(true) { mkFlag(0, "from", "store-uri", "URI of the source Nix store", &srcUri); mkFlag(0, "to", "store-uri", "URI of the destination Nix store", &dstUri); diff --git a/src/nix/installables.cc b/src/nix/installables.cc index 76df05fa32d2..c83d6316d3f3 100644 --- a/src/nix/installables.cc +++ b/src/nix/installables.cc @@ -267,7 +267,9 @@ Buildables toBuildables(ref<Store> store, RealiseMode mode, outputNames.insert(output.first); pathsToBuild.insert( b.drvPath + "!" + concatStringsSep(",", outputNames)); - } + } else + for (auto & output : b.outputs) + pathsToBuild.insert(output.second); buildables.push_back(std::move(b)); } } @@ -303,6 +305,30 @@ Path toStorePath(ref<Store> store, RealiseMode mode, return *paths.begin(); } +PathSet toDerivations(ref<Store> store, + std::vector<std::shared_ptr<Installable>> installables, bool useDeriver) +{ + PathSet drvPaths; + + for (auto & i : installables) + for (auto & b : i->toBuildables()) { + if (b.drvPath.empty()) { + if (!useDeriver) + throw Error("argument '%s' did not evaluate to a derivation", i->what()); + for (auto & output : b.outputs) { + auto derivers = store->queryValidDerivers(output.second); + if (derivers.empty()) + throw Error("'%s' does not have a known deriver", i->what()); + // FIXME: use all derivers? + drvPaths.insert(*derivers.begin()); + } + } else + drvPaths.insert(b.drvPath); + } + + return drvPaths; +} + void InstallablesCommand::prepare() { installables = parseInstallables(*this, getStore(), _installables, useDefaultInstallables()); diff --git a/src/nix/progress-bar.cc b/src/nix/progress-bar.cc index 0c42fe5cc136..76138b2cce28 100644 --- a/src/nix/progress-bar.cc +++ b/src/nix/progress-bar.cc @@ -165,7 +165,7 @@ public: if (type == actQueryPathInfo) { auto name = storePathToName(getS(fields, 0)); - i->s = fmt("querying about " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1)); + i->s = fmt("querying " ANSI_BOLD "%s" ANSI_NORMAL " on %s", name, getS(fields, 1)); } if ((type == actDownload && hasAncestor(*state, actCopyPath, parent)) diff --git a/src/nix/run.cc b/src/nix/run.cc index c72ede99c1c2..2f93ca351502 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -130,6 +130,8 @@ struct CmdRun : InstallablesCommand stopProgressBar(); + restoreSignals(); + /* If this is a diverted store (i.e. its "logical" location (typically /nix/store) differs from its "physical" location (e.g. /home/eelco/nix/store), then run the command in a diff --git a/src/nix/show-derivation.cc b/src/nix/show-derivation.cc new file mode 100644 index 000000000000..ee94fded364f --- /dev/null +++ b/src/nix/show-derivation.cc @@ -0,0 +1,119 @@ +// FIXME: integrate this with nix path-info? + +#include "command.hh" +#include "common-args.hh" +#include "store-api.hh" +#include "archive.hh" +#include "json.hh" +#include "derivations.hh" + +using namespace nix; + +struct CmdShowDerivation : InstallablesCommand +{ + bool recursive = false; + + CmdShowDerivation() + { + mkFlag() + .longName("recursive") + .shortName('r') + .description("include the dependencies of the specified derivations") + .set(&recursive, true); + } + + std::string name() override + { + return "show-derivation"; + } + + std::string description() override + { + return "show the contents of a store derivation"; + } + + Examples examples() override + { + return { + Example{ + "To show the store derivation that results from evaluating the Hello package:", + "nix show-derivation nixpkgs.hello" + }, + Example{ + "To show the full derivation graph (if available) that produced your NixOS system:", + "nix show-derivation -r /run/current-system" + }, + }; + } + + void run(ref<Store> store) override + { + auto drvPaths = toDerivations(store, installables, true); + + if (recursive) { + PathSet closure; + store->computeFSClosure(drvPaths, closure); + drvPaths = closure; + } + + { + + JSONObject jsonRoot(std::cout, true); + + for (auto & drvPath : drvPaths) { + if (!isDerivation(drvPath)) continue; + + auto drvObj(jsonRoot.object(drvPath)); + + auto drv = readDerivation(drvPath); + + { + auto outputsObj(drvObj.object("outputs")); + for (auto & output : drv.outputs) { + auto outputObj(outputsObj.object(output.first)); + outputObj.attr("path", output.second.path); + if (output.second.hash != "") { + outputObj.attr("hashAlgo", output.second.hashAlgo); + outputObj.attr("hash", output.second.hash); + } + } + } + + { + auto inputsList(drvObj.list("inputSrcs")); + for (auto & input : drv.inputSrcs) + inputsList.elem(input); + } + + { + auto inputDrvsObj(drvObj.object("inputDrvs")); + for (auto & input : drv.inputDrvs) { + auto inputList(inputDrvsObj.list(input.first)); + for (auto & outputId : input.second) + inputList.elem(outputId); + } + } + + drvObj.attr("platform", drv.platform); + drvObj.attr("builder", drv.builder); + + { + auto argsList(drvObj.list("args")); + for (auto & arg : drv.args) + argsList.elem(arg); + } + + { + auto envObj(drvObj.object("env")); + for (auto & var : drv.env) + envObj.attr(var.first, var.second); + } + } + + } + + std::cout << "\n"; + } +}; + +static RegisterCommand r1(make_ref<CmdShowDerivation>()); diff --git a/src/nix/why-depends.cc b/src/nix/why-depends.cc index a90d07ed26ee..17e0595ae887 100644 --- a/src/nix/why-depends.cc +++ b/src/nix/why-depends.cc @@ -156,7 +156,7 @@ struct CmdWhyDepends : SourceExprCommand printNode = [&](Node & node, const string & firstPad, const string & tailPad) { assert(node.dist != inf); - std::cerr << fmt("%s%s%s%s" ANSI_NORMAL "\n", + std::cout << fmt("%s%s%s%s" ANSI_NORMAL "\n", firstPad, node.visited ? "\e[38;5;244m" : "", firstPad != "" ? "=> " : "", @@ -209,7 +209,7 @@ struct CmdWhyDepends : SourceExprCommand for (auto & hash : hashes) { auto pos = contents.find(hash); if (pos != std::string::npos) { - size_t margin = 16; + size_t margin = 32; auto pos2 = pos >= margin ? pos - margin : 0; hits[hash].emplace_back(fmt("%s: …%s…\n", p2, @@ -244,7 +244,7 @@ struct CmdWhyDepends : SourceExprCommand for (auto & hit : hits[hash]) { bool first = hit == *hits[hash].begin(); - std::cerr << tailPad + std::cout << tailPad << (first ? (last ? treeLast : treeConn) : (last ? treeNull : treeLine)) << hit; if (!all) break; |