|
1 |
| -{ nixpkgs ? (import <nixpkgs> {}).pkgsMusl, compiler ? "ghc843" }: |
| 1 | +let |
| 2 | + # TODO: Remove when https://github.com/NixOS/cabal2nix/pull/360 is merged and available |
| 3 | + cabal2nix-fix-overlay = final: previous: |
| 4 | + with final.haskell.lib; { |
| 5 | + haskellPackages = previous.haskellPackages.override (old: { |
| 6 | + overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) ( |
| 7 | + |
| 8 | + self: super: { |
| 9 | + cabal2nix = overrideCabal super.cabal2nix (old: { |
| 10 | + src = pkgs.fetchFromGitHub { |
| 11 | + owner = "nh2"; |
| 12 | + repo = "cabal2nix"; |
| 13 | + rev = "5721bed2a598a018119413bfe868bd286735cb15"; |
| 14 | + sha256 = "1436ri6nlfcgd263byb596dcx6g4l9fx47hm11vfh34x849r2kcy"; |
| 15 | + }; |
| 16 | + }); |
| 17 | + |
| 18 | + } |
| 19 | + ); |
| 20 | + }); |
| 21 | + }; |
| 22 | + |
| 23 | + pkgs = (import <nixpkgs> { |
| 24 | + overlays = [ cabal2nix-fix-overlay ]; |
| 25 | + }).pkgsMusl; |
| 26 | + |
| 27 | +in |
| 28 | + |
| 29 | +{ compiler ? "ghc843" }: |
2 | 30 |
|
3 | 31 |
|
4 | 32 | let
|
5 | 33 |
|
6 |
| - pkgs = nixpkgs.pkgsMusl; |
| 34 | + normalHaskellPackages = pkgs.haskellPackages; |
| 35 | + |
| 36 | + sqlite_static = pkgs.sqlite.overrideAttrs (old: { dontDisableStatic = true; }); |
| 37 | + |
| 38 | + lzma_static = pkgs.lzma.overrideAttrs (old: { dontDisableStatic = true; }); |
| 39 | + |
| 40 | + haskellPackages = with pkgs.haskell.lib; normalHaskellPackages.override (old: { |
| 41 | + overrides = pkgs.lib.composeExtensions (old.overrides or (_: _: {})) (self: super: |
| 42 | + let |
| 43 | + # TODO do this via patches instead |
| 44 | + cabal_patched_src = pkgs.fetchFromGitHub { |
| 45 | + owner = "nh2"; |
| 46 | + repo = "cabal"; |
| 47 | + rev = "748f07b50724f2618798d200894f387020afc300"; |
| 48 | + sha256 = "1k559m291f6spip50rly5z9rbxhfgzxvaz64cx4jqpxgfhbh2gfs"; |
| 49 | + }; |
| 50 | + |
| 51 | + Cabal_patched_Cabal_subdir = pkgs.stdenv.mkDerivation { |
| 52 | + name = "cabal-dedupe-src"; |
| 53 | + buildCommand = '' |
| 54 | + cp -rv ${cabal_patched_src}/Cabal/ $out |
| 55 | + ''; |
| 56 | + }; |
| 57 | + |
| 58 | + Cabal_patched = self.callCabal2nix "Cabal" Cabal_patched_Cabal_subdir {}; |
7 | 59 |
|
8 |
| - normalHaskellPackages = pkgs.haskell.packages.${compiler}; |
| 60 | + useFixedCabal = drv: overrideCabal drv (old: { |
| 61 | + setupHaskellDepends = (if old ? setupHaskellDepends then old.setupHaskellDepends else []) ++ [ Cabal_patched ]; |
| 62 | + # TODO Check if this is necessary |
| 63 | + libraryHaskellDepends = (if old ? libraryHaskellDepends then old.libraryHaskellDepends else []) ++ [ Cabal_patched ]; |
| 64 | + }); |
9 | 65 |
|
10 |
| - statify = drv: with pkgs.haskell.lib; pkgs.lib.foldl appendConfigureFlag (disableLibraryProfiling (disableSharedExecutables (disableSharedLibraries drv))) [ |
11 |
| - "--ghc-option=-static" |
12 |
| - "--ghc-option=-optl=-static" |
13 |
| - "--ghc-option=-fPIC" |
| 66 | + statify = drv: with pkgs.haskell.lib; pkgs.lib.foldl appendConfigureFlag (disableLibraryProfiling (disableSharedExecutables (useFixedCabal drv))) [ |
| 67 | + # "--ghc-option=-fPIC" |
| 68 | + "--enable-executable-static" # requires `useFixedCabal` |
14 | 69 | "--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
|
| 70 | + # TODO These probably shouldn't be here but only for packages that actually need them |
15 | 71 | "--extra-lib-dirs=${pkgs.zlib.static}/lib"
|
16 |
| - # XXX: This doesn't actually work "yet": |
17 |
| - # * first, it helps to not remove the static libraries: https://github.com/dtzWill/nixpkgs/commit/54a663a519f622f19424295edb55d01686261bb4 (should be sent upstream) |
18 |
| - # * second, ghc wants to link against libtinfo but no static version of that is built |
19 |
| - # (actually no shared either, we create symlink for it-- I think) |
20 | 72 | "--extra-lib-dirs=${pkgs.ncurses.override { enableStatic = true; }}/lib"
|
21 |
| - ]; |
| 73 | + ]; |
22 | 74 |
|
23 |
| - haskellPackages = with pkgs.haskell.lib; normalHaskellPackages.override { |
24 |
| - overrides = self: super: { |
| 75 | + in |
| 76 | + { |
25 | 77 | # Helpers for other packages
|
26 | 78 |
|
27 | 79 | hpc-coveralls = appendPatch super.hpc-coveralls (builtins.fetchurl https://github.com/guillaume-nargeot/hpc-coveralls/pull/73/commits/344217f513b7adfb9037f73026f5d928be98d07f.patch);
|
| 80 | + persistent-sqlite = super.persistent-sqlite.override { sqlite = sqlite_static; }; |
| 81 | + lzma = super.lzma.override { lzma = lzma_static; }; |
| 82 | + # If we `useFixedCabal` on stack, we also need to use the |
| 83 | + # it on hpack and hackage-security because otherwise |
| 84 | + # stack depends on 2 different versions of Cabal. |
| 85 | + hpack = useFixedCabal super.hpack; |
| 86 | + hackage-security = useFixedCabal super.hackage-security; |
28 | 87 |
|
29 | 88 | # Static executables that work
|
30 | 89 |
|
|
34 | 93 | cabal-install = statify super.cabal-install;
|
35 | 94 | bench = statify super.bench;
|
36 | 95 |
|
37 |
| - # Static executables that don't work yet |
| 96 | + stack = useFixedCabal (statify super.stack); |
38 | 97 |
|
39 |
| - stack = appendConfigureFlag (statify super.stack) [ "--ghc-option=-j1" ]; |
40 |
| - cachix = statify super.cachix; |
41 | 98 | dhall = statify super.dhall;
|
42 |
| - }; |
43 |
| - }; |
| 99 | + |
| 100 | + cachix = appendConfigureFlag (statify super.cachix) [ "--ghc-option=-j1" ]; |
| 101 | + |
| 102 | + # Static executables that don't work yet |
| 103 | + |
| 104 | + }); |
| 105 | + }); |
44 | 106 |
|
45 | 107 | in
|
46 | 108 | rec {
|
47 | 109 | working = {
|
48 | 110 | inherit (haskellPackages)
|
49 | 111 | hello
|
| 112 | + stack |
50 | 113 | hlint
|
51 | 114 | ShellCheck
|
52 | 115 | cabal-install
|
53 | 116 | bench
|
| 117 | + dhall |
| 118 | + cachix |
54 | 119 | ;
|
55 | 120 | };
|
56 | 121 |
|
57 | 122 | notWorking = {
|
58 | 123 | inherit (haskellPackages)
|
59 |
| - stack |
60 |
| - dhall |
61 |
| - cachix |
62 | 124 | ;
|
63 | 125 | };
|
64 | 126 |
|
65 | 127 | all = working // notWorking;
|
66 | 128 |
|
67 | 129 | inherit haskellPackages;
|
68 | 130 | }
|
| 131 | + |
| 132 | +# TODO Update README to depend on nixpkgs master in use (instead of nh2's fork), and write something that picks nh2's patches I use on top here |
| 133 | +# TODO Instead of picking https://github.com/NixOS/nixpkgs/pull/43713, use a Python script to dedupe `-L` flags from the NIX_*LDFLAGS variables |
0 commit comments