aboutsummaryrefslogtreecommitdiff
path: root/src/nix/derivation-add.cc
blob: 4d91d4538001e9995ebf6a7f9a5d82e5cb41aaa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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"});