diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-08-17 15:12:54 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-08-17 17:19:32 +0200 |
commit | 22d6e31fc6a9de2ee424984e629ccd2e394ba512 (patch) | |
tree | 0c8ea6b2799583edf3597f7723883ba4c1655c7e /tests | |
parent | ac841a46797a91eaddb3e0ad193c505fc49da597 (diff) |
Add a mechanism for derivation attributes to reference the derivation's outputs
For example, you can now say:
configureFlags = "--prefix=${placeholder "out"} --includedir=${placeholder "dev"}";
The strings returned by the ‘placeholder’ builtin are replaced at
build time by the actual store paths corresponding to the specified
outputs.
Previously, you had to work around the inability to self-reference by doing stuff like:
preConfigure = ''
configureFlags+=" --prefix $out --includedir=$dev"
'';
or rely on ad-hoc variable interpolation semantics in Autoconf or Make
(e.g. --prefix=\$(out)), which doesn't always work.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/config.nix | 2 | ||||
-rw-r--r-- | tests/local.mk | 3 | ||||
-rw-r--r-- | tests/placeholders.sh | 22 |
3 files changed, 25 insertions, 2 deletions
diff --git a/tests/config.nix b/tests/config.nix index 6244a15fa..76388fdd5 100644 --- a/tests/config.nix +++ b/tests/config.nix @@ -13,7 +13,7 @@ rec { derivation ({ inherit system; builder = shell; - args = ["-e" args.builder]; + args = ["-e" args.builder or (builtins.toFile "builder.sh" "eval \"$buildCommand\"")]; PATH = path; } // removeAttrs args ["builder" "meta"]) // { meta = args.meta or {}; }; diff --git a/tests/local.mk b/tests/local.mk index 1e5439f06..2ca52144b 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -10,7 +10,8 @@ nix_tests = \ timeout.sh secure-drv-outputs.sh nix-channel.sh \ multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \ binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \ - check-reqs.sh pass-as-file.sh tarball.sh restricted.sh + check-reqs.sh pass-as-file.sh tarball.sh restricted.sh \ + placeholders.sh # parallel.sh install-tests += $(foreach x, $(nix_tests), tests/$(x)) diff --git a/tests/placeholders.sh b/tests/placeholders.sh new file mode 100644 index 000000000..071cfe2dc --- /dev/null +++ b/tests/placeholders.sh @@ -0,0 +1,22 @@ +source common.sh + +clearStore + +nix-build --no-out-link -E ' + with import ./config.nix; + + mkDerivation { + name = "placeholders"; + outputs = [ "out" "bin" "dev" ]; + buildCommand = " + echo foo1 > $out + echo foo2 > $bin + echo foo3 > $dev + [[ $(cat ${placeholder "out"}) = foo1 ]] + [[ $(cat ${placeholder "bin"}) = foo2 ]] + [[ $(cat ${placeholder "dev"}) = foo3 ]] + "; + } +' + +echo XYZZY |