[Nix-dev] variable scope / recursion
Lluís Batlle i Rossell
viric at viric.name
Fri Jul 6 14:45:49 CEST 2012
On Fri, Jul 06, 2012 at 02:25:25PM +0200, Mathijs Kwik wrote:
> 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.
I have a maybe similar use case. I use usernixos, and in usernixos I need to
pass pkgs, and I have some ovverrides I want to be used in it. I have some of my
overrides in a file apart (and my public old svn's configuration directory), and
I use them this way in my ~/nixpkgs/config.nix. That's not as nice as having all
recursively nice applied, of course.
let
mypkgs = import ./myconfigs/nixpkgs-overrides.nix;
in
{
usernixos = {pkgs, config, ...}: {
mercurialwsgi.all = {
destination = "/home/viric/public_html/wsgi-bin/hgweb.wsgi";
hgwebConfig = ''
[web]
motd = "Hello"
style = gitweb
[collections]
/home/viric/hg = /home/viric/hg
'';
};
.....
}
packageOverrides = pkgs : with pkgs;
(mypkgs pkgs) // rec {
usernixos = import ./usernixos { pkgs = pkgs // (mypkgs pkgs); };
# This will not be available to usernixos, but 'mypkgs' yes.
btarEnv = pkgs.myEnvFun {
name = "btar";
buildInputs = [ stdenv librsync ];
};
.....
};
}
(For my usernixos:
https://viric.name/cgi-bin/usernixos/timeline )
Regards,
Lluís.
More information about the nix-dev
mailing list