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

haskell: Overriding compiler causes duplicate GHCs on PATH #101580

Open
nh2 opened this issue Oct 24, 2020 · 4 comments
Open

haskell: Overriding compiler causes duplicate GHCs on PATH #101580

nh2 opened this issue Oct 24, 2020 · 4 comments
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: haskell

Comments

@nh2
Copy link
Contributor

nh2 commented Oct 24, 2020

If you use haskell.packages.ghc*.override { ghc = ... } then contrary to expectations, not only the overridden GHC will be on PATH for the build, but the un-overriden one as well, which can cause the wrong one to be picked sometimes.

See https://discourse.nixos.org/t/patching-ghc-for-your-project/9614/3?u=nh2

Steps to reproduce

Clone nixpkgs, inside create a file duplicate-ghcs.nix with contents:

let
  pkgs = import <nixpkgs> {};
in
  (pkgs.haskell.packages.ghc865.override (oldHaskellPackages: {
    ghc = pkgs.haskell.compiler.ghc865.overrideAttrs (old: {
      # x = 1;
    });
  })).dhall

Run nix-store -qR $(NIX_PATH=nixpkgs=. nix-instantiate duplicate-ghcs.nix) | grep ghc-8.6.5, you'll see 1 GHC in use (good):

/nix/store/my6xd0w33sll8ll68zyz9ppdzkvipxr7-ghc-8.6.5-src.tar.xz.drv
/nix/store/qa84fajzb5iygzgpcfz87zh971zwic48-ghc-8.6.5.drv

Then comment in the override:

-# x = 1;
+x = 1;

Now nix-store -qR $(NIX_PATH=nixpkgs=. nix-instantiate duplicate-ghcs.nix) | grep ghc-8.6.5, shows 2 GHCs in use (bad):

/nix/store/my6xd0w33sll8ll68zyz9ppdzkvipxr7-ghc-8.6.5-src.tar.xz.drv
/nix/store/qa84fajzb5iygzgpcfz87zh971zwic48-ghc-8.6.5.drv
/nix/store/yaxj0rwpys9iyh7z2am59z216dg89pb1-ghc-8.6.5.drv

Tested on 20.03 and current nixpkgs master commit 579daed.

CC @peti

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/patching-ghc-for-your-project/9614/4

@nh2
Copy link
Contributor Author

nh2 commented Oct 24, 2020

When I nix-diff the 2 outputs of nix-instantiate, I also see this:

% nix-diff /nix/store/7jzms1m8d8z1bccdfjf1cx073a6xcsa6-dhall-1.32.0.drv /nix/store/h4b3jdqs5na8ccq20zyp15hcj8kyb0p7-dhall-1.32.0.drv
- /nix/store/7jzms1m8d8z1bccdfjf1cx073a6xcsa6-dhall-1.32.0.drv:{out}
+ /nix/store/h4b3jdqs5na8ccq20zyp15hcj8kyb0p7-dhall-1.32.0.drv:{out}
• The input named `Diff-0.4.0` differs
  - /nix/store/65sl8crlgvixcl0if8gp1gl1vfw0fi28-Diff-0.4.0.drv:{out}
  + /nix/store/bxspshdcbi9vxx0id80zkxh2hkmvfc6k-Diff-0.4.0.drv:{out}
  • The set of inputs named `ghc-8.6.5` do not match
      + /nix/store/yaxj0rwpys9iyh7z2am59z216dg89pb1-ghc-8.6.5.drv:{out}
  • The environments do not match:

I find it weird that I only get a + in here:

  • The set of inputs named `ghc-8.6.5` do not match
      + /nix/store/yaxj0rwpys9iyh7z2am59z216dg89pb1-ghc-8.6.5.drv:{out}

instead of a - and a +.

@cdepillabout
Copy link
Member

cdepillabout commented Oct 25, 2020

My guess is that you need to override buildHaskellPackages in addition to ghc:

ghc865 = callPackage ../development/haskell-modules {
buildHaskellPackages = bh.packages.ghc865;
ghc = bh.compiler.ghc865;
compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-8.6.x.nix { };
};

I arrived at this guess by looking at the .drv file for dhall (well, actually I used the Diff package since it has less dependencies than dhall), and I saw that one GHC was pulled in by nativeBuildInputs, and the other GHC was pulled in by depsBuildBuild.

I don't know how things like buildPackages, targetPackages, etc work in nixpkgs (although I'd be really interested in learning about it if anyone knew any good resources), but I think that if you directly override the Haskell stuff in an overlay, buildHaskellPackages just gets overridden automatically.

The following derivation only references one GHC:

let
  myOverlay = final: prev: {
    haskell = prev.haskell // {
      packages = prev.haskell.packages // {
        ghc865 = prev.haskell.packages.ghc865.override {
          ghc = prev.haskell.compiler.ghc865.overrideAttrs (old: {
            x = 1;
          });
        };
      };
    };
  };

  # This is a checkout of nixpkgs at commit 598ffa1176.
  pkgs = import ~/git/nixpkgs {
    overlays = [ myOverlay ];
  };
in
  pkgs.haskell.packages.ghc865.Diff

@stale
Copy link

stale bot commented Apr 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: haskell
Projects
None yet
Development

No branches or pull requests

4 participants