mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-23 06:26:15 +02:00
159b5815b5
To quote Eelco in #5867: > Unfortunately we can't do > > evalSettings.pureEval.setDefault(false); > > because then we have to do the same in main.cc (where > pureEval is set to true), and that would allow pure-eval > to be disabled globally from nix.conf. Instead, a command should specify that it should be impure by default. Then, `evalSettings.pureEval` will be set to `false;` unless it's overridden by e.g. a CLI flag. In that case it's IMHO OK to be (theoretically) able to override `pure-eval` via `nix.conf` because it doesn't have an effect on commands where `forceImpureByDefault` returns `false` (i.e. everything where pure eval actually matters). Closes #5867
78 lines
2.2 KiB
Bash
78 lines
2.2 KiB
Bash
source common.sh
|
|
|
|
testDir="$PWD"
|
|
cd "$TEST_ROOT"
|
|
|
|
replCmds="
|
|
simple = 1
|
|
simple = import $testDir/simple.nix
|
|
:bl simple
|
|
:log simple
|
|
"
|
|
|
|
replFailingCmds="
|
|
failing = import $testDir/simple-failing.nix
|
|
:b failing
|
|
:log failing
|
|
"
|
|
|
|
replUndefinedVariable="
|
|
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)"
|
|
echo "$replOutput"
|
|
echo "$replOutput" | grep -qs 'This should fail' \
|
|
|| fail "nix repl :log doesn't output logs for a failed derivation"
|
|
local replOutput="$(nix repl --show-trace "${nixArgs[@]}" <<< "$replUndefinedVariable" 2>&1)"
|
|
echo "$replOutput"
|
|
echo "$replOutput" | grep -qs "while evaluating the file" \
|
|
|| fail "nix repl --show-trace doesn't show the trace"
|
|
|
|
nix repl "${nixArgs[@]}" --option pure-eval true 2>&1 <<< "builtins.currentSystem" \
|
|
| grep "attribute 'currentSystem' missing"
|
|
nix repl "${nixArgs[@]}" 2>&1 <<< "builtins.currentSystem" \
|
|
| grep "$(nix-instantiate --eval -E 'builtins.currentSystem')"
|
|
}
|
|
|
|
# Simple test, try building a drv
|
|
testRepl
|
|
# Same thing (kind-of), but with a remote store.
|
|
testRepl --store "$TEST_ROOT/store?real=$NIX_STORE_DIR"
|
|
|
|
testReplResponse () {
|
|
local response="$(nix repl <<< "$1")"
|
|
echo "$response" | grep -qs "$2" \
|
|
|| fail "repl command set:
|
|
|
|
$1
|
|
|
|
does not respond with:
|
|
|
|
$2
|
|
|
|
but with:
|
|
|
|
$response"
|
|
}
|
|
|
|
# :a uses the newest version of a symbol
|
|
testReplResponse '
|
|
:a { a = "1"; }
|
|
:a { a = "2"; }
|
|
"result: ${a}"
|
|
' "result: 2"
|