Haskell.nix cross-compilation with flake

Hi, I’ve been trying to get a simple cross-compilation setup from aarch64-darwin to aarch64-multiplatform with haskell.nix, now that pkgsCross.aarch64-multiplatform.gcc is no longer broken on aarch64-darwin (`pkgsCross.aarch64-multiplatform.gcc` is broken on `aarch64-darwin` · Issue #137877 · NixOS/nixpkgs · GitHub).

I am still getting my head around flakes, and haskell.nix, and have come up with flake.nix below, based on the standard flake template haskell.nix provides on their website (although I had to change compiler-src-name to compiler-nix-name).

{
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, haskellNix, flake-utils }: 
    flake-utils.lib.eachDefaultSystem (system:
    let
      overlays = [ haskellNix.overlay
      (final: prev: {
        # This overlay adds our project to pkgs
        helloProject =
          final.haskell-nix.project {
            src = ./.;
            compiler-nix-name = "ghc925";
            # This is used by `nix develop .` to open a shell for use with
            # `cabal`, `hlint` and `haskell-language-server`
            shell.tools = {
              cabal = {};
              hlint = {};
              haskell-language-server = {};
            };
            # Non-Haskell shell tools go here
            shell.buildInputs = with pkgs; [
              nixpkgs-fmt
            ];
            # This adds `js-unknown-ghcjs-cabal` to the shell.
            # shell.crossPlatforms = p: [p.ghcjs];
          };
      })
      ];

      pkgs = (import nixpkgs { inherit system overlays; inherit (haskellNix) config; }).pkgsCross.aarch64-multiplatform;
      flake = pkgs.helloProject.flake {};
    in flake // {
      # Built by `nix build .`
      packages.default = flake.packages."hello:exe:hello";
    });
}

The haskell project itself just has a simple main.hs and a cabal file:

name: hello
version: 1.0.0
license: BSD3
license-file: LICENSE
cabal-version: 1.18
build-type: Simple

executable hello
    build-depends: 
        base < 5,
        hakyll == 4.15.1.1
    main-is: Main.hs
    default-language: Haskell2010

When I run nix build I get the following output:

trace: WARNING: No materialized dummy-ghc-data.  mkdir /nix/store/c9hw0s71x8aiv0ghmp0vklx6rd7mn4w7-source/materialized/dummy-ghc/aarch64-unknown-linux-gnu-aarch64-unknown-linux-gnu-ghc-9.2.5-aarch64-linux
error: a 'aarch64-linux' with features {} is required to build '/nix/store/a0xz1x82c6cy1lqlb8rdcvjkwskg075m-cabal.project.drv', but I am a 'aarch64-darwin' with features {benchmark, big-parallel, nixos-test}
(use '--show-trace' to show detailed location information)

What am I doing wrong? Presumably I’m giving it the wrong package set?

2 Likes