-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
210 lines (183 loc) · 6.39 KB
/
flake.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
{
inputs = {
haskellNix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
flakeUtils.url = "github:numtide/flake-utils";
feedback.url = "github:NorfairKing/feedback";
};
outputs = { self, nixpkgs, haskellNix, flakeUtils, feedback }:
let
supportedSystems = [
"x86_64-linux"
];
in
flakeUtils.lib.eachSystem supportedSystems (system:
let
mkPkg = name: value:
with pkgs.lib; {
name = builtins.replaceStrings
[ "x86_64-w64-" "x86_64-unknown-linux-" ]
[ "" "" ]
name;
value = value;
};
overlays = [
haskellNix.overlay
(final: prev:
let
project = final.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = "ghc964";
name = "gibberish";
flake.variants.profiled = {
modules = [{
enableLibraryProfiling = true;
enableProfiling = true;
}];
};
shell = {
tools = {
cabal = "latest";
haskell-language-server = "latest";
hp2pretty = "latest";
};
nativeBuildInputs = with final; [fourmolu hlint];
withHoogle = true;
# No cross platforms should speed up evaluation
crossPlatforms = _: [];
};
};
in {
gibberishProject = project.appendOverlays [
# Add exes
final.haskell-nix.haskellLib.projectOverlays.projectComponents
];
})
(final: prev: {
fourmolu =
final.haskell-nix.tool
final.gibberishProject.args.compiler-nix-name
"fourmolu"
"0.13.1.0";
hlint =
final.haskell-nix.tool
final.gibberishProject.args.compiler-nix-name
"hlint"
"latest";
fourmoluCheck =
prev.runCommand
"fourmolu-check"
{ buildInputs = [final.fourmolu]; }
''
cd "${final.gibberishProject.args.src}"
fourmolu --mode check src test
[[ "$?" -eq "0" ]] && touch $out
'';
hlintCheck =
prev.runCommand
"hlint-check"
{ buildInputs = [final.hlint]; }
''
cd "${final.gibberishProject.args.src}"
hlint src test
[[ "$?" -eq "0" ]] && touch $out
'';
})
];
pkgs = import nixpkgs {
inherit system overlays;
inherit (haskellNix) config;
};
flake = pkgs.gibberishProject.flake {
crossPlatforms = p:
pkgs.lib.optionals pkgs.stdenv.hostPlatform.isx86_64 (
[p.mingwW64] ++
(pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux
[p.musl64]));
};
cpExesCmd = project:
let
inherit (pkgs) lib;
exes = lib.collect lib.isDerivation project.exes;
in ''
# Create an intermediate dir
mkdir release
# Copy exes to intermediate dir
${lib.concatMapStringsSep
"\n"
(exe: "cp --verbose --remove-destination --update=none ${exe}/bin/* release")
exes}
'';
mkDistMusl =
let
project = pkgs.gibberishProject.projectCross.musl64;
name = "gibberish-${version}-x86_64-linux";
version = project.exes.gibber.identifier.version;
in
pkgs.runCommand
"gibberish-musl64"
{}
''
mkdir -p $out
# Copy exes to intermediate dir
${cpExesCmd project}
# Package distribution
cd release
dist_file=${name}.tar.gz
tar -cvzf $out/$dist_file .
'';
mkDistWin64 =
let
inherit (pkgs) lib;
project = pkgs.gibberishProject.projectCross.mingwW64;
name = "gibberish-${version}-x86_64-windows";
version = project.exes.gibber.identifier.version;
env = {
nativeBuildInputs = [pkgs.zip];
};
in
pkgs.runCommand
"gibberish-win64"
env
''
mkdir -p $out
# Copy exes to intermediate dir
${cpExesCmd project}
# Package distribution
cd release
dist_file=${name}.zip
find . -type f | xargs zip $out/$dist_file
'';
in
with pkgs.lib;
flake // {
apps = {
default = flake.apps."gibberish:exe:gibber";
} // mapAttrs' mkPkg flake.apps;
checks = {
inherit (pkgs) hlintCheck fourmoluCheck;
} //
filterAttrs (name: _: !hasPrefix "profiled" name)
(mapAttrs' mkPkg flake.checks);
packages = {
default = flake.packages."gibberish:exe:gibber";
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
dist-musl = mkDistMusl;
dist-win64 = mkDistWin64;
} // mapAttrs' mkPkg flake.packages;
});
nixConfig = {
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"sgillespie.cachix.org-1:Zgif/WHW2IzHqbMb1z56cMmV5tLAA+zW9d5iB5w/VU4="
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
substituters = [
"https://cache.nixos.org/"
"https://cache.iog.io"
"https://sgillespie.cachix.org"
];
allow-import-from-derivation = "true";
experimental-features = ["nix-command flakes"];
};
}