Skip to content

Commit ef28327

Browse files
committed
survey: Make all listed packages work
1 parent 627a8c5 commit ef28327

File tree

2 files changed

+88
-23
lines changed

2 files changed

+88
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The [`survey`](./survey) directory maintains a select set of Haskell executables
3434
Run for example:
3535

3636
```
37-
NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/2c07921cff84dfb0b9e0f6c2d10ee2bfee6a85ac.tar.gz nix-build --no-link survey/default.nix -A working
37+
NIX_PATH=nixpkgs=https://github.com/nh2/nixpkgs/archive/925aac04f4ca58aceb83beef18cb7dae0715421b.tar.gz nix-build --no-link survey/default.nix -A working
3838
```
3939

4040
There are multiple package sets available in the survey (select via `-A`):

survey/default.nix

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,89 @@
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" }:
230

331

432
let
533

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 {};
759

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+
});
965

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`
1469
"--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
1571
"--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)
2072
"--extra-lib-dirs=${pkgs.ncurses.override { enableStatic = true; }}/lib"
21-
];
73+
];
2274

23-
haskellPackages = with pkgs.haskell.lib; normalHaskellPackages.override {
24-
overrides = self: super: {
75+
in
76+
{
2577
# Helpers for other packages
2678

2779
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;
2887

2988
# Static executables that work
3089

@@ -34,35 +93,41 @@ let
3493
cabal-install = statify super.cabal-install;
3594
bench = statify super.bench;
3695

37-
# Static executables that don't work yet
96+
stack = useFixedCabal (statify super.stack);
3897

39-
stack = appendConfigureFlag (statify super.stack) [ "--ghc-option=-j1" ];
40-
cachix = statify super.cachix;
4198
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+
});
44106

45107
in
46108
rec {
47109
working = {
48110
inherit (haskellPackages)
49111
hello
112+
stack
50113
hlint
51114
ShellCheck
52115
cabal-install
53116
bench
117+
dhall
118+
cachix
54119
;
55120
};
56121

57122
notWorking = {
58123
inherit (haskellPackages)
59-
stack
60-
dhall
61-
cachix
62124
;
63125
};
64126

65127
all = working // notWorking;
66128

67129
inherit haskellPackages;
68130
}
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

Comments
 (0)