Cross compiling Hello World (haskell) to Windows using nix.
Switch branches/tags
Nothing to show
Clone or download
Latest commit e85a1b0 Mar 6, 2018

README.org

Hello Windows

This repository contains the necessary nix-expressions and a nixpkgs submodule that should allow us to cross compile a small haskell application into a working windows executable.

hs-hello.png

Building

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 result/bin/hs-hello.exe.

config.nix

We will need a customized GHC. Due to the introduction of the buildPackages for the cross compilation capabilities in nixpkgs this 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 buildPackages.

hello-world.nix

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 Cabal library.

default.nix

In the default.nix we’ll pull everything together. Set the crossSystem to mingwW64 and the packageOverlays via config.

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.

We use callPackage on the buildPackages to ensure that the Cabal library is built for the build machine. For the hello-world package (hello-world.nix) we use pkgs which will result in the package to be built for the host machine.