How can I install a Haskell library to be accessible via GHCi with Nixos?

This works differently on NixOS because of purity. NixOS' GHC will only look at its own immutable installation directory and the packages that have been installed by the user with cabal install.

What you can do is install into your user profile a GHC wrapper that supplies a nice set of packages when you run ghci.

Create a file my-ghc.nix:

(import <nixpkgs> {}).haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
    lens
    aeson
    turtle
])

Uninstall your previous attempt, to avoid name collisions:

nix-env -e ghc turtle

Install the wrapped GHC:

nix-env -if my-ghc.nix

You may edit the file in the future and re-run that command.

When I am working on a project, I prefer to use cabal2nix and nix-shell. (For an introduction, see Oliver Charles' blog post)

Tags:

Haskell

Nixos

Nix