Skip to content

Commit

Permalink
Make config.nix shims
Browse files Browse the repository at this point in the history
As requested in #11792 (comment)
  • Loading branch information
Ericson2314 committed Nov 6, 2024
1 parent e70c9bb commit f7591bc
Show file tree
Hide file tree
Showing 56 changed files with 49 additions and 77 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/build-hook-ca-fixed.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ busybox }:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/build-hook.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ busybox, contentAddressed ? false }:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let

Expand Down
2 changes: 2 additions & 0 deletions tests/functional/ca/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/ca/config.nix"
2 changes: 1 addition & 1 deletion tests/functional/ca/content-addressed.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/ca/nix-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion tests/functional/ca/nondeterministic.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ca/racy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/check-refs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/check-reqs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {
dep1 = mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/check.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{checkBuildId ? 0}:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

{
nondeterministic = mkDerivation {
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/chroot-store.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 0 additions & 9 deletions tests/functional/common/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions tests/functional/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix"
2 changes: 1 addition & 1 deletion tests/functional/dependencies.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ hashInvalidator ? "" }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let {

Expand Down
2 changes: 2 additions & 0 deletions tests/functional/dyn-drv/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Shim to get generated file
import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix"
2 changes: 1 addition & 1 deletion tests/functional/dyn-drv/old-daemon-error-hack.nix
Original file line number Diff line number Diff line change
@@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/dyn-drv/recursive-mod-json.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/dyn-drv/config.nix";
with import ./config.nix;

let innerName = "foo"; in

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/dyn-drv/text-hashed-output.nix
Original file line number Diff line number Diff line change
@@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/export-graph.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/extra-sandbox-profile.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ destFile, seed }:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "simple";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/failing.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ busybox }:
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
let

mkDerivation = args:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/filter-source.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "filter";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/fixed.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
3 changes: 0 additions & 3 deletions tests/functional/flakes/bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/functional/flakes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion tests/functional/flakes/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions tests/functional/flakes/develop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}: {
Expand Down
2 changes: 0 additions & 2 deletions tests/functional/flakes/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/fod-failing.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
rec {
x1 = mkDerivation {
name = "x1";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/gc-concurrent.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

{ lockFifo ? null }:

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/gc-runtime.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "gc-runtime";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/hermetic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/ifd.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
import (
mkDerivation {
name = "foo";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/import-from-derivation.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {
bar = mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/impure-derivations.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/impure-env.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ var, value }:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "test";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/linux-sandbox-cert-test.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ mode }:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation (
{
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/multiple-outputs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/nar-access.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {
a = mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/nix-build-examples.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/parallel.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{sleepTime ? 3}:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/path.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "filter";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/readfile-context.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let

Expand Down
4 changes: 0 additions & 4 deletions tests/functional/restricted.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=.
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/search.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

{
hello = mkDerivation rec {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/secure-drv-outputs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

{

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/shell-hello.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

rec {
hello = mkDerivation {
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/shell.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/simple-failing.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "simple-failing";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/simple.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

mkDerivation {
name = "simple";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/structured-attrs-shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;
let
dep = mkDerivation {
name = "dep";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/structured-attrs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

let

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/symlink-derivation.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/timeout.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

{

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/user-envs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{ foo ? "foo"
}:

with import "${builtins.getEnv "_NIX_TEST_BUILD_DIR"}/config.nix";
with import ./config.nix;

assert foo == "foo";

Expand Down

0 comments on commit f7591bc

Please sign in to comment.