forked from fluffynukeit/adaspark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
339 lines (295 loc) · 8.3 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
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
{
description = "Compilers and tools for SPARK2014 Ada development";
inputs.nixpkgs.url = "github:nixos/nixpkgs/20.09";
outputs = { self, nixpkgs }:
with import nixpkgs {
system = "x86_64-linux";
};
let
python = python27;
pythonPackages = python27Packages;
# Customized environment supporting gprbuild search paths.
base_env = gcc10Stdenv;
mk_gpr_path = inputs :
lib.strings.makeSearchPath "share/gpr" inputs
+ ":" +
lib.strings.makeSearchPath "lib/gnat" inputs;
adaenv_func = include_gprbuild : let
maybe_gpr = if include_gprbuild then [gprbuild] else [];
core = (overrideCC base_env gnat10).override {
name="adaenv" + (if include_gprbuild then "-boot" else "");
initialPath = base_env.initialPath ++ maybe_gpr;
};
in
core // { # use modified mkDerivation function
mkDerivation = params :
assert lib.asserts.assertMsg (params ? name)
"Attribute 'name' of derivation must be specified!"; let
new_params = params // {
# Fix crti.o linker error
LIBRARY_PATH = params.LIBRARY_PATH or "${adaenv.glibc}/lib";
# Find installed gpr projects in nix store. Consult
# GPR manual for search path order
GPR_PROJECT_PATH = mk_gpr_path ((new_params.buildInputs or []) ++ maybe_gpr);
};
in core.mkDerivation new_params;
};
adaenv_boot = adaenv_func false; # does not include gprbuild by default
adaenv = adaenv_func true; # does include gprbuild by default
# xmlada library needed for gprbuild. Built with bootstrap.
xmladasrc = fetchFromGitHub {
owner = "AdaCore";
repo = "xmlada";
rev = "4aca7578264b3d42d9629a7437705a3b62c6fa04"; # version 20.2
sha256 = "sha256-aBfhmnbzJxdqdItVM6dn29C5JYE8jMhpBYjYv+RQA40=";
};
xmlada = adaenv_boot.mkDerivation {
name = "xmlada";
version = "20.2";
buildInputs = [
gprbuild-bootstrap
];
src = xmladasrc;
configurePhase = ''
./configure --prefix=$prefix --enable-build=Production
'';
buildPhase = ''
make all
'';
installPhase = ''
make install
'';
};
# gprbuild tool
gprbuildsrc = fetchFromGitHub {
owner = "AdaCore";
repo = "gprbuild";
rev = "245ee13c5cd384dc3cea10a49a5e6a07042e49e1"; # version 20.2
sha256 = "sha256-wAnDQXyg0vR3TfsKtfvYnDZ1CnX+1ZRRQi7XwOTckNo=";
};
gprconfig_kbsrc = fetchFromGitHub {
owner = "AdaCore";
repo = "gprconfig_kb";
rev = "94abfa8bb8da6457ac0288907a817f691d00f74e"; # version 20.2
sha256 = "sha256-S+iH0h50o6HdoSDf+8SQ5Fe3IOf/AGEe46fyfdnKsIk=";
};
gprbuild-bootstrap = adaenv_boot.mkDerivation {
name = "gprbuild-bootstrap";
version = "20.2";
src = gprbuildsrc;
patchPhase = "
patchShebangs ./bootstrap.sh
";
dontConfigure = true;
dontBuild = true;
installPhase = ''
./bootstrap.sh \
--with-xmlada="${xmladasrc}" \
--prefix=$prefix
'';
};
gprbuild = adaenv_boot.mkDerivation {
name = "gprbuild";
version = "20.2";
buildInputs = [
gprbuild-bootstrap
xmlada
which
];
src = gprbuildsrc;
configurePhase = ''
make prefix=$prefix BUILD=production setup
'';
buildPhase = ''
make all libgpr.build
'';
installPhase = ''
make install libgpr.install
mkdir -p $out/share/gprconfig
cp ${gprconfig_kbsrc}/db/* $out/share/gprconfig/
'';
};
# gnatcoll-core
gnatcoll-coresrc = fetchFromGitHub {
owner = "AdaCore";
repo = "gnatcoll-core";
rev = "d71d4fce1438dd645c546892a8c8a6a5e65a856d"; # version 20.2
sha256 = "sha256-yEGj9ku3o+BOH8BwA/SuLsLCr/CcWdEdzzdrtOsy1wg=";
};
gnatcoll-core = adaenv.mkDerivation {
name = "gnatcoll-core";
version = "20.2";
buildInputs = [
xmlada
];
src = gnatcoll-coresrc;
configurePhase = ''
make prefix=$prefix BUILD=PROD setup
'';
};
# Spark2014 tools
sparksrc = fetchFromGitHub {
owner = "AdaCore";
repo = "spark2014";
rev = "d846b3d10503db9567a509bff2982366d8caa131"; # 20.2, to match gcc 10.2
sha256 = "sha256-SaJ8nGGn21dtHIsE02GslefUaYZG7JX//o7rB+AsndM=";
fetchSubmodules = true;
};
gnatsrc = adaenv.cc.cc.src;
spark2014 = adaenv.mkDerivation {
name = "SPARK2014";
version = "20.2";
buildInputs = [
ocaml
ocamlPackages.ocamlgraph
ocamlPackages.menhir
ocamlPackages.zarith
ocamlPackages.camlzip
ocamlPackages.ocplib-simplex
ocamlPackages.findlib
ocamlPackages.num
gnatcoll-core
python
pythonPackages.sphinx
xmlada
];
srcs = [
sparksrc
gnatsrc # need to list here to get local uncompressed copy
];
sourceRoot = "source";
configurePhase = ''
ln -s ../../gcc-10.2.0/gcc/ada gnat2why/gnat_src \
&& make setup
'';
installPhase = ''
make install-all
cp -a ./install/. $out
'';
};
# ASIS tools like gnattest, gnatcheck, etc.
aunitsrc = fetchFromGitHub {
owner = "AdaCore";
repo = "aunit";
rev = "5a4c3255af756177aead3ff89b2278a1a47009e4"; # tag 20.2
sha256 = "sha256-45hevx+oUiZLKER3cZF4FHJT5IFOKMKsY7L8u8rDa+E=";
};
aunit = adaenv.mkDerivation {
name = "AUnit";
version = "20.2";
src = aunitsrc;
installPhase = ''
make INSTALL=$prefix install
'';
};
gnat_utilsrc = fetchFromGitHub {
owner = "simonjwright";
repo = "gnat_util";
rev = "7e5af8f4365b49cd39b1e7de5fd3c6eb71b989e2";
sha256 = "sha256-Pz2B/W3FRN6zwOk6MXNuHKDa3539/wshZuFDjtrdZ18="; # gcc 10.1.0
};
gnat_util = adaenv.mkDerivation {
name = "gnat_util";
version = "10.1.0";
srcs = [
gnat_utilsrc
gnatsrc # list here to get local uncompressed copy
];
sourceRoot = "source";
GCC_SRC_BASE="gcc-10.2.0";
installPhase = ''
make prefix=$prefix install
'';
};
asis = adaenv.mkDerivation {
name = "ASIS";
version = "gcc-10.1.0";
src = fetchFromGitHub {
owner = "simonjwright";
repo = "asis";
rev = "75eabc75aa5f7f1559524153f209601574f32b5c"; # gcc-10.1 tag
sha256 = "sha256-26kmPF8uksCOHc5yqJZ8DW7rS56fClff5cIMj0x5+MI=";
# The asis distribution must include source code that matches the
# version of gcc used.
};
buildInputs = [
xmlada
aunit
gnat_util
gnatcoll-core
];
postUnpack = ''
make -C source xsetup-snames
cp -nr source/gnat/* source/asis/
'';
buildPhase = ''
make all tools
'';
installPhase = ''
make prefix=$prefix install install-tools
'';
};
alire = adaenv.mkDerivation rec {
name = "alire";
# v1.0.0 failed to fetch submodules, so using current HEAD
version = "1.1.0-dev+0f603c29";
src = fetchFromGitHub {
owner = "alire-project";
repo = "alire";
rev = "c63615df9bed6212881f61d769ab189b3f425a8b";
sha256 = "sha256-bs1myX6Qgsdp/RU9FvOaDJ6nB9gsa0oDsNjwYctP/Dw=";
fetchSubmodules = true;
};
buildInputs = [ gprbuild git ];
buildPhase = ''
gprbuild -j0 -P alr_env
'';
installPhase = ''
install -D bin/alr $out/bin/alr
'';
};
in
# HERE BEGINS THE THINGS THAT THIS FLAKE PROVIDES:
{
# Derivations (create an environment with `nix shell`)
inherit xmlada gnatcoll-core asis gnat_util aunit;
gpr = gprbuild;
gnat = adaenv.cc;
spark = spark2014;
alr = alire;
# Notes on nix shell and nix develop:
# "nix develop" will open a shell environment that simulates the build environment
# for the specified derivation, with default being devShell if it is defined, and
# defaultPackage if it is not. If the the derivation has a shellHook, it will be
# run. However, buildEnv is not allowed to have a shellHook for some reason. The
# derivation can be a buildable package (including buildEnv) or not like mkShell.
#
# "nix shell" will open a shell environment with the specified *packages* installed
# on the PATH. The default is defaultPackage. devShell is not used. shellHooks will
# not be run. A mkShell invocation cannot be installed, so it cannot be used with
# nix shell.
adaspark = buildEnv {
name = "adaspark";
paths = [
self.gnat
gnat10.cc # need the original compiler on the path for gprconfig to work
self.gpr
self.spark
self.asis
self.alr
];
};
packages.x86_64-linux = {
inherit (self) xmlada gnatcoll-core gnat gpr spark adaspark gnat_util aunit asis;
};
defaultPackage.x86_64-linux = self.packages.x86_64-linux.adaspark;
devShell.x86_64-linux = mkShell {
buildInputs = [self.adaspark];
LIBRARY_PATH=self.gpr.LIBRARY_PATH; # pull out any LIBRARY_PATH from a adaenv derivation
};
# End derivations
# Put the adaenv function in the flake so other users can download it and use its
# mkDerivation function and other features.
inherit adaenv fetchFromGitHub fetchgit fetchtarball;
};
}