haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

How to add propagatedBuildInputs in a cross-compiling-generic way?

Open ramirez7 opened this issue 3 years ago • 2 comments

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
];

ramirez7 avatar Mar 13 '22 02:03 ramirez7

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

michaelpj avatar Mar 14 '22 10:03 michaelpj

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.

ramirez7 avatar Jun 03 '22 21:06 ramirez7

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 👍

ramirez7 avatar Sep 19 '22 23:09 ramirez7