[Nix-dev] selectVersion

Marc Weber marco-oweber at gmx.de
Thu Jan 29 15:03:42 CET 2009


On Thu, Jan 29, 2009 at 02:24:03PM +0100, Eelco Dolstra wrote:
> Hi,
> 
> Can somebody explain what the use of selectVersion in all-packages.nix is?  It's
> full of calls like
> 
>   selectVersion ../tools/system/ddrescue "1.8"
> 
> which seems rather pointless to me, given that you can just as easily say
> "import ../tools/system/ddrescue/1.8.nix".  I propose a global search/replace to
> get rid of them...

He Eelco!

You've missed a small detail
I'm laughing now because I remember your statement on irc about all
those different ways which exist to write derivations :-)

To make the story short: definition of selectVersion:

  # Call a specific version of a Nix expression, that is,
  # `selectVersion ./foo {version = "0.1.2"; args...}' evaluates to
  # `import ./foo/0.1.2.nix args'.
  selectVersion = dir: defVersion: args:
    let
      pVersion =
        if (args ? version && args.version != "") then
          args.version
        else
          getConfig [ (baseNameOf (toString dir)) "version" ] defVersion;
    in
      import (dir + "/${pVersion}.nix") (args // { version = pVersion;
  });


you can use it this way to override the version selection:

  fooFun args = selectVersion ../tools/system/ddrescue "1.8" args ;

  # selects "1.8"
  foo = foo { inherit:  stdenv ... };

  # 1.8 is overridden by "newer":
  fooNewer = foo { version = "newer"; inherit  stdenv ...};


Also have a look at my post (title = "[Nix-dev] example squidHead, I'd like to depreceate selectVersion.")
http://article.gmane.org/gmane.linux.distributions.nixos/1344/match=selectVersion

If we are at it: Things like this would become more easy if we allowed
any string as attr
{
  "package-2.10" = ...;
  "package-3.20" = ...;
}


Sincerly
Marc Weber



More information about the nix-dev mailing list