[Nix-dev] variable scope / recursion

Mathijs Kwik mathijs at bluescreen303.nl
Fri Jul 6 12:10:00 CEST 2012


On Fri, Jul 6, 2012 at 12:01 PM, Kirill Elagin <kirelagin at gmail.com> wrote:
> rec is the answer (this is something like let/letrec in Lisp, if you know
> what I mean ;) ).

I don't see how rec would help here.
As I understand it, rec helps when an attrset has attributes that
refer to each other.
But in this case, bar isn't referring to foo in the same object (the
overrides object I'm creating, containing just foo and bar), but to
pkgs.foo.

Anyway, I tried it anyway:
   packageOverrides = pkgs:
     rec { foo = "string";
       bar = pkgs.foo + " concatenation";
     };

But this does not help.
Still "missing attribute foo".


>
> --
> Кирилл Елагин
>
>
> 2012/7/6 Mathijs Kwik <mathijs at bluescreen303.nl>
>>
>> Hi all,
>>
>> I was reading this interesting piece of all-packages.nix
>> (comments/whitespace removed):
>>
>>   applyGlobalOverrides = overrider:
>>     let
>>       overrides = overrider pkgsOrig //
>>         (lib.optionalAttrs (pkgsOrig.stdenv ? overrides && crossSystem
>> == null) (pkgsOrig.stdenv.overrides pkgsOrig));
>>       pkgsOrig = pkgsFun pkgs {};
>>       pkgs = pkgsFun pkgs overrides;
>>     in pkgs;
>>
>> I'm familiar with tying-the-knot lazy trickery in haskell.
>> As pkgsOrig uses pkgs (the final end result including overrides), and
>> the overrider function gets passed pkgsOrig, I would expect the
>> following to work:
>>
>>   packageOverrides = pkgs:
>>     { foo = "string";
>>       bar = pkgs.foo + " concatenation";
>>     };
>>
>> However, it complains about foo missing.
>> What am I missing?
>>
>> Thanks,
>> Mathijs
>> _______________________________________________
>> 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