[Nix-dev] Proper way of adding custom nix expressions
Andres Loeh
ksnix at andres-loeh.de
Thu Nov 1 08:14:53 CET 2012
Hi Richard.
What Peter says is true. And ultimately, you should be motivated to
just submit your new packages as a pull request to nixpkgs.
However, I'd like to point out that there's also a somewhat less
invasive way to test your own Haskell packages.
There's a nixpkgs configuration file at ~/.nixpkgs/config.nix (it
might not exist yet). In this config file you can specify a
configuration option called packageOverrides that modifies the package
set from nixpkgs in any way you like. In particular, you can add
packages. Now, adding something to the set of Haskell packages is a
little bit tricky, because they're all defined in a sub-attribute
depending on the compiler version, and you have to ensure that
dependencies are picked up correctly from that set.
So here's what you'd do to add the "boomerang" Haskell package.
(1) Call cabal2nix to produce a Nix expression for boomerang and put
it in a suitable location. I'm assuming
~/.nixpkgs/haskell/boomerang.nix.
(2) Edit your ~/.nixpkgs/config.nix so that it has the following structure:
> pkgs : {
> packageOverrides = pkgs : rec {
> myHaskellPackages =
> let callPackage = pkgs.lib.callPackageWith myHaskellPackages; in
> pkgs.recurseIntoAttrs (pkgs.haskellPackages.override {
> extraPrefs = self : {
> boomerang = callPackage ./haskell/boomerang.nix {};
> };
> });
> };
> }
Instead of pkgs.haskellPackages.override, you can select another set
of haskellPackages from all-packages.nix, one that's specific to your
compiler version, if you prefer. The pkgs.recurseIntoAttrs call is
optional, but it ensures that you can view your own new Haskell
packages in nix-env -q calls.
(3) You can now install boomerang via path
(nixos.pkgs.myHaskellPackages.boomerang) or you can use
myHaskellPackages.ghcWithPackages to build a set of specific packages
for this version of GHC.
Cheers,
Andres
More information about the nix-dev
mailing list