mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
Merge pull request #6419 from ckiee/repl-build-symlink
nix repl: make symlinks with the :bl command
This commit is contained in:
commit
cd0549a9cd
4 changed files with 31 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -79,6 +79,7 @@ perl/Makefile.config
|
|||
/tests/shell.drv
|
||||
/tests/config.nix
|
||||
/tests/ca/config.nix
|
||||
/tests/repl-result-out
|
||||
|
||||
# /tests/lang/
|
||||
/tests/lang/*.out
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
# Release X.Y (202?-??-??)
|
||||
|
||||
* `nix repl` has a new build-'n-link (`:bl`) command that builds a derivation
|
||||
while creating GC root symlinks.
|
||||
|
|
|
@ -33,6 +33,7 @@ extern "C" {
|
|||
#include "command.hh"
|
||||
#include "finally.hh"
|
||||
#include "markdown.hh"
|
||||
#include "local-fs-store.hh"
|
||||
|
||||
#if HAVE_BOEHMGC
|
||||
#define GC_INCLUDE_NEW
|
||||
|
@ -419,7 +420,8 @@ bool NixRepl::processLine(std::string line)
|
|||
<< " <expr> Evaluate and print expression\n"
|
||||
<< " <x> = <expr> Bind expression to variable\n"
|
||||
<< " :a <expr> Add attributes from resulting set to scope\n"
|
||||
<< " :b <expr> Build derivation\n"
|
||||
<< " :b <expr> Build a derivation\n"
|
||||
<< " :bl <expr> Build a derivation, creating GC roots in the working directory\n"
|
||||
<< " :e <expr> Open package or function in $EDITOR\n"
|
||||
<< " :i <expr> Build derivation, then install result into current profile\n"
|
||||
<< " :l <path> Load Nix expression and add it to scope\n"
|
||||
|
@ -502,18 +504,26 @@ bool NixRepl::processLine(std::string line)
|
|||
runNix("nix-shell", {state->store->printStorePath(drvPath)});
|
||||
}
|
||||
|
||||
else if (command == ":b" || command == ":i" || command == ":s" || command == ":log") {
|
||||
else if (command == ":b" || command == ":bl" || command == ":i" || command == ":s" || command == ":log") {
|
||||
Value v;
|
||||
evalString(arg, v);
|
||||
StorePath drvPath = getDerivationPath(v);
|
||||
Path drvPathRaw = state->store->printStorePath(drvPath);
|
||||
|
||||
if (command == ":b") {
|
||||
if (command == ":b" || command == ":bl") {
|
||||
state->store->buildPaths({DerivedPath::Built{drvPath}});
|
||||
auto drv = state->store->readDerivation(drvPath);
|
||||
logger->cout("\nThis derivation produced the following outputs:");
|
||||
for (auto & [outputName, outputPath] : state->store->queryDerivationOutputMap(drvPath))
|
||||
logger->cout(" %s -> %s", outputName, state->store->printStorePath(outputPath));
|
||||
for (auto & [outputName, outputPath] : state->store->queryDerivationOutputMap(drvPath)) {
|
||||
auto localStore = state->store.dynamic_pointer_cast<LocalFSStore>();
|
||||
if (localStore && command == ":bl") {
|
||||
std::string symlink = "repl-result-" + outputName;
|
||||
localStore->addPermRoot(outputPath, absPath(symlink));
|
||||
logger->cout(" ./%s -> %s", symlink, state->store->printStorePath(outputPath));
|
||||
} else {
|
||||
logger->cout(" %s -> %s", outputName, state->store->printStorePath(outputPath));
|
||||
}
|
||||
}
|
||||
} else if (command == ":i") {
|
||||
runNix("nix-env", {"-i", drvPathRaw});
|
||||
} else if (command == ":log") {
|
||||
|
|
|
@ -1,29 +1,37 @@
|
|||
source common.sh
|
||||
|
||||
testDir="$PWD"
|
||||
cd "$TEST_ROOT"
|
||||
|
||||
replCmds="
|
||||
simple = 1
|
||||
simple = import ./simple.nix
|
||||
:b simple
|
||||
simple = import $testDir/simple.nix
|
||||
:bl simple
|
||||
:log simple
|
||||
"
|
||||
|
||||
replFailingCmds="
|
||||
failing = import ./simple-failing.nix
|
||||
failing = import $testDir/simple-failing.nix
|
||||
:b failing
|
||||
:log failing
|
||||
"
|
||||
|
||||
replUndefinedVariable="
|
||||
import ./undefined-variable.nix
|
||||
import $testDir/undefined-variable.nix
|
||||
"
|
||||
|
||||
testRepl () {
|
||||
local nixArgs=("$@")
|
||||
rm -rf repl-result-out || true # cleanup from other runs backed by a foreign nix store
|
||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replCmds")"
|
||||
echo "$replOutput"
|
||||
local outPath=$(echo "$replOutput" |&
|
||||
grep -o -E "$NIX_STORE_DIR/\w*-simple")
|
||||
nix path-info "${nixArgs[@]}" "$outPath"
|
||||
[ "$(realpath ./repl-result-out)" == "$outPath" ] || fail "nix repl :bl doesn't make a symlink"
|
||||
# run it again without checking the output to ensure the previously created symlink gets overwritten
|
||||
nix repl "${nixArgs[@]}" <<< "$replCmds" || fail "nix repl does not work twice with the same inputs"
|
||||
|
||||
# simple.nix prints a PATH during build
|
||||
echo "$replOutput" | grep -qs 'PATH=' || fail "nix repl :log doesn't output logs"
|
||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds" 2>&1)"
|
||||
|
|
Loading…
Reference in a new issue