Gabriella439 / haskell-nix

Nix and Haskell in production
1.14k stars 116 forks source link

Development dependencies #92

Open jerbaroo opened 3 years ago

jerbaroo commented 3 years ago

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 commented 3 years ago

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;
  })
Gabriella439 commented 3 years ago

@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 ];
}