[Nix-dev] Howto add custom packages ? - would inherit *; be useful here?

Eelco Dolstra eelco at cs.uu.nl
Fri Apr 27 14:03:38 CEST 2007


Marc Weber wrote:

> This does'nt work with
> nix-env -aq '*'
> to list all packages (the mypackage and all from pkgs)
> 
> I'm looking for something like 
> ==
> with (import /pr/nix/nixsvn/trace/nixpkgs/trunk/pkgs/top-level/all-packages.nix {});
> rec {
>   mypackage = stdenv.mkDerivation {
>     name = "mypackage";
>   };
>   inherit transfig, ...;
>   # I'd like to do a inherit *;
> }
> 
> ... are all remeaning packages not listed yet but defined in
> all-packages.nix

You can use the "//" operator, which merges two attribute sets:

let pkgs = import /home/eelco/Dev/nixpkgs {}; in

pkgs // {

  test = pkgs.stdenv.mkDerivation {
    name = "test-1.2.3";
    buildCommand = "mkdir $out";
  };

}

(The "import /home/eelco/Dev/nixpkgs" is possible since yesterday, because
Nixpkgs now a "default.nix" in its root that just imports
pkgs/top-level/all-packages.nix.)

So this returns pkgs with the attribute "test" added:

$ nix-env -f foo.nix -qa \* | grep -C1 test
tcsh-6.14.00
test-1.2.3
tetex-3.0

You can also combine this with the "with" if you want:

let pkgs = import /home/eelco/Dev/nixpkgs {}; in

with pkgs;

pkgs // {

  test = stdenv.mkDerivation {
    name = "test-1.2.3";
    buildCommand = "mkdir $out";
  };

}

-- 
Eelco Dolstra | http://www.cs.uu.nl/~eelco



More information about the nix-dev mailing list