2

I'm looking for something similar to this:

shell.nix

{ pkgs ? import <nixpkgs> {} }:
let
  threadscope = ...
  speedscope = ...
in
  stdenv.mkDerivation {
    name = "haskell-env";
    nativeBuildInputs = [
      # Haskell tools
      ghcid ghc

      # Profiling tools
      threadscope
      speedscope
    ];
  }

Then I can use nix-shell:

% nix-shell
...
nix-shell % threadscope <some-commands>
nix-shell % speedscope <some-commands>

Do you usually just build from source from github / hackage / stackage or use pkgs.haskellPackages.<my-package>?

Robert Hensing
  • 6,708
  • 18
  • 23
Noel Kwan
  • 123
  • 1
  • 5
  • 1
    I've changed your example to use `nativeBuildInputs` which is more suitable for shell tools. `buildInputs` is intended for libraries and such, but includes legacy behavior that is sub-optimal. For example, shell tab completion won't be supported for `buildInputs`. You'll see many examples that use `buildInputs` though, because it kind of works and it's a somewhat recent change. – Robert Hensing Dec 09 '20 at 11:20

1 Answers1

3

I usually take tools from haskellPackages.

If you only want a shell with tools, you can use an expression like this.

{ pkgs ? import <nixpkgs> {} }:

let
  # Select a package set. haskellPackages is recommended, but
  # if you need a different ghc, use pkgs.haskell.packages.ghc8102 for example
  haskellPackages = pkgs.haskellPackages;

in
  pkgs.mkShell {
    nativeBuildInputs = [
      # Haskell tools
      haskellPackages.ghc
      haskellPackages.ghcid

      # Profiling tools
      haskellPackages.threadscope
      # pkgs.speedscope (not packaged yet)
    ];
  }

If you want a shell with specific precompiled libraries, you can use the ghcWithPackages function instead of ghc. If you want precompiled dependencies for your local Haskell package(s), you can replace pkgs.mkShell by the haskellPackages.shellFor function.

If you'd like to package speedscope, the Nixpkgs manual documents the packaging process for node packages

Robert Hensing
  • 6,708
  • 18
  • 23