You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+17-7
Original file line number
Diff line number
Diff line change
@@ -3,23 +3,25 @@
3
3
With this repository you can easily build most Haskell programs into fully static Linux executables.
4
4
5
5
* results are fully static executables (`ldd` says `not a dynamic executable`)
6
-
* to make that possible, it and all dependencies (including ghc) are built against [`musl`](https://www.musl-libc.org/) instead of glibc
6
+
* to make that possible, each exe and all dependencies (including ghc) are built against [`musl`](https://www.musl-libc.org/) instead of glibc
7
7
8
8
## History
9
9
10
10
`glibc` encourages dynamic linking to the extent that correct functionality under static linking is somewhere between difficult and bug-ridden.
11
11
For this reason, static linking, despite its many advantages (details [here](https://github.com/NixOS/nixpkgs/issues/43795)) has become less and less common.
12
12
13
-
Due to GHC's dependency on a libc, and many libraries depending on C libraries for which Linux distributions often do not include static library archive files, this situation has resulted in Haskell programs being extremely hard to produce for the common Haskeller, even though the language is generally well-suited for static linking.
13
+
Due to GHC's dependency on a libc, and many libraries depending on C libraries for which Linux distributions often do not include static library archive files, this situation has resulted in fully static Haskell programs being extremely hard to produce for the common Haskeller, even though the language is generally well-suited for static linking.
14
14
15
-
This project set out to solve this.
15
+
This project solves this.
16
16
17
17
It was inspired by a [blog post by Vaibhav Sagar](https://vaibhavsagar.com/blog/2018/01/03/static-haskell-nix/),
18
18
and a [comment by Will Dietz](https://github.com/NixOS/nixpkgs/pull/37598#issuecomment-375117019) about musl.
19
19
20
+
Work on this so far was sponsored largely by my free time, [FP Complete](https://haskell.fpcomplete.com/) and their clients, and the contributors mentioned [here](https://github.com/NixOS/nixpkgs/issues/43795#issue-342546855).
21
+
20
22
By now we have a nixpkgs issue on [Fully static Haskell executables](https://github.com/NixOS/nixpkgs/issues/43795) (progress on which is currently this repo, with plans to later merge it into nixpkgs), and [a merged nixpkgs overlay for static nixpkgs in general](https://github.com/NixOS/nixpkgs/pull/48803).
21
23
22
-
## Building a minimal example
24
+
## Building a minimal example (don't use this in practice)
23
25
24
26
`default.nix` builds an example executable (originally from https://github.com/vaibhavsagar/experiments). Run:
This prints a path that contains the fully linked static executable in the `bin` subdirectory.
31
33
32
34
This example is so that you get the general idea.
33
-
In practice, you probably want to use the approach in the "Building arbitrary packages" section below.
35
+
In practice, you probably want to use one of the approaches from the "Building arbitrary packages" or "Building stack projects" sections below.
34
36
35
37
## Binary caches for faster building (optional)
36
38
@@ -49,8 +51,6 @@ Note that you may not get cached results if you use a different `nix` version th
49
51
50
52
## Building arbitrary packages
51
53
52
-
The [`static-stack`](./static-stack) directory shows how to build a fully static `stack` executable (a Haskell package with many dependencies), and makes it reasonably easy to build other packages as well.
53
-
54
54
The [`survey`](./survey) directory maintains a select set of Haskell executables that are known and not known to work with this approach; contributions are welcome to grow the set of working executables.
55
55
Run for example:
56
56
@@ -63,3 +63,13 @@ There are multiple package sets available in the survey (select via `-A`):
63
63
*`working` -- build all exes known to be working
64
64
*`notWorking` -- build all exes known to be not working (help welcome to make them work)
65
65
*`haskellPackages.somePackage` -- build a specific package from our overridden package set
66
+
67
+
If you are a nix user, you can easily `import` this functionality and add an override to add your own packages.
68
+
69
+
## Building `stack` projects
70
+
71
+
The [`static-stack2nix-builder-example`](./static-stack2nix-builder-example) directory shows how to build any `stack`-based project statically.
72
+
73
+
Another example of this is the the official static build of `stack` itself.
74
+
See the [`static-stack`](./static-stack) directory for how that's done.
75
+
`stack` is a big package with many dependencies, demonstrating that this works also for large projects.
0 commit comments