[Nix-dev] Referring to a path inside ${out}...in a nix expression
Marc Weber
marco-oweber at gmx.de
Tue Jun 26 01:03:19 CEST 2012
> stdenv.mkDerivation { .. } :
> {
> ...
> warfile = "${out}/repository/big/fat/path/geonetwork-opensource-2.6.4.war"
> ...
> }
You have to understand that you can't pass out as input to the same
derivation. Why?
All inputs yield a hash, the nix/store/xxxx hash.
Let's take a very simple example:
derivation = {
A = 7;
C = 8;
}
hash would be echo 'A=7;B=8' | md5sum (its more complicated, but this
example will work to make you understand).
635a3b176019f096630581a8ee3a263e
Now you want this:
derivation = {
A = 7;
C = 8;
D = "$HASH/some/path";
}
Thus
'A=7;B=8;D=$HASH/some/path' | md5sum
Thus the input to the hash function depends on the output of it - no
solution -> infinite recursion which is why nix can't provide $out the
way you want to use it.
If you grep nixpkgs for $out you'll find many cases. But they all use
$out in shell scripts only such as
preConfigure=''
configureFlags="--lib-path=$out/lib"
'';
which works because the shell script is run when $out is known
(obviously), but not at nix evaluation time.
What you really want is this workaround:
let X = derivation {
// your war file
}
in X // {
warfile = "${X}/some/path";
}
Thus you merge the warfile path after the derivation is complete (hash
has been calculated)
passthru is a very related special "attr name" which gets removed before
the derivation is created and merged back in a similar way, but it can't
depend on $out.
Seriously: Packaging maven/ivy/sbt/... like stuff for nix (would be great) - but is
insane at the moment because it would requiring making mvn and nix work
together nicely - and that would result in something like patching maven to
use the nix store to store "jar" files (shared cache) and build results
for it (kind of) - which in turn would mean mvn creating .nix files on
the fly (which would be possible) - but which would make it harder to
create .nix files in advance so that you can share them.
It probably would be possible - just nobody started this effort yet
(AFAIK).
Managing the transient dependencies in ivy would be .. lot's of fun :)
Don't get me wrong - I'd like be able to rebuild the same source with
different java/scala compilers easily - it will just take a lot of
dedication to get it done properly.
Good luck.
Marc Weber
More information about the nix-dev
mailing list