@@ -6,7 +6,7 @@ First, understand how to cross-compile a normal package from
6Nixpkgs. Matthew Bauer's [Beginners' guide to cross compilation in
6Nixpkgs. Matthew Bauer's [Beginners' guide to cross compilation in
7Nixpkgs][bauer] is a useful resource.
7Nixpkgs][bauer] is a useful resource.
9−[bauer]: https://matthewbauer.us/blog/beginners-guide-to-cross.html
9+[bauer]: https://matthewbauer.us/blog/beginners-guide-to-cross.html
12Using an example from the guide, this builds GNU Hello for a Raspberry
12Using an example from the guide, this builds GNU Hello for a Raspberry
@@ -47,18 +47,24 @@ You should be prepared for a long wait because it first needs to build
47GHC, before building all the Haskell dependencies of [Bench][]. If all
47GHC, before building all the Haskell dependencies of [Bench][]. If all
48of these dependencies compiled successfully, I would be very surprised!
48of these dependencies compiled successfully, I would be very surprised!
51+ The above example won't build, but you can try and see, if you like.
52+ It will fail on [clock-0.7.2](http://hackage.haskell.org/package/clock-0.7.2),
53+ which needs a patch to build.
50To fix the build problems, you must add extra configuration to the
55To fix the build problems, you must add extra configuration to the
51package set. Your project will have a [`mkStackPkgSet`](../reference/library.md#mkstackpkgset) or
56package set. Your project will have a [`mkStackPkgSet`](../reference/library.md#mkstackpkgset) or
52[`mkCabalProjectPkgSet`](../reference/library.md#mkcabalprojectpkgset). It is there where you must add
57[`mkCabalProjectPkgSet`](../reference/library.md#mkcabalprojectpkgset). It is there where you must add
53−[module options](../reference/modules.md) for setting compiler flags and so on.
58+[module options](../reference/modules.md) for setting compiler flags, adding patches, and so on.
55### Static executables with Musl libc
61### Static executables with Musl libc
57Another application of cross-compiling is to produce fully static
63Another application of cross-compiling is to produce fully static
58binaries for Linux. For information about how to do that with the
64binaries for Linux. For information about how to do that with the
59[Nixpkgs Haskell infrastructure][nixpkgs] (not [Haskell.nix][]), see
65[Nixpkgs Haskell infrastructure][nixpkgs] (not [Haskell.nix][]), see
60−[nh2/static‑haskell‑nix][nh2]. Vaibhav Sagar's linked [blog
66+[nh2/static‑haskell‑nix][nh2]. Vaibhav Sagar's linked
61−post][vaibhav] is also very informative.
67+[blog post][vaibhav] is also very informative.
@@ -98,6 +104,76 @@ executables you must add package overrides to:
98 `integer-gmp`. However, at present, [Haskell.nix][] does not provide
104 `integer-gmp`. However, at present, [Haskell.nix][] does not provide
99 an option for this.
105 an option for this.
108+### How to cross-compile your project
110+Set up your project Haskell package set.
114+{ pkgs ? import <nixpkgs> {}
116+ # Import the Haskell.nix library,
117+ haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {
121+ # Instantiate a package set using the generated file.
122+ pkgSet = haskell.mkCabalProjectPkgSet {
123+ plan-pkgs = import ./pkgs.nix;
124+ pkg-def-extras = [];
127+ # You will need to put build fixes here.
132+ pkgSet.config.hsPkgs
135+Apply that package set to the Nixpkgs cross package sets that you are
138+We are going to expand the `pkgs.pkgsCross` shortcut to be more
143+ pkgs = import <nixpkgs> {}
145+ shortcut = pkgs.pkgsCross.SYSTEM;
146+ actual = import <nixpkgs> { crossSystem = pkgs.lib.systems.examples.SYSTEM; };
150+In the above example, for any `SYSTEM`, `shortcut` and `actual` are
151+the same package set.
156+ myProject = import ./default.nix;
158+ pkgsNative = import <nixpkgs> {};
159+ pkgsRaspberryPi = import <nixpkgs> {
160+ crossSystem = pkgsNative.lib.systems.examples.raspberryPi;
163+ native = myProject { pkgs = pkgsNative; };
164+ crossRaspberryPi = myProject { pkgs = pkgsRaspberryPi; };
167+ my-project-native = native.my-project.components.exes.my-project;
168+ my-project-raspberry-pi = crossRaspberryPi.my-project.components.exes.my-project;
172+Try to build it, and apply fixes to the `modules` list, until there
101[nh2]: https://github.com/nh2/static-haskell-nix
177[nh2]: https://github.com/nh2/static-haskell-nix
102[vaibhav]: https://vaibhavsagar.com/blog/2018/01/03/static-haskell-nix/
178[vaibhav]: https://vaibhavsagar.com/blog/2018/01/03/static-haskell-nix/
103[haskell.nix]: https://github.com/input-output-hk/haskell.nix
179[haskell.nix]: https://github.com/input-output-hk/haskell.nix