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