forked from awakesecurity/gRPC-haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.nix
239 lines (209 loc) · 9.21 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
# If you would like to test and build changes quickly using `cabal`, run:
#
# $ nix-shell
# [nix-shell]$ cabal configure --enable-tests && cabal test
#
# This will open up a Nix shell where all of your Haskell tools will work like
# normal, except that all dependencies (including C libraries) are managed by
# Nix. The only thing that won't work is running tests inside this shell
# (although you can still build them). Fixing the test suite requires
# extensive patching of the test scripts (see `postPatch` below)
#
# Note that this will compile the library once without tests using Nix. This
# is due to the fact that `grpc-haskell`'s test suite cannot test code
# generation without the library being built at least once.
#
# If you want to build and test this repository using `nix`, you can run the
# following command:
#
# $ nix-build --attr grpc-haskell release.nix
#
# ... but this is not recommended for normal development because this will
# rebuild the repository from scratch every time, which is extremely slow. Only
# do this if you want to exactly reproduce our continuous integration build.
#
# By default, Nix will pick a version for each one of your Haskell dependencies.
# If you would like to select a different version then, run:
#
# $ cabal2nix cabal://${package-name}-${version} > nix/${package-name}.nix
#
# ... and then add this line below in the Haskell package overrides section:
#
# ${package-name} =
# haskellPackagesNew.callPackage ./nix/${package-name}.nix { };
#
# ... replacing `${package-name}` with the name of the package that you would
# like to upgrade and `${version}` with the version you want to upgrade to.
#
# You can also add private Git dependencies in the same way, except supplying
# the `git` URL to clone:
#
# $ cabal2nix <your private git url>/${package-name}.git > ./nix/${package-name}.nix
#
# ...but also be sure to supply `fetchgit = pkgs.fetchgitPrivate` in the
# `haskellPackagesNew.callPackage` invocation for your private package.
#
# Note that `cabal2nix` also takes an optional `--revision` flag if you want to
# pick a revision other than the latest to depend on.
#
# If you want to test a local source checkout of a dependency, then run:
#
# $ cabal2nix path/to/dependency/repo > nix/${package-name}.nix
#
# Finally, if you want to add grpc-haskell to your own package set, you can
# setup the overlay with:
#
# grpc-nixpkgs = import path/to/gRPC-haskell/nixpkgs.nix;
# grpc-overlay = (import path/to/gRPC-haskell/release.nix).overlay;
# # optionally use the same nixpkgs source
# pkgs = grpc-nixpkgs { overlays = [ grpc-overlay ]; };
#
# ... and use the extend function to setup haskell package override:
#
# # see https://github.com/NixOS/nixpkgs/issues/25887
# haskellPackages = pkgs.haskellPackages.extend (self: super: {
# your-package = self.callCabal2nix "your-package" ./. { };
# };);
let
overlay = pkgsNew: pkgsOld: {
grpc = pkgsNew.callPackage ./nix/grpc.nix { };
haskellPackages = pkgsOld.haskellPackages.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
parameterized =
pkgsNew.haskell.lib.overrideCabal
haskellPackagesOld.parameterized
(old: {
broken = false;
patches = (old.patches or [ ]) ++ [ ./nix/parameterized.patch ];
});
haskell-src =
haskellPackagesNew.callHackage "haskell-src" "1.0.3.1" {};
proto3-wire =
haskellPackagesNew.callPackage ./nix/proto3-wire.nix { };
proto3-suite =
pkgsNew.haskell.lib.dontCheck
(haskellPackagesNew.callPackage ./nix/proto3-suite.nix {});
grpc-haskell-core =
pkgsNew.haskell.lib.buildFromSdist (pkgsNew.usesGRPC
(haskellPackagesNew.callCabal2nix "grpc-haskell-core" ./core {
gpr = pkgsNew.grpc;
}
)
);
grpc-haskell-no-tests =
pkgsNew.haskell.lib.buildFromSdist (pkgsNew.usesGRPC
(pkgsNew.haskell.lib.dontCheck
(haskellPackagesNew.callCabal2nix "grpc-haskell" ./. { })
));
grpc-haskell =
pkgsNew.usesGRPC
(pkgsNew.haskell.lib.overrideCabal
(pkgsNew.haskell.lib.buildFromSdist (haskellPackagesNew.callCabal2nix "grpc-haskell" ./. { }))
(oldDerivation:
let
ghc =
haskellPackagesNew.ghcWithPackages (pkgs: [
pkgs.grpc-haskell-no-tests
# Include some additional packages in this custom ghc for
# running tests in the nix-shell environment.
pkgs.tasty-quickcheck
pkgs.turtle
]);
python = pkgsNew.python.withPackages (pkgs: [
pkgs.grpcio-tools
]);
in {
configureFlags = (oldDerivation.configureFlags or []) ++ [
"--flags=with-examples"
];
buildDepends = (oldDerivation.buildDepends or [ ]) ++ [
pkgsNew.makeWrapper
# Give our nix-shell its own cabal so we don't pick up one
# from the user's environment by accident.
haskellPackagesNew.cabal-install
# And likewise for c2hs
haskellPackagesNew.c2hs
];
patches =
(oldDerivation.patches or [ ]) ++ [ ./tests/tests.patch ];
postPatch = (oldDerivation.postPatch or "") + ''
patchShebangs tests
substituteInPlace tests/simple-client.sh \
--replace @makeWrapper@ ${pkgsNew.makeWrapper} \
--replace @grpc@ ${pkgsNew.grpc}
substituteInPlace tests/simple-server.sh \
--replace @makeWrapper@ ${pkgsNew.makeWrapper} \
--replace @grpc@ ${pkgsNew.grpc}
wrapProgram tests/protoc.sh \
--prefix PATH : ${python}/bin
wrapProgram tests/test-client.sh \
--prefix PATH : ${python}/bin
wrapProgram tests/test-server.sh \
--prefix PATH : ${python}/bin
wrapProgram tests/simple-client.sh \
--prefix PATH : ${ghc}/bin
wrapProgram tests/simple-server.sh \
--prefix PATH : ${ghc}/bin
'';
shellHook = (oldDerivation.shellHook or "") + ''
# This lets us use our custom ghc and python environments in the shell.
export PATH=${ghc}/bin:${python}/bin''${PATH:+:}$PATH
'';
})
);
};
};
test-grpc-haskell =
pkgsNew.mkShell {
nativeBuildInputs = [
(pkgsNew.haskellPackages.ghcWithPackages (pkgs: [
pkgs.grpc-haskell
]
)
)
];
};
usesGRPC = haskellPackage:
# On Linux, LD_LIBRARY_PATH needs to be set for loading
# grpc-haskell{-,core} code into `ghci` from within `nix-shell`
# environments.
#
# TODO: We might try using pkgsNew.fixDarwinDylibNames (see PR#129)
# instead of setting DYLD_LIBRARY_PATH, but we might still need them
# around for `ghci` as on Linux.
pkgsNew.haskell.lib.overrideCabal haskellPackage (oldAttributes: {
preBuild = (oldAttributes.preBuild or "") +
pkgsNew.lib.optionalString pkgsNew.stdenv.isDarwin ''
export DYLD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH
'';
shellHook = (oldAttributes.shellHook or "") +
pkgsNew.lib.optionalString pkgsNew.stdenv.isDarwin ''
export DYLD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH
'' +
pkgsNew.lib.optionalString pkgsNew.stdenv.isLinux ''
export LD_LIBRARY_PATH=${pkgsNew.grpc}/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
'';
}
);
};
overlays = [ overlay ];
config = { };
nixpkgs = import ./nixpkgs.nix;
linuxPkgs = nixpkgs { inherit config overlays; system = "x86_64-linux" ; };
darwinPkgs = nixpkgs { inherit config overlays; system = "x86_64-darwin"; };
pkgs = nixpkgs { inherit config overlays; };
in
{
grpc-haskell-core-linux = linuxPkgs.haskellPackages.grpc-haskell-core;
grpc-haskell-core-darwin = darwinPkgs.haskellPackages.grpc-haskell-core;
grpc-haskell-core = pkgs.haskellPackages.grpc-haskell-core;
grpc-haskell-linux = linuxPkgs.haskellPackages.grpc-haskell;
grpc-haskell-darwin = darwinPkgs.haskellPackages.grpc-haskell;
grpc-haskell = pkgs.haskellPackages.grpc-haskell;
grpc-haskell-no-tests = pkgs.haskellPackages.grpc-haskell-no-tests;
grpc-linux = linuxPkgs.grpc;
grpc-darwin = darwinPkgs.grpc;
grpc = pkgs.grpc;
inherit pkgs config overlay;
inherit (pkgs) test-grpc-haskell;
}