haskell-nix icon indicating copy to clipboard operation
haskell-nix copied to clipboard

Development dependencies

Open jerbaroo opened this issue 4 years ago • 2 comments

Project 2 on Non-Haskell dependencies describes how to include a dependency of the Haskell application being built. However what about a dependency that is only required for development e.g. haskell-language-server, it should be possible to include that in release.nix somehow so it is available in a Nix shell.

jerbaroo avatar Jan 20 '21 19:01 jerbaroo

This is what I figured out can be done. Not sure if it's the best way to do things though.

let
  pkgs = import <nixpkgs> { };
  mypkg = pkgs.haskellPackages.callCabal2nix "mypkg" ./mypkg.cabal {};
  devTools = [ pkgs.haskell-language-server ];
in
  pkgs.lib.overrideDerivation mypkg.env (old: {
    buildInputs = old.buildInputs ++ devTools;
  })

jerbaroo avatar Jan 20 '21 20:01 jerbaroo

@jerbaroo: You can use pkgs.mkShell, which comes in handy for extending an existing derivation to create a shell-specific derivation.

For example, if pkgs.haskellPackages.mypkg.env contains the derivation for your default shell, then you can create an extended shell containing pkgs.haskell-language-server like this:

pkgs.mkShell {
  inputsFrom = [ pkgs.haskellPackages.mypkg.env ];

  nativeBuildInputs = [ pkgs.haskell-language-server ];
}

Gabriella439 avatar Jan 28 '21 05:01 Gabriella439