Skip to content

Commit ac35783

Browse files
authored
Merge pull request #2 from cdepillabout/static-compilation
Make static compilation a little easier
2 parents 8b32b2a + 78e6661 commit ac35783

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11

2+
## next
3+
4+
* Add a `callPackage` argument to `stacklock2nix` so that users can easily statically-compile Haskell packages.
5+
6+
This could be used like the following:
7+
8+
```nix
9+
my-haskell-stacklock = final.stacklock2nix {
10+
stackYaml = ./stack.yaml;
11+
baseHaskellPkgSet = final.pkgsStatic.haskell.packages.ghc924;
12+
callPackage = final.pkgsStatic.callPackage;
13+
...
14+
};
15+
```
16+
217
## 0.1.0
318
419
* Initial release.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ Advantages of haskell.nix:
170170
(without also requiring a `stack.yaml.lock` file).
171171
- A shared cache from IOHK. (Although users commonly report not
172172
getting cache hits for various reasons.)
173+
- The ability to cross-compile Haskell libraries. (For instance,
174+
building an ARM64 binary on an x86_64 machine.)
173175

174176
Advantages of `stacklock2nix`:
175177

@@ -205,3 +207,26 @@ PRs, and helping people who run into problems. I prioritize issues and PRs
205207
from people who are sponsors.
206208

207209
You can find the sponsor page [here](https://github.com/sponsors/cdepillabout).
210+
211+
## FAQ
212+
213+
- **Is it possible to use `stacklock2nix` to build a statically-linked Haskell library?**
214+
215+
Recent versions (since mid-2022) of the Haskell infrastructure in Nixpkgs
216+
have the ability to link Haskell executables completely statically. An
217+
easy way to test this out is to use the
218+
[`pkgsStatic` subpackage set](https://functor.tokyo/blog/2021-10-20-nix-cross-static)
219+
in Nixpkgs.
220+
221+
Instead of passing a value like `pkgs.haskell.packages.ghc924` to the
222+
`baseHaskellPkgSet` of the `stacklock2nix` function, pass
223+
`pkgs.pkgsStatic.haskell.packages.ghc924`:
224+
225+
```nix
226+
my-haskell-stacklock = final.stacklock2nix {
227+
stackYaml = ./stack.yaml;
228+
baseHaskellPkgSet = final.pkgsStatic.haskell.packages.ghc924;
229+
callPackage = final.pkgsStatic.callPackage;
230+
...
231+
};
232+
```

nix/build-support/stacklock2nix/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
, fetchurl
44
, haskell
55
, lib
6-
, pkgs
76
, runCommand
87
, stdenv
9-
}:
8+
}@topargs:
109

1110
{ # The path to your stack.yaml file.
1211
#
@@ -77,6 +76,7 @@
7776
#
7877
# This is not used if `baseHaskellPkgSet` is `null`.
7978
all-cabal-hashes ? null
79+
, callPackage ? topargs.callPackage
8080
}:
8181

8282
# The stack.yaml path can be computed from the stack.yaml.lock path, or

0 commit comments

Comments
 (0)