[Nix-dev] variable scope / recursion

Mathijs Kwik mathijs at bluescreen303.nl
Fri Jul 6 14:25:25 CEST 2012


On Fri, Jul 6, 2012 at 2:12 PM, Marc Weber <marco-oweber at gmx.de> wrote:
> Excerpts from Mathijs Kwik's message of Fri Jul 06 11:53:28 +0200 2012:
>>   packageOverrides = pkgs:
>>     { foo = "string";
>>       bar = pkgs.foo + " concatenation";
>>     };
>
> solution a) use rec:
>
>
> (rec {
>   foo = ...
>   bar = foo
>   ;
> })


I'l make myself more clear... the example was simplified.
I want to do something like callPackage.

packageOverrides = pkgs:
{ myPackage1 = import ./my-package1 { inherit pkgs; };
  myPackage2 = import ./my-package2 { inherit pkgs; };
}

the expressions for myPackage1 and 2 need a "pkgs" argument which is
the full packages-tree, so the original one _and_ my extensions. So
myPackage2 wants to depend on myPackage1 and (for example) stdenv. Now
I can of course pass myPackage1 as explicit argument to myPackage2,
but I prefer to have a unified pkgs set.

so I can't use your solution.


>
> solution b,c )
>   use let recursion or fix function (which in turn can be implemented by
>   let recursion or such).
>
> second: read comments & code: pkgs is the original pkgs, not the patched one:
>
>   overrider pkgsOrig // ..

once again, I read the comments, that's why I asked this question in
the first place.
I know the comment text says it's the original/unmodified set, but if
you look at the code you see:

pkgsOrig = pkgsFun pkgs {};

in other words, pkgs (the final result) is fed to pkgsFun, so pkgsOrig
should have every attribute in it, that the final result has.
If not, can you please explain to me _why_ this is not the case, not
just "the comment says so"?

>
> Then it should be clear wy foo is not known.

nope, it's in pkgs, which is in pkgsOrig

>
> Marc Weber
> _______________________________________________
> 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