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/shell
/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/debugger-test-out
/tests/functional/test-libstoreconsumer/test-libstoreconsumer

View File

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

View File

@ -1,6 +1,6 @@
{ busybox, contentAddressed ? false }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
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 ({
__contentAddressed = true;

View File

@ -6,7 +6,4 @@ flakeDir="$TEST_HOME/flake"
mkdir -p "${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"

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 ({
__contentAddressed = true;

View File

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

View File

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

View File

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

View File

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

View File

@ -39,9 +39,6 @@ EOF
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
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 $#
}
# 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
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 ? "" }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
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.
# 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

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.
# 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 {

View File

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

View File

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

View File

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

View File

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

View File

@ -4,9 +4,6 @@ source common.sh
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"
cat <<EOF > flake.nix

View File

@ -35,9 +35,6 @@ writeSimpleFlake() {
EOF
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() {

View File

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

View File

@ -27,9 +27,6 @@ EOF
mkdir -p "$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"
{
outputs = {self}: {

View File

@ -8,8 +8,6 @@ clearStore
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
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
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 {
x1 = mkDerivation {
name = "x1";

View File

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

View File

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

View File

@ -5,7 +5,7 @@
, withFinalRefs ? false
}:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
let
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 (
mkDerivation {
name = "foo";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,10 +12,6 @@ mkdir -p "$TEST_ROOT/nix"
cp ./simple.nix "$TEST_ROOT/nix"
cp ./simple.builder.sh "$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"
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 {

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 {
hello = mkDerivation {

View File

@ -1,6 +1,6 @@
{ 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;
let

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
let
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"
}:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
assert foo == "foo";