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

前端 未结 2 785
渐次进展
渐次进展 2021-02-09 02:11

I\'ve managed to install ghc with nix-env -i ghc.

I\'d like to install a Haskell library now, how should this be done? For example the turtle (

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-09 02:57

    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  {}).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)

提交回复
热议问题