This repository contains the necessary nix-expressions and a
submodule that should allow us to cross compile a small haskell application
into a working windows executable.
To build the cross compiled
hs-hello.exe with nix, all we need is
$ nix-build -A hello-world --cores 0
This will build the necessary dependencies, and finally build the
hs-hello.exe, which we can find in
We will need a customized GHC. Due to the introduction of the
buildPackages for the cross compilation capabilities in
turns out to be a bit more complicated than we like. The core issue here is
that the stage logic and the
packageOverrides do not play well together.
Specifically changes made via
packageOverrides do not show up in the
This is our usual haskell package expression. Just note the additional
enableSharedExecutables = false; setupHaskellDepends = [ Cabal_HEAD ];
as we don’t have dynamic libraries with our cross compiler (yet). And need
to link against a custom
default.nix we’ll pull everything together. Set the
mingwW64 and the
In addition we setup a custom
Cabal library, which we want to link against;
the one that ships with GHC has some defects when cross compiling to windows.
callPackage on the
buildPackages to ensure that the
library is built for the build machine. For the
hello-world.nix) we use
pkgs which will result in the package to be built
for the host machine.