[Nix-dev] An issue regarding the default parameters of a function

Shea Levy shea at shealevy.com
Fri Feb 12 14:22:48 CET 2016


This is intentional: @-capture captures what was actually passed. You 
can always do something like: let args_ = args // { buildDepends = 
args.buildDepends or buildDepends; } if you really need this behavior.

On 2016-02-12 06:11, Sergey Mironov wrote:
> Hi. I have an issue regarding the combination of two Nix features:
> default parameters ( f = {arg ? def } : ...) and arbitrary length
> parameters (f = args@{arg, ...} : ...). It looks like they doesn't
> work together silently. Here is the example from my code. I'd like 
> the
> function make-nk-parser to tweak some of it's arguments and pass them
> downstream to the makeHaskell function. In particular, I want it to
> add 'nk' to the list of dependencies or make it the only dependency.
>
>
>     make-nk-parser = args@{buildDepends ? [], ...} :
>         makeHaskell (args // {
>             pname = "nk-parser";
>             buildDepends = args.buildDepends ++ [nk];
>             isExecutable = true;
>         });
>
> Unfortunately, this code doesn't work. I call make-nk-parser with
> empty arguments and Nix errors with "error: attribute ‘buildDepends’
> missing" near the args.buildDepends. In contrast, the following
> workaround works:
>
>     make-nk-parser = args@{...} :
>         let
>             buildDepends = if args ? buildDepends then
> args.buildDepends else [];
>         in
>         makeHaskell (args // {
>             pname = "nk-parser";
>             buildDepends = buildDepends ++ [nk];
>             isExecutable = true;
>         });
>
> Is it a known bug or feature?
>
> Regards,
> Sergey
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev



More information about the nix-dev mailing list