lix/tests/functional/impure-eval.sh
eldritch horrors fb76a4d335 libcmd: munge evalSettings in the right place
these must be tampered with before the evaluator is created, *never*
after. doing it any other way leads to interesting things like #596.

fixes #596

Change-Id: Iea253ccce44b94b1243833837a3df93c795967d9
2024-12-06 00:59:53 +01:00

39 lines
1.2 KiB
Bash

source common.sh
export REMOTE_STORE="dummy://"
simpleTest () {
local expr=$1; shift
local result=$1; shift
# rest, extra args
[[ "$(nix eval --impure --raw "$@" --expr "$expr")" == "$result" ]]
}
# `builtins.storeDir`
## Store dir follows `store` store setting
simpleTest 'builtins.storeDir' '/foo' --store "$REMOTE_STORE?store=/foo"
simpleTest 'builtins.storeDir' '/bar' --store "$REMOTE_STORE?store=/bar"
# `builtins.currentSystem`
## `system` alone affects by default
simpleTest 'builtins.currentSystem' 'foo' --system 'foo'
simpleTest 'builtins.currentSystem' 'bar' --system 'bar'
## `system` affects if `eval-system` is an empty string
simpleTest 'builtins.currentSystem' 'foo' --system 'foo' --eval-system ''
simpleTest 'builtins.currentSystem' 'bar' --system 'bar' --eval-system ''
## `eval-system` alone affects
simpleTest 'builtins.currentSystem' 'foo' --eval-system 'foo'
simpleTest 'builtins.currentSystem' 'bar' --eval-system 'bar'
## `eval-system` overrides `system`
simpleTest 'builtins.currentSystem' 'bar' --system 'foo' --eval-system 'bar'
simpleTest 'builtins.currentSystem' 'baz' --system 'foo' --eval-system 'baz'
## `-f` honors nix-path
[ "$(nix eval --option nix-path "foo=$PWD" -f '<foo/eval.nix>' attr.foo)" = '"bar"' ]