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

Talk about how to use GHC-specific tools (e.g. ghc-mod) #30

Open
adelbertc opened this issue Sep 20, 2017 · 5 comments
Open

Talk about how to use GHC-specific tools (e.g. ghc-mod) #30

adelbertc opened this issue Sep 20, 2017 · 5 comments

Comments

@adelbertc
Copy link

Tools like ghc-mod, as far as I understand, need to be built with the same version of GHC as the project you intend to use it in. Curious how you handle it with the setup described in this tutorial.

@adelbertc adelbertc changed the title Talk about how to use GHC-specific tools Talk about how to use GHC-specific tools (e.g. ghc-mod) Sep 20, 2017
@Gabriella439
Copy link
Owner

I think this is as simple as adding ghc-mod to your record of project build products and then installing it

For example, if you had a project like this one from the tutorial:

let
  config = {
    packageOverrides = pkgs: rec {
      haskellPackages = pkgs.haskellPackages.override {
        overrides = haskellPackagesNew: haskellPackagesOld: rec {
          optparse-applicative =
            haskellPackagesNew.callPackage ./optparse-applicative-2.nix { };

          project1 =
            haskellPackagesNew.callPackage ./default.nix { };

          turtle =
            haskellPackagesNew.callPackage ./turtle.nix { };
        };
      };
    };
  };

  pkgs = import <nixpkgs> { inherit config; };

in
  { project1 = pkgs.haskellPackages.project1;
  }

... then I think you can just add ghc-mod to the output:

let
  config = {
    packageOverrides = pkgs: rec {
      haskellPackages = pkgs.haskellPackages.override {
        overrides = haskellPackagesNew: haskellPackagesOld: rec {
          optparse-applicative =
            haskellPackagesNew.callPackage ./optparse-applicative-2.nix { };

          project1 =
            haskellPackagesNew.callPackage ./default.nix { };

          turtle =
            haskellPackagesNew.callPackage ./turtle.nix { };
        };
      };
    };
  };

  pkgs = import <nixpkgs> { inherit config; };

in
  { project1 = pkgs.haskellPackages.project1;
    ghc-mod  = pkgs.haskellPackages.ghc-mod;
  }

... and then you can install the ghc-mod provided by your project by running:

$ nix-env --install --attr ghc-mod --file release.nix

@adelbertc: Could you try that out and let me know if it works for you? If it does, then I can add this to the tutorial

@adelbertc
Copy link
Author

Hmm wouldn't that globally install ghc-mod? For something like ghc-mod where the version of GHC it's compiled against matters, you'd want to do it on a per project basis right? At work we have it available once we drop into a project-specific shell.nix, curious how you would approach it.

@Gabriella439
Copy link
Owner

The problem is that nix-shell doesn't support loading multiple derivations from a release.nix file

@adelbertc
Copy link
Author

Right, so I guess if possible you would need a shell.nix that stays in sync with default.nix (ruling out cabal2nix --shell since the generated expression seems to largely duplicate default.nix) but also lets you add in tooling in buildDepends or buildTools or something?

@alpmestan
Copy link

Have you tried indeed simply adding ghc-mod to your buildDepends/buildTools? If not, you might want to verify that it allows you to have a working ghc-mod that's aware of your project. Then you can automate that by maybe overriding your project's derivation at the last minute, right before calling callPackage, by adding a buildDepends/buildTools entry. Anything that guarantees that ghc-mod will be built, with the same ghc version as everything else in the project, and that it ends up in your PATH.

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

No branches or pull requests

3 participants