aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-19 20:36:33 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-04-19 20:36:33 -0400
commite26662709e4f458e0916d43a613d44b174ad4679 (patch)
tree92744f40e38d746b298395c7c1907620a6a00a44 /tests
parentf3a31b14db6629ec424f31842157e6f614231bcd (diff)
Add a more interesting test
In this one, we don't just output an existing derivation as is, but modify it first.
Diffstat (limited to 'tests')
-rw-r--r--tests/dyn-drv/recursive-mod-json.nix33
-rw-r--r--tests/dyn-drv/recursive-mod-json.sh25
-rw-r--r--tests/local.mk1
-rw-r--r--tests/recursive.sh6
4 files changed, 62 insertions, 3 deletions
diff --git a/tests/dyn-drv/recursive-mod-json.nix b/tests/dyn-drv/recursive-mod-json.nix
new file mode 100644
index 000000000..9b32c55e9
--- /dev/null
+++ b/tests/dyn-drv/recursive-mod-json.nix
@@ -0,0 +1,33 @@
+with import ./config.nix;
+
+let innerName = "foo"; in
+
+mkDerivation rec {
+ name = "${innerName}.drv";
+ SHELL = shell;
+
+ requiredSystemFeatures = [ "recursive-nix" ];
+
+ drv = builtins.unsafeDiscardOutputDependency (import ./text-hashed-output.nix).root.drvPath;
+
+ buildCommand = ''
+ export NIX_CONFIG='experimental-features = nix-command ca-derivations'
+
+ PATH=${builtins.getEnv "EXTRA_PATH"}:$PATH
+
+ # JSON of pre-existing drv
+ nix derivation show $drv | jq .[] > drv0.json
+
+ # Fix name
+ jq < drv0.json '.name = "${innerName}"' > drv1.json
+
+ # Extend `buildCommand`
+ jq < drv1.json '.env.buildCommand += "echo \"I am alive!\" >> $out/hello\n"' > drv0.json
+
+ # Used as our output
+ cp $(nix derivation add < drv0.json) $out
+ '';
+ __contentAddressed = true;
+ outputHashMode = "text";
+ outputHashAlgo = "sha256";
+}
diff --git a/tests/dyn-drv/recursive-mod-json.sh b/tests/dyn-drv/recursive-mod-json.sh
new file mode 100644
index 000000000..070c5c2cb
--- /dev/null
+++ b/tests/dyn-drv/recursive-mod-json.sh
@@ -0,0 +1,25 @@
+source common.sh
+
+# FIXME
+if [[ $(uname) != Linux ]]; then skipTest "Not running Linux"; fi
+
+enableFeatures 'recursive-nix'
+restartDaemon
+
+clearStore
+
+rm -f $TEST_ROOT/result
+
+EXTRA_PATH=$(dirname $(type -p nix)):$(dirname $(type -p jq))
+export EXTRA_PATH
+
+# Will produce a drv
+metaDrv=$(nix-instantiate ./recursive-mod-json.nix)
+
+# computed "dynamic" derivation
+drv=$(nix-store -r $metaDrv)
+
+# build that dyn drv
+res=$(nix-store -r $drv)
+
+grep 'I am alive!' $res/hello
diff --git a/tests/local.mk b/tests/local.mk
index d3467aac2..a3c2ef3d5 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -111,6 +111,7 @@ nix_tests = \
import-derivation.sh \
ca/import-derivation.sh \
dyn-drv/text-hashed-output.sh \
+ dyn-drv/recursive-mod-json.sh \
nix_path.sh \
case-hack.sh \
placeholders.sh \
diff --git a/tests/recursive.sh b/tests/recursive.sh
index 6335d44a5..27e1674ca 100644
--- a/tests/recursive.sh
+++ b/tests/recursive.sh
@@ -1,11 +1,11 @@
source common.sh
-sed -i 's/experimental-features .*/& recursive-nix/' "$NIX_CONF_DIR"/nix.conf
-restartDaemon
-
# FIXME
if [[ $(uname) != Linux ]]; then skipTest "Not running Linux"; fi
+enableFeatures 'recursive-nix'
+restartDaemon
+
clearStore
rm -f $TEST_ROOT/result