haskell.nix
haskell.nix copied to clipboard
How to add propagatedBuildInputs in a cross-compiling-generic way?
My cross-compiled project targeting Windows (mingwW64) currently doesn't quite work. Nix copies some dlls, but not all. One missing is zlib's.
I think this is due to the zlib Haskell library not having propagatedBuildInputs. If I could add zlib-the-C-library to propagatedBuildInputs, I think the Windows dll copying logic would work.
The issue is I don't know how to do this. I know I can use the modules argument to project to override propagatedBuildInputs. But that isn't enough: If I just hard-code it to use pkgs.zlib (where pkgs is my import ./nix/pkgs.nix)..then I'm pretty sure it is not cross-compiler-generic - it'll hard-code it to my Linux zlib.
Feels like a lambda would go a long way here.
modules = p: [
# do the overriding
];
I think we have this problem in general. See e.g. the following workaround in plutus for this problem: https://github.com/input-output-hk/plutus/blob/master/nix/pkgs/haskell/haskell.nix#L84
Bumping to ghc 9.2.3 fixed some extra library propagation - I no longer have to manual copy libgcc_s_seh-1.dll and mcfgthread-12.dll alongside my exe :+1:
-cp $(nix-build --no-out-link --expr '(import ../nix/pkgs.nix).pkgsCross.mingwW64.buildPackages.gcc.cc')/x86_64-w64-mingw32/lib/libgcc_s_seh-1.dll "$releasedir"
-cp $(nix-build --no-out-link --expr '(import ../nix/pkgs.nix).pkgsCross.mingwW64.windows.mcfgthreads')/bin/mcfgthread-12.dll "$releasedir"
zlib still seems necessary though, but I suspect that has more to do with how that Haskell library is package.
Looking at @michaelpj 's code again, it looks the API I want already basically exists:
modules = [
(
{pkgs, ...}:
# do the overriding
)
];
I didn't make the connection between NixOS modules and haskell.nix modules. But they seem to have the same API.
I will try modules to fix my issues with propagated build inputs for zlib and gloss. If it works, I'll link the result here & close this issue 👍