[Nix-dev] variable scope / recursion
Mathijs Kwik
mathijs at bluescreen303.nl
Fri Jul 6 15:01:32 CEST 2012
On Fri, Jul 6, 2012 at 2:45 PM, Lluís Batlle i Rossell <viric at viric.name> wrote:
> 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 ];
> };
> .....
> };
> }
>
Seems similar indeed. Basically what I'm trying to achieve has to do
with user environments as well, passing pre-defined package sets, to
nix-env. In the end I want users to be able to write a simple nix
expression for an "application" (mostly web apps / node js / snap /
rails), leading to a derivation with the source code, database config,
ssl config, monit config, cronjobs and a simple startup-script to
activate these.
so I think I should have a look at usernixos some time soon =)
But I'm not just looking for a solution, I prefer learning a lot along the way.
I'm gonna try a different solution now though. With the new NIX_PATH
stuff, I can probably just create my own package collection and make
it available as <mynixpkgs> and have that import/extend <nixpkgs>.
>
> (For my usernixos:
> https://viric.name/cgi-bin/usernixos/timeline )
>
> Regards,
> Lluís.
More information about the nix-dev
mailing list