[Nix-dev] Re: New proposal about expression syntax usage.

apfelmus apfelmus at quantentunnel.de
Wed Aug 15 14:35:39 CEST 2007


Michael Raskin schrieb:
> apfelmus wrote:
>> I'm not sure whether this is a good idea. The advantage of naming the
>> arguments explicitly like in
>>
>>  {stdenv, fetchurl, ncurses} : ...
>>
>> is that nix can check that these and only these arguments are passed to
>> the function. I.e. nix performs (does it?) a pattern match on the argument.
 >
> But it doesn't check that all of them are used anyway. So when you are
> editing a package it is easy to forget to add something to buildInputs
> etc. And not being able to pass extra arguments is not such a big plus
> per se.

Yes, lazy evaluation exactly means that there is no check whether the 
packages are actually used or not. But the pattern match does check 
whether the arguments are supplied at least (does it?), i.e. it's the 
compiler complains if you forgot to pass an argument to the function.

>>  buildInputs = toList args;
>>
>> Of course, this assumes that all arguments are derivations and not flags.
 >
> And this is not very good. Well, if we add some slow functions inside
> Nix (like uniqList) and replace big template.nix with a library function
> (like mkDerivation is), we will be able to just use it always and add a
> check that args contain no extra parameters.

It's also conceivable to have separate argument for packages and flags, 
i.e. something like

   foo = args@{stdenv, packages@{fetchurl, ncurses}, flags@{useBar}} : {
    ...
     buildInputs = toList packages;
   }

   foo {inherit stdenv; {inherit fetchurl, ncurses;}; { useBar = true };}

In fact, that could even be used to eliminate the duplication in 
all-packages.nix by recursively supplying the whole package set as 
argument, like in

   foo {inherit stdenv; all-packages; { useBar = true }; }

That now assumes that there is no check whether too many arguments have 
been passed. In fact, this is a bit dangerous since the pattern match 
for {fetchurl, ncurses} now has to filter the attribute set or the 
buildInputs  will be _all_ packages from  all-packages !

Regards,
apfelmus




More information about the nix-dev mailing list