-
-
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.
Also refine `nix show-derivation`'s docs very slightly.
- Loading branch information
1 parent
dfddfdb
commit 1745a10
Showing
6 changed files
with
108 additions
and
4 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,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 "add-derivation.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 = 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,18 @@ | ||
R""( | ||
|
||
# Description | ||
|
||
This command reads from standard input a JSON representation of a | ||
[store derivation] to which an [*installable*](./nix.md#installables) evaluates. | ||
|
||
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
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,26 @@ | ||
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 < $TEST_HOME/simple.json) | ||
|
||
[[ "$drvPath" = "$drvPath2" ]] | ||
|
||
# Content-addressed derivations can be renamed. | ||
jq '.name = "foo"' < $TEST_HOME/simple.json > $TEST_HOME/foo.json | ||
drvPath3=$(nix add-derivation --dry-run < $TEST_HOME/foo.json) | ||
# With --dry-run nothing is actually written | ||
[[ ! -e "$drvPath3" ]] | ||
|
||
# Without --dry-run it is actually written | ||
drvPath4=$(nix add-derivation < $TEST_HOME/foo.json) | ||
[[ "$drvPath4" = "$drvPath3" ]] | ||
[[ -e "$drvPath3" ]] | ||
|
||
# The modified derivation read back as JSON matches | ||
nix show-derivation $drvPath3 | jq .[] > $TEST_HOME/foo-read.json | ||
diff $TEST_HOME/foo.json $TEST_HOME/foo-read.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 < $TEST_HOME/simple.json) | ||
|
||
[[ "$drvPath" = "$drvPath2" ]] | ||
|
||
# Input addressed derivations cannot be renamed. | ||
jq '.name = "foo"' < $TEST_HOME/simple.json | expectStderr 1 nix add-derivation | 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