-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db8a0be
commit cf58363
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 | ||
{ | ||
Path path; | ||
std::optional<std::string> namePart; | ||
|
||
CmdAddDerivation() | ||
{ | ||
addFlag({ | ||
.longName = "name", | ||
.shortName = 'n', | ||
.description = "Override the name component of the derivation path. It defaults to the base name of *path*.", | ||
.labels = {"name"}, | ||
.handler = {&namePart}, | ||
}); | ||
} | ||
|
||
std::string description() override | ||
{ | ||
return "Add a store derivation"; | ||
} | ||
|
||
std::string doc() override | ||
{ | ||
return | ||
#include "add-derivation.md" | ||
; | ||
} | ||
|
||
Category category() override { return catUtility; } | ||
|
||
void run(ref<Store> store) override | ||
{ | ||
if (!namePart) namePart = baseNameOf(path); | ||
auto & name = *namePart; | ||
|
||
auto json = nlohmann::json::parse(drainFD(STDIN_FILENO)); | ||
|
||
auto drv = Derivation::fromJSON(*store, name, json); | ||
drv.name = name; | ||
|
||
auto drvPath = writeDerivation(*store, drv, NoRepair, /* read only */ true); | ||
|
||
drv.checkInvariants(*store, drvPath); | ||
|
||
writeDerivation(*store, drv, NoRepair, dryRun); | ||
|
||
logger->cout("%s", store->printStorePath(drvPath)); | ||
} | ||
}; | ||
|
||
static auto rCmdAddDerivation = registerCommand<CmdAddDerivation>("add-derivation"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
R""( | ||
|
||
# Description | ||
|
||
This command reads from the given path a JSON representation of a | ||
[store derivation] to which *installables* evaluate. Store derivations | ||
are used internally by Nix. They are store paths with extension `.drv` | ||
that represent the build-time dependency graph to which a Nix | ||
expression evaluates. | ||
|
||
[store derivation]: ../../glossary.md#gloss-store-derivation | ||
|
||
The JSON format is documented under the [`show-derivation`] command. | ||
|
||
[`show-derivation`]: ./nix3-show-derivation.md | ||
|
||
)"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
source common.sh | ||
|
||
export NIX_TESTS_CA_BY_DEFAULT=1 | ||
|
||
drvPath=$(nix-instantiate ../simple.nix) | ||
|
||
nix show-derivation $drvPath | jq .[] > $TEST_HOME/simple.json | ||
|
||
drvPath2=$(nix add-derivation --name simple < $TEST_HOME/simple.json) | ||
|
||
[[ "$drvPath" = "$drvPath2" ]] | ||
|
||
# Content-addressed derivations can be renamed. | ||
nix add-derivation --name foo < $TEST_HOME/simple.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
source common.sh | ||
|
||
drvPath=$(nix-instantiate simple.nix) | ||
|
||
nix show-derivation $drvPath | jq .[] > $TEST_HOME/simple.json | ||
|
||
drvPath2=$(nix add-derivation --name simple < $TEST_HOME/simple.json) | ||
|
||
[[ "$drvPath" = "$drvPath2" ]] | ||
|
||
# Input addressed derivations cannot be renamed. | ||
expectStderr 1 nix add-derivation --name foo < $TEST_HOME/simple.json | grepQuiet "has incorrect output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters