I have a derivation (default.nix
) defined as:
with import <nixpkgs> {};
let
version = "7.5.1";
in
stdenv.mkDerivation {
name = "gurobi-${version}";
src = fetchurl {
url = http://packages.gurobi.com/7.5/gurobi7.5.1_linux64.tar.gz;
sha256 = "7f5c8b0c3d3600ab7a1898f43e238a9d9a32ac1206f2917fb60be9bbb76111b6";
};
installPhase = ''
cp -R linux64 $out
patchelf --set-interpreter \
${stdenv.glibc}/lib/ld-linux-x86-64.so.2 $out/bin/*
patchelf --set-rpath ${stdenv.glibc}/lib $out/bin/*
'';
GUROBI_HOME = "$out";
}
Aside: even when I have cp -R linux64 $out/
, it seems the contents of linux64
are copied into $out
, rather than linux64
itself being copied into $out
... which seems non-standard, I think.
A second file (gurobi-shell.nix
) is:
with import <nixpkgs> {};
let
myGurobi = (import ./default.nix);
in stdenv.mkDerivation {
name = "gurobi-shell";
buildInputs = [ myGurobi ];
shellHook = ''
export GUROBI_HOME="${myGurobi.GUROBI_HOME}"
export GUROBI_PATH="${myGurobi.GUROBI_HOME}"
'';
}
When I run nix-shell gurobi-shell.nix
and then echo $GUROBI_HOME
, I get:
/nix/store/jsy0q02hyprz6mllblfb0gim3l8077d8-gurobi-shell
However, I expect and want it to be:
/nix/store/s2kj78cnpnnbwr6q8qylg0n02m0sm32a-gurobi-7.5.1
EDIT: I guess that this may have something to do with lazy evaluation, but am not sure. In any case, I found a workaround, which is to use myGurobi.out
instead of myGurobi.GUROBI_HOME
.