[Nix-dev] Howto resolving dependencies automatically but much faster ?

Marc Weber marco-oweber at gmx.de
Wed Dec 16 23:50:22 CET 2009


> Resolution of Hackage dependencies sounds like something that shouldn't be done
> in Nix, but in the script that generates the Nix expressions from Hackage.

Example:

               TARGET1                            TARGET2                 
                  |    \                             |    \               
                libA    libC (< 1.0)             libA    libC (>= 1.0) 
                  |                                  |                    
                libC (< 2.0)                      libC (< 2.0)          



Now you can see if you satisfy the dependencies of TARGET1 you won't be
able to build TARGET2 because you already built libA depending on
libC < 1.0. But TARGET2 requires libC >= 1.0.

Building TARGET1 using different versions of libC can be done but is a
very bad idea. Worst case: segmentation fault.

How to solve this? you have to build libA two times:

rec {
  TARGET1 = { buildInputs = [ libA-built-for-TARGET1 libC-0.9 ] };
  TARGET2 = { buildInputs = [ libA-built-for-TARGET2 libC-1.5 ] };

  libA-built-for-TARGET1 = { buildInputs = [ libC-0.9 ]; }
  libA-built-for-TARGET2 = { buildInputs = [ libC-1.5 ]; }

  libC-0.9 = ..
  libC-1.5 = ..
}

However you can already see that this leads to a huge mess because we
talk about 5 packages only..

That's why the solver written in nix allows you to write something like:

TARGET1 = exe "TARGET1";

and be done. It will create
libA-built-for-TARGET{1,2} on the fly.

You can quickly select different versions:

TARGET1base3 = exe "TARGET1" { constraints = { base < 4  } };
TARGET1base4 = exe "TARGET1" { constraints = { base >= 4 } };

where exe is function calculating dependencies for TARGET1 only.

You're right that gentoo, archlinux and debian try to do what you
propose. However this doesn't satisfy all dev needs you might have.


So porting hackage to Nix in a sane and complete way is still work in
progress.

For darcs I already chose to ask darcs dev to make darcs compile with
most recent versions of packages. But I can't patch all packages on
hackage!

Today there was a mail on mailinglist about darcs:
 * lower base requirement down to base-2
 At least ghc-6.6.1 is able to build it without problems.

Thus some people still care about older versions.

That's why a static image of hackage will never ever work for me.

I even patched cabal to create .nix files. But for the reasons shown
above I abondoned that route..

Anyway: implementing such a feature is much more fun if you have more
type constraints..

I probably have to optimize the implementation in any case skipping
branches which were tried before.

Marcs Weber



More information about the nix-dev mailing list