[Nix-dev] different compiler versions at the same time ?

Eelco Dolstra eelco at cs.uu.nl
Mon Jun 4 13:19:48 CEST 2007


Hi,

Marc Weber wrote:

> How is this done using nix?
> 
> I think this applies to java/ python/ gcc as well.
> 
> Situation:
>   I want to test a library/ application and check wether I can compile
>   it with ghc-6.4, ghc-6.5 and ghc-6.6.

If you just want to test whether it builds, that's quite easy: you can make a
function that takes the desired ghc (and whatever other variations you want to
test) as an argument and builds the library.

Example: building Nix with different versions of the ATerm and Berkeley DB
dependencies:

  buildNix = aterm: db4: import ../tools/package-management/nix/unstable.nix {
    inherit fetchurl stdenv perl curl bzip2 openssl aterm db4;
  };

  nixTest = [
    (buildNix aterm db44)
    (buildNix aterm242fixes db44)
    (buildNix aterm db45)
    (buildNix aterm242fixes db45)
  ];

And an easy way to perform the test is to say

$ nix-build -f top-level/all-packages.nix -A nixTest

which will build all 4 variants and leave symlinks to them in the current directory:

$ ls -l result*
lrwxrwxrwx 1 eelco users 59 2007-06-04 12:35 result ->
/nix/store/3k65bf7wzznkcf2fkf1f41zvjkv1sh0b-nix-0.11pre8648
lrwxrwxrwx 1 eelco users 59 2007-06-04 12:35 result-2 ->
/nix/store/rbjnvp4yax93s8l9rgmrqms17f6bmsgx-nix-0.11pre8648
...

(I stuck nixTest in all-packages.nix because I'm lazy, usually you would put it
in a separate Nix expression.)

Note that all variants have the symbolic name nix-0.11pre8648, but that doesn't
matter if you don't want to install it.  If you *do* want to install them, then
you can give them different symbolic names for use in nix-env:

  nixTest = [
    (appendToName "with-aterm-2.4.2-db-4.4") (buildNix aterm db44))
    (appendToName "with-aterm-2.4.2-fixes-db-4.4") (buildNix aterm242fixes db44))
    ...

Also, there are various ways to disambiguate between packages with the same
symbolic name/version.  You can specify the absolute path of the desired
variant, if you know it ("nix-env -qa --out-path" shows it):

$ nix-env -i /nix/store/3k65bf7wzznkcf2fkf1f41zvjkv1sh0b-nix-0.11pre8648

Or use the attribute path (which is unambiguous):

$ nix-env -qaA zlib
zlibStatic  zlib-1.2.3
zlib        zlib-1.2.3

$ nix-env -i -A zlibStatic

-- 
Eelco Dolstra | http://www.cs.uu.nl/~eelco



More information about the nix-dev mailing list