aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-05-11 10:52:17 +0200
committerregnat <rg@regnat.ovh>2021-05-17 15:10:48 +0200
commitf46adb783c939c61a087cdfd8af964f4ad6f9816 (patch)
treec315dcfa20644d0d75b10ca844bce90548519a2f
parentf0c0052d4b16d13d2a826a2839b680b729651179 (diff)
Add a test for `nix run` with CA derivations
-rw-r--r--.gitignore1
l---------tests/ca/config.nix.in1
-rw-r--r--tests/ca/content-addressed.nix34
-rw-r--r--tests/ca/flake.nix3
-rwxr-xr-xtests/ca/nix-run.sh9
-rw-r--r--tests/local.mk5
6 files changed, 37 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 37aada307..2e14561fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -82,6 +82,7 @@ perl/Makefile.config
/tests/shell
/tests/shell.drv
/tests/config.nix
+/tests/ca/config.nix
# /tests/lang/
/tests/lang/*.out
diff --git a/tests/ca/config.nix.in b/tests/ca/config.nix.in
new file mode 120000
index 000000000..af24ddb30
--- /dev/null
+++ b/tests/ca/config.nix.in
@@ -0,0 +1 @@
+../config.nix.in \ No newline at end of file
diff --git a/tests/ca/content-addressed.nix b/tests/ca/content-addressed.nix
index e5b1c4de3..d328fc92c 100644
--- a/tests/ca/content-addressed.nix
+++ b/tests/ca/content-addressed.nix
@@ -1,4 +1,11 @@
-with import ../config.nix;
+with import ./config.nix;
+
+let mkCADerivation = args: mkDerivation ({
+ __contentAddressed = true;
+ outputHashMode = "recursive";
+ outputHashAlgo = "sha256";
+} // args);
+in
{ seed ? 0 }:
# A simple content-addressed derivation.
@@ -14,7 +21,7 @@ rec {
echo "Hello World" > $out/hello
'';
};
- rootCA = mkDerivation {
+ rootCA = mkCADerivation {
name = "rootCA";
outputs = [ "out" "dev" "foo"];
buildCommand = ''
@@ -27,11 +34,8 @@ rec {
ln -s $out $dev
ln -s $out $foo
'';
- __contentAddressed = true;
- outputHashMode = "recursive";
- outputHashAlgo = "sha256";
};
- dependentCA = mkDerivation {
+ dependentCA = mkCADerivation {
name = "dependent";
buildCommand = ''
echo "building a dependent derivation"
@@ -39,20 +43,14 @@ rec {
cat ${rootCA}/self/dep
echo ${rootCA}/self/dep > $out/dep
'';
- __contentAddressed = true;
- outputHashMode = "recursive";
- outputHashAlgo = "sha256";
};
- transitivelyDependentCA = mkDerivation {
+ transitivelyDependentCA = mkCADerivation {
name = "transitively-dependent";
buildCommand = ''
echo "building transitively-dependent"
cat ${dependentCA}/dep
echo ${dependentCA} > $out
'';
- __contentAddressed = true;
- outputHashMode = "recursive";
- outputHashAlgo = "sha256";
};
dependentNonCA = mkDerivation {
name = "dependent-non-ca";
@@ -72,6 +70,14 @@ rec {
cat ${dependentCA}/dep
echo foo > $out
'';
-
+ };
+ runnable = mkCADerivation rec {
+ name = "runnable-thing";
+ buildCommand = ''
+ mkdir -p $out/bin
+ echo ${rootCA} # Just to make it depend on it
+ echo "" > $out/bin/${name}
+ chmod +x $out/bin/${name}
+ '';
};
}
diff --git a/tests/ca/flake.nix b/tests/ca/flake.nix
new file mode 100644
index 000000000..332c92a67
--- /dev/null
+++ b/tests/ca/flake.nix
@@ -0,0 +1,3 @@
+{
+ outputs = { self }: import ./content-addressed.nix {};
+}
diff --git a/tests/ca/nix-run.sh b/tests/ca/nix-run.sh
new file mode 100755
index 000000000..81402af10
--- /dev/null
+++ b/tests/ca/nix-run.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+source common.sh
+
+sed -i 's/experimental-features .*/& ca-derivations ca-references nix-command flakes/' "$NIX_CONF_DIR"/nix.conf
+
+FLAKE_PATH=path:$PWD
+
+nix run --no-write-lock-file $FLAKE_PATH#runnable
diff --git a/tests/local.mk b/tests/local.mk
index e2c94dde6..542be6b7e 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -46,6 +46,7 @@ nix_tests = \
ca/build.sh \
ca/substitute.sh \
ca/signatures.sh \
+ ca/nix-run.sh \
ca/nix-copy.sh
# parallel.sh
@@ -53,6 +54,6 @@ install-tests += $(foreach x, $(nix_tests), tests/$(x))
tests-environment = NIX_REMOTE= $(bash) -e
-clean-files += $(d)/common.sh $(d)/config.nix
+clean-files += $(d)/common.sh $(d)/config.nix $(d)/ca/config.nix
-test-deps += tests/common.sh tests/config.nix tests/plugins/libplugintest.$(SO_EXT)
+test-deps += tests/common.sh tests/config.nix tests/ca/config.nix tests/plugins/libplugintest.$(SO_EXT)