[Nix-dev] [haskell NG] Override package
Kirill Elagin
kirelagin at gmail.com
Wed Feb 18 19:56:09 CET 2015
There are multiple ways to override a package in haskell-ng. Personally I
use the most general one, that is `haskellngPackages.override`.
`haskellngPackages` is itself a function with default arguments provided in
`top-level/all-packages.nix`, but you can call `haskellngPackages.override`
passing it an attrset with arguments to override, and in our case we want
to override the `overrides` argument (huh), which is internally appended to
the haskell packages set. The `overrides` argument should be a function,
taking two arguments, `self` (the resulting set of haskell packages) and
`super` (the original set of haskell packages); and it should return the
attrset of new or overriden packages.
Inside of that attrset you might want to use `overrideCabal` to alter the
derivation.
Here is an example. That’s how I override the `hoq` package to use my local
git checkout with fixes I need:
~~~~~~~
{
<...>
packageOverrides = pkgs_: let pkgs = pkgs_.pkgs; in with pkgs; {
<...>
haskellngPackages = pkgs_.haskellngPackages.override {
overrides = self: super: {
hoq = haskell-ng.lib.overrideCabal super.hoq
(drv: {
src = fetchgit {
url = "/home/kirrun/proj/hoq";
rev = "dc78b0f9600163670a3bdd6259dbdd69acc63087";
sha256 =
"0v4mll94xkjfpw8dpdgdm71zmdmvbp64pn77yw8xzrczyn06q46l";
};
});
};
};
};
}
~~~~~
Here is how it works:
1. Is override the whole `haskellngPackages` using `packageOverrides` as
one does with all other (not necessariliy haskell-related) packages.
2. I use `pkgs` for the new `pkgs` and `pkgs_` for the original ones. This
is needed because `haskellngPackages` is defined using `haskellngPackages`
which causes infinite recursion otherwise.
3. I use `haskell-ng.lib.overrideCabal` to override the derivation of
`hoq`, which takes a function from the original derivation to the attrset
of attributes to replace. I replace ontly the `src` attribute.
Note that the net result is that the only thing changed in the derivation
is its `src` attribute. In case you want to do more intrusive changes it
_might_ (or, more likely, might not!) be easier to put together a brand new
derivation and just `callPackage` it.
On Mon Feb 16 2015 at 11:42:12 AM YCH <dontdieych at gmail.com> wrote:
> Hello,
>
> I'm very happily learning Haskell with nix-shell and haskell-ng
> environment. In
> comparison to previous 'haskell', there is no problem at all.
>
> But I've found problem that hdevtools does not see related build-depends
> options in cabal file.
>
> https://github.com/bitc/hdevtools/issues/38
>
> So I would try patched hdevtools from fork.
>
> https://github.com/maximkulkin/hdevtools
>
> Cloned, checked out proper branch. What is next step?
>
> I've read quite many document. Wiki, nix pills, ... . But I'm confused
> about
> so many different ways doing similar things. And I'm worried about
> haskell-ng
> specific things. There is already 'haskellngPackages.hdevtools'. So I
> should
> override using ~/hdevtools. I'll attach my current setup information.
>
> Arch Linux
> nix-unstable
>
> Thanks.
>
> ~~~
> $ nix-env -q
> cabal-install-1.22.0.0
> cabal2nix-2.0
> nix-1.8
> nox-0.0.1
>
> $ ls -1
> cis194.cabal
> HW01.hs
> HW02.hs
> LICENSE
> Main.hs
> Setup.hs
> shell.nix
> Test.hs
> ... snip ...
>
> $ cat cis194.cabal
>
> -- Initial cis194.cabal generated by cabal init. For further
> -- documentation, see http://haskell.org/cabal/users-guide/
>
> name: cis194
> version: 0.1.0.0
> -- synopsis:
> -- description:
> -- license:
> license-file: LICENSE
> author: dontdieych
> maintainer: dontdieych at gmail.com
> -- copyright:
> -- category:
> build-type: Simple
> -- extra-source-files:
> cabal-version: >=1.10
>
> library
> default-language: Haskell2010
> build-depends:
> base >=4.7 && <4.8
> , MissingH
> exposed-modules:
> HW01
> , HW02
>
> executable cis194
> default-language: Haskell2010
> main-is: Main.hs
> -- hs-source-dirs:
> -- other-modules:
> -- other-extensions:
> build-depends:
> base >=4.7 && <4.8
>
> test-suite test
> default-language: Haskell2010
> type: exitcode-stdio-1.0
> main-is: Test.hs
> build-depends:
> base >=4.7 && <4.8
> , tasty
> , tasty-th
> , tasty-quickcheck
> , tasty-rerun
> -- , QuickCheck
>
> $ cat shell.nix # cabal2nix . --shell > shell.nix
>
> with (import <nixpkgs> {}).pkgs;
> let pkg = haskellngPackages.callPackage
> ({ mkDerivation, base, MissingH, QuickCheck, stdenv, tasty
> , tasty-hunit, tasty-quickcheck, tasty-rerun, tasty-th
> }:
> mkDerivation {
> pname = "cis194";
> version = "0.1.0.0";
> src = ./.;
> isLibrary = false;
> isExecutable = true;
> buildDepends = [
> base MissingH QuickCheck tasty tasty-hunit
> tasty-quickcheck
> tasty-rerun tasty-th
> ];
> buildTools = [
> haskellngPackages.hdevtools # I've added this config.
> ];
> license = stdenv.lib.licenses.unfree;
> }) {};
> in
> pkg.env
>
> $ cat ../hdevtools/default.nix # via cabal2nix . > defult.nix
>
> { mkDerivation, base, Cabal, cmdargs, directory, filepath, ghc
> , ghc-paths, network, stdenv, syb, time, transformers, unix
> }:
> mkDerivation {
> pname = "hdevtools";
> version = "0.1.0.6";
> src = ./.;
> isLibrary = false;
> isExecutable = true;
> buildDepends = [
> base Cabal cmdargs directory filepath ghc ghc-paths network syb
> time transformers unix
> ];
> homepage = "https://github.com/bitc/hdevtools/";
> description = "Persistent GHC powered background server for FAST
> haskell development tools";
> license = stdenv.lib.licenses.mit;
> }
> ~~~
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20150218/24bfac44/attachment-0001.html
More information about the nix-dev
mailing list