[Nix-dev] Re: [PATCH] t/allow-arbitrary-strinsg-in-names

Marc Weber marco-oweber at gmx.de
Sat Jan 15 00:02:47 CET 2011


Excerpts from Yury G. Kudryashov's message of Fri Jan 14 21:28:18 +0100 2011:
> Marc Weber wrote:
> 
> > patch for nix allowing arbitrary strings as attr names still waiting for
> > review or comments.
> Is it possible to translate the following
> 
> rec {
>   foo_1_2 = {};
>   foo = foo_1_2;
> }
> 
> to use foo-1.2?

You're close::

    let x = rec {
      "foo.1.2" = {};
      str = "foo.1.2"; # << this is interpreted as string. [*]
    };
    in [ x."foo.1.2" x.str ]

yields

    [ {}  "foo.1.2" ]


This as an example of my usage. Its a convenient way to select attr
values based on a version using switch / match like style:


  { fetchurl, stdenv, qt4Support ? false, qt4, cairo, freetype, fontconfig, zlib,
    libjpeg, pixman, curl, libpthreadstubs, libXau, libXdmcp, openjpeg,
    libxml2, pkgconfig, glib, gtk, cmake, lcms
  , version ? "0.16.0"}:

  let

    homepage = http://poppler.freedesktop.org/;

    depsByVersion =  {

      # older version required by inkscape
      "0.14.5" = rec {
         name = "poppler-0.14.5";
         src = fetchurl {
           url = "${homepage}${name}.tar.gz";
           sha256 = "0k41cj0yp3l7854y1hlghn2cgqmqq6hw5iz8i84q0w0s9iy321f8";
         };
      };

      "0.16.0" = rec {
        name = "poppler-0.16.0";

        src = fetchurl {
          url = "${homepage}${name}.tar.gz";
          sha256 = "1b6505x1ynm7ffrgby2cavhgp65i8y0qz0wqpc73233ipm510gp9";
        };
      };

    };

    versionSpecific = stdenv.lib.maybeAttr version (throw "no valid poppler version") depsByVersion;

  in

  stdenv.mkDerivation ({

    // shared stuff

  } // versionSpecific )


Note: I know that you should take care about complexity. However very
often several versions have almost the same buildinputs. Creating each
time a new file / functions seems to be overkill to me. (I don't ask you
to share my point of view here).

I agree that this patch introduces a second meaning to "foo". However its
more intuitive than say using [foo-1.2] or `foo-1.2` or anything like
that (IMHO). Maybe even (foo-1.2) should be used? then the rec example
above would work ?
"foo" (=string) like) syntax is used in PHP, JS etc.

Marc Weber



More information about the nix-dev mailing list