Hey @yellowbean, I’ve been quite bothered by this issue as well.
In the nix community it seems that it’s typical to always use a shell for the particular project you are building, and thus the advice I’ve found online for this is always to just start the shell to build that project.
That said, I’d prefer to have a working global environment (declaratively configured in my NixOS/nix-darwin config) for building Haskell projects and GHC itself by default.
I’ve fixed this just today actually, the key lines you need I believe are replicating what nix-shell
is doing behind the scenes:
home.sessionVariables = {
# Commonly needed in the env for building haskell pkgs
# ncurses, gmp, zlib
PKG_CONFIG_PATH = "${pkgs.zlib.dev}/lib/pkgconfig:${pkgs.gmp.dev}/lib/pkgconfig:${pkgs.ncurses.dev}/lib/pkgconfig";
C_INCLUDE_PATH = "${pkgs.zlib.dev}/include:${pkgs.gmp.dev}/include:${pkgs.ncurses.dev}/include";
LIBRARY_PATH = "${pkgs.zlib}/lib:${pkgs.gmp}/lib:${pkgs.ncurses}/lib";
};
For what it’s worth, my global package set looks like this:
let
hs-comp = pkgs.haskell.compiler.ghc910;
hs-pkgs = pkgs.haskell.packages.ghc910;
in
{
...
home.packages = with pkgs; [
fzf ripgrep
hs-comp
hs-pkgs.cabal-install
hs-pkgs.haskell-language-server
nixos-rebuild # to deploy to remote nixos machines directly
# For (building) GHC
hs-pkgs.alex hs-pkgs.happy autoconf automake python3
# Make this available by default
pkgs.pkg-config
];
home.sessionVariables = ... # as in the first snippet
}
Hope that’s helpful! I would have loved to find this solution earlier .
PS: If you are not using home-manager
, you should be able to do the same thing by setting the variables in environment.variables
and packages in environment.systemPackages
.
Cheers