Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add example on haskellPackages overlay #44718

Closed
teto opened this issue Aug 8, 2018 · 7 comments
Closed

doc: add example on haskellPackages overlay #44718

teto opened this issue Aug 8, 2018 · 7 comments

Comments

@teto
Copy link
Member

teto commented Aug 8, 2018

Issue description

I would like to override some packages in haskellPackages but using overlays instead of the "old way" packageOverrides in config.nix
https://nixos.org/nixpkgs/manual/#how-to-override-package-versions-in-a-compiler-specific-package-set
I've searched the net for some time and am a bit confused at to what is best (extend/override)
#26561
Gabriella439/haskell-nix#53

what I've come up with is

self: prev:
  haskellPackages = prev.haskellPackages.override {
    overrides = hself: hsuper: rec {  
      cabal-helper = prev.haskell.lib.doJailbreak hsuper.cabal-helper;
    };
  };
}

but when in a nix repl, haskellPackages.cabal-helper.jailbreak won't exist. I would be very grateful to anyone sharing a working overlay.

It would be nice to have an overlay usage example in the nixpkgs manual too.

@ljli
Copy link
Contributor

ljli commented Aug 9, 2018

Your example is fine, there is a missing brace but that is inessential. You might have expected that the attribute at haskellPackages.cabal-helper.jailbreak exists because of the definition of doJailbreak but if you follow the definition of overrideCabal, you'll see that the jailbreak attribute ends up as an argument to the haskell builder defined in generic-builder.nix, it is not materialized as an attribute in the final derivation. To see that your overlay works you could compare the derivation hashes of the new and the old cabal-helper or you could inspect haskellPackages.cabal-helper.postPatch.

I would have written the example almost the same but composing with potential old overrides:

self: super: {
  haskellPackages = super.haskellPackages.override (oldArgs: {
    overrides =
      self.lib.composeExtensions (oldArgs.overrides or (_: _: {}))
        (hself: hsuper: {
          cabal-helper = self.haskell.lib.doJailbreak hsuper.cabal-helper;
        });
  });
}

@teto
Copy link
Member Author

teto commented Aug 9, 2018

Indeed running w/o overlay doesn't give the same result thanks. I now get

[ 7 of 12] Compiling CabalHelper.Shared.Common ( src/CabalHelper/Shared/Common.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/CabalHelper/Shared/Common.o )
[ 8 of 12] Compiling CabalHelper.Shared.InterfaceTypes ( src/CabalHelper/Shared/InterfaceTypes.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/CabalHelper/Shared/InterfaceTypes.o )
[ 9 of 12] Compiling CabalHelper.Shared.Sandbox ( src/CabalHelper/Shared/Sandbox.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/CabalHelper/Shared/Sandbox.o )
[10 of 12] Compiling Paths_cabal_helper ( dist/build/cabal-helper-wrapper/autogen/Paths_cabal_helper.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/Paths_cabal_helper.o )
[11 of 12] Compiling CabalHelper.Compiletime.Compile ( src/CabalHelper/Compiletime/Compile.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/CabalHelper/Compiletime/Compile.o )
[12 of 12] Compiling Main             ( src/CabalHelper/Compiletime/Wrapper.hs, dist/build/cabal-helper-wrapper/cabal-helper-wrapper-tmp/Main.o )

src/CabalHelper/Compiletime/Wrapper.hs:38:1: error:
    Could not find module ‘Distribution.PackageDescription.Parse’
    Perhaps you meant
      Distribution.PackageDescription.Parsec (from Cabal-2.2.0.1)
      Distribution.PackageDescription.Check (from Cabal-2.2.0.1)
      Distribution.PackageDescription.Quirks (from Cabal-2.2.0.1)
    Use -v to see a list of the files searched for.
   |
38 | import Distribution.PackageDescription.Parse (readPackageDescription)
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

but I will probably manage something.

Still hoping for the manual to be updated. Might do it once I get more confident with haskell.

@teto teto closed this as completed Aug 9, 2018
@ljli
Copy link
Contributor

ljli commented Aug 9, 2018

Jailbreaking a package means disregarding all versions bounds on the dependencies if you know or hope it will work anyway. I assume you are trying to build cabal-helper < 0.8.1 and because of the jailbreak Cabal >= 2.2 is used which doesn't have the Distribution.PackageDescription.Parse module anymore. I think there is a newer version for cabal-helper with support for the newest Cabal, so updating would be an option.

@teto
Copy link
Member Author

teto commented Aug 11, 2018

hum I've been - unsuccessfully - trying to use the latest cabal-helper as suggested: I tried asking on irc to no avail so trying here.

First I tried in shell.nix override-source and/or overrides

let
  pkgs = import <nixpkgs> { };

  drv = pkgs.haskellPackages.developPackage {
      root = ./.;

      # adding the problematic ghc-mod here
      modifier = drv:
      pkgs.haskell.lib.addBuildDepends drv (with pkgs.haskellPackages; [ 
          # hlint 
          ghc-mod
          # cabal-install
      ]);

      source-overrides =
      { # Use a specific hackage version
        # cabal-helper = "0.8.1.0"; # instead of the problematic 0.8.0.2

        # rev for "0.8.1.0";
        cabal-helper = pkgs.fetchFromGitHub  
          { owner = "DanielG";
            repo = "cabal-helper";
          rev    = "e2a41086c2b044f4d9c1276a920bba8e3eeb501c";
          sha256 = "0b3qahifb42vx0s0h43lqznmykmgii268jc2d0rc7l6haiq610kd";

          };
      };

      overrides = self: super:
      { # Don't run a package's test suite


      };

    };
in
  drv

then I tried via the overlay

self: prev:
{

  haskell = prev.haskell // {
    packageOverrides = hself: hsuper: rec {  

      cabal-helper = hsuper.callCabal2nix "cabal-helper" (prev.fetchFromGitHub {
        owner  = "DanielG";
        repo   = "cabal-helper";
          rev    = "e2a41086c2b044f4d9c1276a920bba8e3eeb501c";
          sha256 = "0b3qahifb42vx0s0h43lqznmykmgii268jc2d0rc7l6haiq610kd";

      }) {};
    };

  };
}

yet always "0.8.0.2" gets chosen ?

these derivations will be built:
  /nix/store/5fp73128n65fg4zjppl967s51q5zd5p3-cabal-plan-0.4.0.0.drv
  /nix/store/f9f57g6achgkawwlbga644hglmi3anlj-cabal-helper-0.8.0.2.drv

@ljli
Copy link
Contributor

ljli commented Aug 11, 2018

The commit rev you referenced is actually the parent of the release commit for 0.8.1.0, with the only missing thing being the version bump to 0.8.1.0, that could explain your observation.

@teto
Copy link
Member Author

teto commented Aug 11, 2018

Right I updated the revision/hash. Thanks for the help.
cabal-helper is completely ignored when running the nix-shell but picked up when defined in overlay.

It then fails with

ignoring (possibly broken) abi-depends field for packages
unpacking sources
unpacking source archive /nix/store/ld0yjihhlxfz0f7564c287i24jj38wfg-cabal-plan-0.4.0.0.tar.gz
source root is cabal-plan-0.4.0.0
setting SOURCE_DATE_EPOCH to timestamp 1532125614 of file cabal-plan-0.4.0.0/src-topograph/Topograph.hs
patching sources
applying patch /nix/store/0jy5jhk6nfv9a7hak94d0ibr2pxlnqbl-16.patch
patching file cabal-plan.cabal
Hunk #1 FAILED at 93.
1 out of 1 hunk FAILED -- saving rejects to file cabal-plan.cabal.rej
note: keeping build directory '/tmp/nix-build-cabal-plan-0.4.0.0.drv-13'

Where does the patch come from ? it doesn't appear in hackage-packages.nix definition of cabal-plan.

@ljli
Copy link
Contributor

ljli commented Aug 11, 2018

I think from here:

cabal-plan = appendPatch super.cabal-plan (pkgs.fetchpatch {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants