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

旧城冷巷雨未停 提交于 2019-12-04 05:27:15

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)

As an alternative Robert's answer, one can use a nix-shell environment by creating a shell.nix file with contents of:

{ pkgs ? import <nixpkgs> {} }:
let myGhc = pkgs.haskellPackages.ghcWithPackages (hpkgs: with hpkgs; [
      turtle
    ]);
in
pkgs.mkShell {
  buildInputs = [ myGhc ];
}

And entering this environment with nix-shell.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!