[Nix-dev] example squidHead, I'd like to depreceate selectVersion.

Marc Weber marco-oweber at gmx.de
Sun Dec 21 18:04:08 CET 2008


I've removed the squidHead version by accident not knowing Michael
Raskin has been using it.

I've refactored the squid expression and I'd like to tell you about it
maybe even proposing this style for all small packages.
small means small .nix derivation files here:


selectVersion is nice but I don't like it because it's somewhat
cumbersome:
You can't easily install a zsh "cvs" version. You have to use package
overriding and edit your config.nix file adding these lines:

  packageOverrides = pkgs : {
    zsh = pkgs.zsh.passthru.function { version = "cvs"; };
  }

That's why I'd propose you switiching to this style


  squids = recurseIntoAttrs( import ../servers/squid/squids.nix {
    inherit fetchurl stdenv perl lib composableDerivation;
  });
  squid = squids.squid3Beta; # has ipv6 support


where

  squids = { 
    squid30 = <derivation>;
    squid3Beta = <derivation>;
    squid3Head = <derivation>;
  }

Then you can install a particular version using

  nix-env -iA squids.squid30
  without editing any config.

The squids file uses the fun-overriding implementation:

  args: with args;
  let edf = composableDerivation.edf; in
  rec {
    squid30 = composableDerivation.composableDerivation {
      initial = {
        name = "squid-3.0-stable5";

        buildInputs = [perl];

        src = args.fetchurl {
          url = http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE5.tar.bz2;
          sha256 = "1m4ccpjw30q9vwsycmgg9dmhly0mpznvxrch6f7dxgfzpjp26l7w";
        };

        configureFlags = ["--enable-ipv6"];

        meta = {
          description = "http-proxy";
          homepage = "http://www.squid-cache.org";
          license = "GPL2";
        };

      };
    };

    squid3Beta = squid30.passthru.funMerge {
      name = "squid-3.1-beta";
      src = args.fetchurl {
        url = http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.0.3.tar.bz2;
        sha256 = "0khc4w9sbdwzxw8285z60ymz15q5qjy7b8yvvfnzfkihdacs735x";
      };
      configureFlags = ["--enable-ipv6"];
    };

    squid3Head = squid3Beta.passthru.funMerge {
      name = "squid-3.1-HEAD";
      src = args.fetchurl {
        url = http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.0.3-20081221.tar.bz2;
        md5 = "345b50251dcc369e1be992d0a4a4c801";
      };
    };

    latest = squid3Beta;
  }

So i think it's minimal code and still nice to read?
I'm not sure wether it makes sense defining some special attr names such as

squids.default (default stable version)
squids.latest (beta, alpha, git, cvs or whatever unstable and maybe buggy version)

Any thoughts or comments?

Have I missed arguments pro selectVersion ?

Maybe that you don't have to write
  let version = "x.y"; in
  mkDerivation { .. }
because its added to args automatically when using selectVersion?

seleectVersion is fine if you install by name.. 
But who does so nowadays
because nix-env -A is much faster anyway?

If you select a version by selectVersion you may even break depending
packages.. How do you feel about that?

Example 

  a = selectVersion "3.0" (import ... );

  b = mkDerivation { buildInputs = [ a ]; };

If the users chooses 2.5 instead of 3.0 he may break b without knowing!

Alternative:

  as = { stable = ..; latest = ..; };
  a = as.stable;

  b = mkDerivation { buildInputs = [ (getConfig [ "b" "aVersion" ] a) ] };


Sincerly

Marc Weber



More information about the nix-dev mailing list