diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-02-17 18:37:35 -0500 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-04-07 08:34:58 -0400 |
commit | 59e072871410ba88694cf2597079a9f0f115e458 (patch) | |
tree | 50fb7642ffc6bafa527e4f67aa38b0ac1bad9d77 /src/nix/derivation-add.cc | |
parent | 27597f813126bf0e866c6f6ba35dc7d3761843f8 (diff) |
Create `nix derivation add` command
Also refine `nix derivation show`'s docs very slightly.
Diffstat (limited to 'src/nix/derivation-add.cc')
-rw-r--r-- | src/nix/derivation-add.cc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/nix/derivation-add.cc b/src/nix/derivation-add.cc new file mode 100644 index 000000000..4d91d4538 --- /dev/null +++ b/src/nix/derivation-add.cc @@ -0,0 +1,45 @@ +// FIXME: rename to 'nix plan add' or 'nix derivation add'? + +#include "command.hh" +#include "common-args.hh" +#include "store-api.hh" +#include "archive.hh" +#include "derivations.hh" +#include <nlohmann/json.hpp> + +using namespace nix; +using json = nlohmann::json; + +struct CmdAddDerivation : MixDryRun, StoreCommand +{ + std::string description() override + { + return "Add a store derivation"; + } + + std::string doc() override + { + return + #include "derivation-add.md" + ; + } + + Category category() override { return catUtility; } + + void run(ref<Store> store) override + { + auto json = nlohmann::json::parse(drainFD(STDIN_FILENO)); + + auto drv = Derivation::fromJSON(*store, json); + + auto drvPath = writeDerivation(*store, drv, NoRepair, /* read only */ dryRun); + + drv.checkInvariants(*store, drvPath); + + writeDerivation(*store, drv, NoRepair, dryRun); + + logger->cout("%s", store->printStorePath(drvPath)); + } +}; + +static auto rCmdAddDerivation = registerCommand2<CmdAddDerivation>({"derivation", "add"}); |