forked from awakesecurity/proto3-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.nix
299 lines (253 loc) · 10.4 KB
/
release.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# To develop iteratively within this repository, open a Nix shell via:
#
# $ nix-shell
#
# ... and then use `cabal` to build and test:
#
# [nix-shell]$ cabal configure --enable-tests
# [nix-shell]$ cabal test
#
# Note that nix-shell will actually build most of the code in order to
# allow testing of code generation. You might wish to temporarily edit
# shell.nix to specify "proto3-suite-boot" instead of "proto3-suite" in
# order to get things to compile, then switch back to enable testing.
{ compiler ? "ghc865", enableDhall ? false }:
let
fetchNixpkgs = import ./nix/fetchNixpkgs.nix;
nixpkgsRelease = "20.03";
unpatchedNixpkgs = fetchNixpkgs {
rev = "fdfd5ab05444c38a006cb107d7d1ee8cb0b15719";
sha256 = "17hsjpjahl0hff3z2khrcwxygjyyrav2pia3qqlli0sgywfrgf95";
};
config = { };
upgrade = packageList: haskellPackagesNew: haskellPackagesOld:
let op = name: {
inherit name;
value = haskellPackagesNew.callPackage (./nix + "/${name}.nix") { };
};
in
builtins.listToAttrs (builtins.map op packageList);
dontCheck = haskell: packageList: haskellPackagesNew: haskellPackagesOld:
let op = name: {
inherit name;
value = haskell.lib.dontCheck haskellPackagesOld.${name};
};
in
builtins.listToAttrs (builtins.map op packageList);
jailbreak = haskell: packageList: haskellPackagesNew: haskellPackagesOld:
let op = name: {
inherit name;
value = haskell.lib.doJailbreak haskellPackagesOld.${name};
};
in
builtins.listToAttrs (builtins.map op packageList);
patch = haskell: packageList: haskellPackagesNew: haskellPackagesOld:
let op = name: {
inherit name;
value = haskell.lib.appendPatch haskellPackagesOld.${name}
(./nix + "/${name}.patch");
};
in
builtins.listToAttrs (builtins.map op packageList);
composeExtensionList = lib: lib.foldr lib.composeExtensions (_: _: {});
overlays = [
(pkgsNew: pkgsOld: rec {
haskell = pkgsOld.haskell // {
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override {
overrides =
let
ghcVer = pkgsOld.haskell.packages.${compiler}.ghc.version;
geVer = v: xs:
if builtins.compareVersions ghcVer v >= 0 then xs else [];
rangeVer = lowInclusive: highExclusive: xs:
if builtins.compareVersions ghcVer lowInclusive >= 0 &&
builtins.compareVersions ghcVer highExclusive < 0
then xs
else [];
upgradeOverrides = upgrade
( [ "generic-random"
"parameterized"
"proto3-wire"
] ++ rangeVer "8.8" "8.10" [
"network-bsd"
] ++ geVer "8.8" [
"dhall"
"haskell-src"
"insert-ordered-containers"
"prettyprinter"
"swagger2"
] ++ geVer "8.10" [
"assoc"
"cabal-install"
"cborg"
"cborg-json"
"ChasingBottoms"
"ChasingBottoms"
"comonad"
"contravariant-extras"
"cryptohash-sha256"
"dec"
"Diff"
"distributive"
"doctest"
"ed25519"
"generics-sop"
"hackage-security"
"HTTP"
"http-media"
"inspection-testing"
"language-haskell-extract"
"lens"
"lukko"
"memory"
"optics-core"
"optics-extra"
"optics-th"
"polyparse"
"quickcheck-instances"
"range-set-list"
"refact"
"repline"
"resolv"
"semigroupoids"
"serialise"
"singleton-bool"
"sop-core"
"these"
"tls"
"turtle"
"vector-th-unbox"
]
);
patchOverrides = patch haskell
([ "parameterized" ] ++ geVer "8.10.1" [ "cabal-install" ]);
dontCheckOverrides = dontCheck haskell
[ "cryptohash-sha256"
"dhall"
"doctest"
"ed25519"
"http-media"
"network-uri"
];
jailbreakOverrides = jailbreak haskell
[ "cabal-install"
"haskell-src"
"language-haskell-extract"
"refact"
"system-fileio"
];
manualOverrides = haskellPackagesNew: haskellPackagesOld: rec {
proto3-suite-base =
let cabal2nixFlags = if enableDhall then "-fdhall" else "";
in haskellPackagesNew.callCabal2nixWithOptions
"proto3-suite" ./. cabal2nixFlags { };
proto3-suite-boot =
pkgsNew.haskell.lib.overrideCabal
proto3-suite-base
(oldArgs: {
configureFlags = (oldArgs.configureFlags or [])
++ [ "--disable-optimization" ]
++ (if enableDhall then [ "-fdhall" ] else []);
doCheck = false;
doHaddock = false;
}
);
proto3-suite =
pkgsNew.haskell.lib.overrideCabal
proto3-suite-base
(oldArgs:
let
protobuf = pkgsNew.protobuf;
python = pkgsNew.python.withPackages
(pkgs: [ pkgs.protobuf]);
ghc =
haskellPackagesNew.ghcWithPackages
( pkgs: oldArgs.testHaskellDepends ++
[ proto3-suite-boot ] );
test-files = ./test-files;
cg-artifacts = pkgsNew.runCommand "proto3-suite-test-cg-artifacts" {} ''
mkdir -p $out/protos
cp -r ${test-files}/. $out/protos/.
cd $out
build () {
echo "[proto3-suite-test-cg-artifacts] Compiling proto-file/$1"
${proto3-suite-boot}/bin/compile-proto-file \
--out $out \
--includeDir "$2" \
--proto "$1"
}
for proto in $(find ${test-files} -name 'test_*.proto'); do
build ''${proto#${test-files}/} ${test-files}
done
echo "[proto3-suite-test-cg-artifacts] Protobuf CG complete"
'';
copyGeneratedCode = ''
echo "Copying CG artifacts from ${cg-artifacts} into ./gen/"
mkdir -p gen
${pkgsNew.rsync}/bin/rsync \
--recursive \
--checksum \
${cg-artifacts}/ gen
chmod -R u+w gen
'';
in rec {
configureFlags = (oldArgs.configureFlags or [])
++ (if enableDhall then [ "-fdhall" ] else []);
postPatch = (oldArgs.postPatch or "") + copyGeneratedCode;
testHaskellDepends =
(oldArgs.testHaskellDepends or []) ++ [
pkgsNew.ghc
pkgsNew.protobuf3_1
proto3-suite-boot
python
protobuf
];
shellHook = (oldArgs.shellHook or "") + ''
${copyGeneratedCode}
export PATH=${haskellPackagesNew.cabal-install}/bin:${ghc}/bin:${python}/bin:${protobuf}/bin''${PATH:+:}$PATH
'';
}
);
};
in
composeExtensionList pkgsNew.lib
[ upgradeOverrides
patchOverrides
dontCheckOverrides
jailbreakOverrides
manualOverrides
];
};
};
};
})
];
unpatchedPkgs = import unpatchedNixpkgs { inherit config overlays; };
# https://github.com/NixOS/nixpkgs/pull/85446
nixpkgs = unpatchedPkgs.stdenvNoCC.mkDerivation {
name = "nixpkgs-${nixpkgsRelease}-patched";
src = unpatchedNixpkgs;
# Backport fix <https://github.com/NixOS/nixpkgs/pull/85446> to 20.03:
patches = [ ./nix/with-packages-wrapper.patch ];
phases = [ "unpackPhase" "patchPhase" "installPhase" ];
installPhase = ''
mkdir -p $out
cp -R ./ $out/
'';
preferLocalBuild = true;
};
linuxPkgs =
import nixpkgs { inherit config overlays; system = "x86_64-linux" ; };
darwinPkgs =
import nixpkgs { inherit config overlays; system = "x86_64-darwin"; };
pkgs =
import nixpkgs { inherit config overlays; };
in
{ proto3-suite-linux =
linuxPkgs.haskell.packages."${compiler}".proto3-suite;
proto3-suite-darwin =
darwinPkgs.haskell.packages."${compiler}".proto3-suite;
inherit (pkgs.haskell.packages."${compiler}")
proto3-suite-boot proto3-suite;
}