@@ -0,0 +1,86 @@
1+{ mkStackPkgSet, callStackToNix, importAndFilterProject
2+, stdenv, gmp6, openssl, zlib, libffi
3+, buildPackages
4+}:
5+
6+with stdenv.lib;
7+
8+let
9+ # IFD stack-to-nix
10+ stack-pkgs = (importAndFilterProject (callStackToNix {
11+ src = ./.;
12+ })).pkgs;
13+
14+ # Grab the compiler name from stack-to-nix output.
15+ # compiler = (stack-pkgs.extras {}).compiler.nix-name;
16+ compiler = "ghc865"; # fixme
17+
18+ pkgSet = { gpl ? true }: mkStackPkgSet {
19+ inherit stack-pkgs;
20+ pkg-def-extras = [];
21+ modules = [
22+ # Musl libc fully static build
23+ (let
24+ staticLibs = [
25+ zlib.static
26+ (openssl.override { static = true; }).out
27+ (libffi.overrideAttrs (oldAttrs: {
28+ dontDisableStatic = true;
29+ configureFlags = (oldAttrs.configureFlags or []) ++ [
30+ "--enable-static"
31+ "--disable-shared"
32+ ];
33+ }))
34+ ] ++ optional gpl (gmp6.override { withStatic = true; });
35+
36+ withFullyStatic = {
37+ configureFlags =
38+ optionals stdenv.hostPlatform.isMusl ([
39+ "--disable-executable-dynamic"
40+ "--disable-shared"
41+ "--ghc-option=-optl=-pthread"
42+ "--ghc-option=-optl=-static"
43+ ] ++ map (drv: "--ghc-option=-optl=-L${drv}/lib") staticLibs);
44+ };
45+ in {
46+ # Select a non-GMP compiler, usually for software licensing reasons.
47+ ghc.package = mkIf (stdenv.hostPlatform.isMusl && !gpl)
48+ buildPackages.haskell.compiler.integer-simple.${compiler};
49+
50+ # Add GHC flags and libraries for fully static build
51+ packages.pandoc.components.exes.pandoc = withFullyStatic;
52+ })
53+ ];
54+ };
55+ packagesGmp = (pkgSet { gpl = true; }).config.hsPkgs;
56+ packagesIntegerSimple = (pkgSet { gpl = false; }).config.hsPkgs;
57+in
58+ stdenv.mkDerivation {
59+ name = "fully-static-test";
60+
61+ depsBuildBuild = [ buildPackages.file ];
62+
63+ buildCommand = flip concatMapStrings
64+ [ packagesGmp /* packagesIntegerSimple */ ]
65+ (packages: ''
66+ exe="${packages.pandoc.components.exes.pandoc}/bin/pandoc"
67+
68+ printf "checking whether executable runs... " >& 2
69+ $exe --version
70+
71+ '' + optionalString stdenv.hostPlatform.isMusl ''
72+ printf "checking whether executable is static... " >& 2
73+ file $exe
74+ file $exe | grep "statically linked"
75+
76+ '') + "touch $out";
77+
78+ meta.platforms = platforms.all;
79+
80+ passthru = {
81+ # Attributes used for debugging with nix repl
82+ inherit pkgSet buildPackages stack-pkgs;
83+ pandoc-gmp = packagesGmp.pandoc.components.exes.pandoc;
84+ pandoc-integer-simple = packagesIntegerSimple.pandoc.components.exes.pandoc;
85+ };
86+ }