Make config.nix shims

As requested in https://github.com/NixOS/nix/pull/11792#discussion_r1827034428
This commit is contained in:
John Ericson 2024-11-03 17:22:12 -05:00
parent e70c9bb06a
commit f7591bc6ed
56 changed files with 49 additions and 77 deletions

3
.gitignore vendored
View File

@ -102,9 +102,6 @@ perl/Makefile.config
/tests/functional/restricted-innocent /tests/functional/restricted-innocent
/tests/functional/shell /tests/functional/shell
/tests/functional/shell.drv /tests/functional/shell.drv
/tests/functional/config.nix
/tests/functional/ca/config.nix
/tests/functional/dyn-drv/config.nix
/tests/functional/repl-result-out /tests/functional/repl-result-out
/tests/functional/debugger-test-out /tests/functional/debugger-test-out
/tests/functional/test-libstoreconsumer/test-libstoreconsumer /tests/functional/test-libstoreconsumer/test-libstoreconsumer

View File

@ -1,6 +1,6 @@
{ busybox }: { busybox }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let

View File

@ -1,6 +1,6 @@
{ busybox, contentAddressed ? false }: { busybox, contentAddressed ? false }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let

View File

@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/ca/config.nix"

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/ca/config.nix"; with import ./config.nix;
let mkCADerivation = args: mkDerivation ({ let mkCADerivation = args: mkDerivation ({
__contentAddressed = true; __contentAddressed = true;

View File

@ -6,7 +6,4 @@ flakeDir="$TEST_HOME/flake"
mkdir -p "${flakeDir}" mkdir -p "${flakeDir}"
cp flake.nix "${_NIX_TEST_BUILD_DIR}/ca/config.nix" content-addressed.nix "${flakeDir}" cp flake.nix "${_NIX_TEST_BUILD_DIR}/ca/config.nix" content-addressed.nix "${flakeDir}"
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$flakeDir"/*.nix
nix run --no-write-lock-file "path:${flakeDir}#runnable" nix run --no-write-lock-file "path:${flakeDir}#runnable"

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/ca/config.nix"; with import ./config.nix;
let mkCADerivation = args: mkDerivation ({ let mkCADerivation = args: mkDerivation ({
__contentAddressed = true; __contentAddressed = true;

View File

@ -2,7 +2,7 @@
# build it at once. # build it at once.
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/ca/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "simple"; name = "simple";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {
dep1 = mkDerivation { dep1 = mkDerivation {

View File

@ -1,6 +1,6 @@
{checkBuildId ? 0}: {checkBuildId ? 0}:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
{ {
nondeterministic = mkDerivation { nondeterministic = mkDerivation {

View File

@ -39,9 +39,6 @@ EOF
cp simple.nix shell.nix simple.builder.sh "${config_nix}" "$flakeDir/" cp simple.nix shell.nix simple.builder.sh "${config_nix}" "$flakeDir/"
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$flakeDir"/*.nix
TODO_NixOS TODO_NixOS
outPath=$(nix build --print-out-paths --no-link --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' --store "$TEST_ROOT/x" path:"$flakeDir") outPath=$(nix build --print-out-paths --no-link --sandbox-paths '/nix? /bin? /lib? /lib64? /usr?' --store "$TEST_ROOT/x" path:"$flakeDir")

View File

@ -343,15 +343,6 @@ count() {
echo $# echo $#
} }
# Sometimes, e.g. due to pure eval, restricted eval, or sandboxing, we
# cannot look up `config.nix` in the build dir, and have to instead get
# it from the current directory. (In this case, the current directly
# will be somewhere in `$TEST_ROOT`.)
removeBuildDirRef() {
# shellcheck disable=SC2016 # The ${} in this is Nix, not shell
sed -i -e 's,"${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/[^ ]*config.nix",./config.nix,' "$@"
}
trap onError ERR trap onError ERR
fi # COMMON_FUNCTIONS_SH_SOURCED fi # COMMON_FUNCTIONS_SH_SOURCED

View File

@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"

View File

@ -1,5 +1,5 @@
{ hashInvalidator ? "" }: { hashInvalidator ? "" }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let { let {

View File

@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix"

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix"; with import ./config.nix;
# A simple content-addressed derivation. # A simple content-addressed derivation.
# The derivation can be arbitrarily modified by passing a different `seed`, # The derivation can be arbitrarily modified by passing a different `seed`,

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix"; with import ./config.nix;
let innerName = "foo"; in let innerName = "foo"; in

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix"; with import ./config.nix;
# A simple content-addressed derivation. # A simple content-addressed derivation.
# The derivation can be arbitrarily modified by passing a different `seed`, # The derivation can be arbitrarily modified by passing a different `seed`,

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -1,6 +1,6 @@
{ destFile, seed }: { destFile, seed }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "simple"; name = "simple";

View File

@ -1,5 +1,5 @@
{ busybox }: { busybox }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let
mkDerivation = args: mkDerivation = args:

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "filter"; name = "filter";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -4,9 +4,6 @@ source common.sh
cp ../simple.nix ../simple.builder.sh "${config_nix}" "$TEST_HOME" cp ../simple.nix ../simple.builder.sh "${config_nix}" "$TEST_HOME"
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$TEST_HOME"/*.nix
cd "$TEST_HOME" cd "$TEST_HOME"
cat <<EOF > flake.nix cat <<EOF > flake.nix

View File

@ -35,9 +35,6 @@ writeSimpleFlake() {
EOF EOF
cp ../simple.nix ../shell.nix ../simple.builder.sh "${config_nix}" "$flakeDir/" cp ../simple.nix ../shell.nix ../simple.builder.sh "${config_nix}" "$flakeDir/"
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$flakeDir"/*.nix
} }
createSimpleGitFlake() { createSimpleGitFlake() {

View File

@ -3,7 +3,6 @@
source common.sh source common.sh
cp ../simple.nix ../simple.builder.sh "${config_nix}" $TEST_HOME cp ../simple.nix ../simple.builder.sh "${config_nix}" $TEST_HOME
removeBuildDirRef "$TEST_HOME/simple.nix"
cd $TEST_HOME cd $TEST_HOME

View File

@ -27,9 +27,6 @@ EOF
mkdir -p "$TEST_HOME/nixpkgs" mkdir -p "$TEST_HOME/nixpkgs"
cp "${config_nix}" ../shell.nix "$TEST_HOME/nixpkgs" cp "${config_nix}" ../shell.nix "$TEST_HOME/nixpkgs"
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$TEST_HOME/nixpkgs"/*.nix
cat <<EOF >"$TEST_HOME/nixpkgs/flake.nix" cat <<EOF >"$TEST_HOME/nixpkgs/flake.nix"
{ {
outputs = {self}: { outputs = {self}: {

View File

@ -8,8 +8,6 @@ clearStore
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
cp ../shell-hello.nix "${config_nix}" $TEST_HOME cp ../shell-hello.nix "${config_nix}" $TEST_HOME
# `config.nix` cannot be gotten via build dir / env var (runs afoul pure eval). Instead get from flake.
removeBuildDirRef "$TEST_HOME"/*.nix
cd $TEST_HOME cd $TEST_HOME
cat <<EOF > flake.nix cat <<EOF > flake.nix

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {
x1 = mkDerivation { x1 = mkDerivation {
name = "x1"; name = "x1";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
{ lockFifo ? null }: { lockFifo ? null }:

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "gc-runtime"; name = "gc-runtime";

View File

@ -5,7 +5,7 @@
, withFinalRefs ? false , withFinalRefs ? false
}: }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let
contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1"; contentAddressedByDefault = builtins.getEnv "NIX_TESTS_CA_BY_DEFAULT" == "1";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
import ( import (
mkDerivation { mkDerivation {
name = "foo"; name = "foo";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {
bar = mkDerivation { bar = mkDerivation {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -1,6 +1,6 @@
{ var, value }: { var, value }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "test"; name = "test";

View File

@ -1,6 +1,6 @@
{ mode }: { mode }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation ( mkDerivation (
{ {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {
a = mkDerivation { a = mkDerivation {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {

View File

@ -1,6 +1,6 @@
{sleepTime ? 3}: {sleepTime ? 3}:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "filter"; name = "filter";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let

View File

@ -12,10 +12,6 @@ mkdir -p "$TEST_ROOT/nix"
cp ./simple.nix "$TEST_ROOT/nix" cp ./simple.nix "$TEST_ROOT/nix"
cp ./simple.builder.sh "$TEST_ROOT/nix" cp ./simple.builder.sh "$TEST_ROOT/nix"
cp "${config_nix}" "$TEST_ROOT/nix" cp "${config_nix}" "$TEST_ROOT/nix"
simple_nix="$TEST_ROOT/nix/simple.nix"
# N.B. redefine
config_nix="$TEST_ROOT/nix/config.nix"
removeBuildDirRef "${simple_nix}"
cd "$TEST_ROOT/nix" cd "$TEST_ROOT/nix"
nix-instantiate --restrict-eval ./simple.nix -I src=. nix-instantiate --restrict-eval ./simple.nix -I src=.

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
{ {
hello = mkDerivation rec { hello = mkDerivation rec {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
{ {

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
rec { rec {
hello = mkDerivation { hello = mkDerivation {

View File

@ -1,6 +1,6 @@
{ inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }: { inNixShell ? false, contentAddressed ? false, fooContents ? "foo" }:
let cfg = import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; in let cfg = import ./config.nix; in
with cfg; with cfg;
let let

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "simple-failing"; name = "simple-failing";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
mkDerivation { mkDerivation {
name = "simple"; name = "simple";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let
dep = mkDerivation { dep = mkDerivation {
name = "dep"; name = "dep";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
let let
foo_in_store = builtins.toFile "foo" "foo"; foo_in_store = builtins.toFile "foo" "foo";

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
{ {

View File

@ -2,7 +2,7 @@
{ foo ? "foo" { foo ? "foo"
}: }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"; with import ./config.nix;
assert foo == "foo"; assert foo == "foo";