[Nix-dev] libs and static libs?

Nicolas Pierron nicolas.b.pierron at gmail.com
Mon Oct 26 17:02:47 CET 2009


Hi Marc,

On Mon, Oct 26, 2009 at 08:28, Marc Weber <marco-oweber at gmx.de> wrote:
> A much nicer way is this:
>
> {fetchurl, stdenv, static ? true}:
> stdenv.mkDerivation ((rec {
>  name = "fcgi-2.4.0";
>
>  [..]
> }) // (if static then { dontDisableStatic=1; configureFlags="--enable-static"; } else {} ))

stdenv.lib.optionalAttr static { dontDisableStatic=1;
configureFlags="--enable-static"; }

> Then you can use mkOverride and .override { static = true; } to get
> static libraries.

indeed, but this implies that you add a lot of static arguments, a
nicer way would be to not have this flag on the package.

> Can you think of a sane more general way implementing this?

Yes.

One possible way is to extend derivations by adding custom derivation inside it.

addVariationsInStdenv = default: stdenv: pkgs: stdenv // {
  mkDerivation = args:
    let
      variations =  {
        shared = stdenv.mkDerivation args;
        static = (makeStaticBinaries stdenv).mkDerivation args;
        staticKlibc = (useKlibc stdenv pkgs.klibc).mkDerivation args;
        staticDietLibC = (useDietLibC stdenv).mkDerivation args;
      };
    in
      variations."${default}" // variations;
};

Thus all packages will use the default variation (could be "shared" or
"static") and you can access others by adding the variation type at
the end of the derivation:

# returns the default variation
pkgs.mysql

# return the static variation
pkgs.mysql.static

This avoid duplicating code and this would be added in all
derivations.  In addition this code should not change the default hash
of the shared versions which are already compiled.  So this could be
added safely in the mainline (use
nixpkgs/maintainers/scripts/rebuild-amount.sh to ensure that before
committing)

Cheers,

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/
If you are doing something twice then you should try to do it once.



More information about the nix-dev mailing list