forked from Plutonomicon/cardano-transaction-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
481 lines (432 loc) · 16.5 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
{
description = "cardano-transaction-lib";
nixConfig.bash-prompt = "\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]CTL@\\[\\033[33m\\]$(git rev-parse --abbrev-ref HEAD) \\[\\e[0;32m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
inputs = {
nixpkgs.follows = "ogmios/nixpkgs";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
ogmios.url = "github:mlabs-haskell/ogmios/a7687bc03b446bc74564abe1873fbabfa1aac196";
kupo-nixos.url = "github:mlabs-haskell/kupo-nixos/6f89cbcc359893a2aea14dd380f9a45e04c6aa67";
kupo-nixos.inputs.kupo.follows = "kupo";
kupo = {
url = "github:CardanoSolutions/kupo/v2.2.0";
flake = false;
};
# ogmios nixos module (remove and replace with the above after merging and updating)
ogmios-nixos.url = "github:mlabs-haskell/ogmios";
cardano-node.follows = "ogmios-nixos/cardano-node";
# for new environments like preview and preprod. TODO: remove this when cardano-node is updated
iohk-nix-environments.url = "github:input-output-hk/iohk-nix";
cardano-node.inputs.iohkNix.follows = "iohk-nix-environments";
# Repository with network parameters
cardano-configurations = {
# Override with "path:/path/to/cardano-configurations";
url = "github:input-output-hk/cardano-configurations";
flake = false;
};
easy-purescript-nix = {
url = "github:justinwoo/easy-purescript-nix/da7acb2662961fd355f0a01a25bd32bf33577fa8";
flake = false;
};
# TODO use a tag for blockfrost as soon as they tag a recent commit (we need it as a flake)
blockfrost.url = "github:blockfrost/blockfrost-backend-ryo/49269a9adb27b370209a61de2f5407945112860a";
db-sync.url = "github:input-output-hk/cardano-db-sync/13.1.0.0";
# Plutip server related inputs
plutip.url = "github:mlabs-haskell/plutip/89cf822c213f6a4278a88c8a8bb982696c649e76";
plutip-nixpkgs.follows = "plutip/nixpkgs";
haskell-nix.url = "github:mlabs-haskell/haskell.nix";
iohk-nix = {
follows = "plutip/iohk-nix";
flake = false;
};
CHaP = {
url = "github:input-output-hk/cardano-haskell-packages?ref=repo";
flake = false;
};
};
outputs =
{ self
, nixpkgs
, cardano-configurations
, ...
}@inputs:
let
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
perSystem = nixpkgs.lib.genAttrs supportedSystems;
mkNixpkgsFor = system: import nixpkgs {
overlays = nixpkgs.lib.attrValues self.overlays ++ [
(_: _: {
ogmios-fixtures = inputs.ogmios;
})
];
inherit system;
};
inherit (import ./nix/runtime.nix { inherit inputs; })
buildCtlRuntime launchCtlRuntime;
allNixpkgs = perSystem mkNixpkgsFor;
nixpkgsFor = system: allNixpkgs.${system};
buildOgmiosFixtures = pkgs: pkgs.runCommand "ogmios-fixtures"
{
buildInputs = [ pkgs.jq pkgs.pcre ];
}
''
cp -r ${pkgs.ogmios-fixtures}/server/test/vectors vectors
chmod -R +rwx .
function on_file () {
local path=$1
local parent="$(basename "$(dirname "$path")")"
if command=$(pcregrep -o1 -o2 -o3 'Query\[(.*)\]|(EvaluateTx)|(SubmitTx)' <<< "$path")
then
echo "$path"
json=$(jq -c .result "$path")
md5=($(md5sum <<< "$json"))
printf "%s" "$json" > "ogmios/$command-$md5.json"
fi
}
export -f on_file
mkdir ogmios
find vectors/ -type f -name "*.json" -exec bash -c 'on_file "{}"' \;
mkdir $out
cp -rT ogmios $out
'';
psProjectFor = pkgs:
let
projectName = "cardano-transaction-lib";
# `filterSource` will still trigger rebuilds with flakes, even if a
# filtered path is modified as the output path name is impurely
# derived. Setting an explicit `name` with `path` helps mitigate this
src = builtins.path {
path = self;
name = "${projectName}-src";
filter = path: ftype:
!(pkgs.lib.hasSuffix ".md" path)
&& !(ftype == "directory" && builtins.elem
(baseNameOf path) [ "doc" ]
);
};
ogmiosFixtures = buildOgmiosFixtures pkgs;
project = pkgs.purescriptProject {
inherit src pkgs projectName;
packageJson = ./package.json;
packageLock = ./package-lock.json;
shell = {
withRuntime = true;
shellHook = exportOgmiosFixtures;
packageLockOnly = true;
packages = with pkgs; [
arion
fd
nixpkgs-fmt
nodePackages.eslint
nodePackages.prettier
blockfrost-backend-ryo
];
};
};
exportOgmiosFixtures =
''
export OGMIOS_FIXTURES="${ogmiosFixtures}"
'';
in
rec {
packages = {
ctl-example-bundle-web = project.bundlePursProject {
main = "Ctl.Examples.ByUrl";
entrypoint = "examples/index.js";
};
ctl-runtime = pkgs.arion.build {
inherit pkgs;
modules = [ (buildCtlRuntime pkgs { }) ];
};
docs = project.buildSearchablePursDocs {
packageName = projectName;
};
};
checks = {
ctl-e2e-test = project.runE2ETest {
name = "ctl-e2e-test";
testMain = "Test.Ctl.E2E";
env = { OGMIOS_FIXTURES = "${ogmiosFixtures}"; };
buildInputs = [ inputs.kupo-nixos.packages.${pkgs.system}.kupo ];
};
ctl-plutip-test = project.runPlutipTest {
name = "ctl-plutip-test";
testMain = "Test.Ctl.Plutip";
env = { OGMIOS_FIXTURES = "${ogmiosFixtures}"; };
};
ctl-staking-test = project.runPlutipTest {
name = "ctl-staking-test";
testMain = "Test.Ctl.Plutip.Staking";
};
ctl-unit-test = project.runPursTest {
name = "ctl-unit-test";
testMain = "Test.Ctl.Unit";
env = { OGMIOS_FIXTURES = "${ogmiosFixtures}"; };
};
};
devShell = project.devShell;
apps = {
docs = project.launchSearchablePursDocs {
builtDocs = packages.docs;
};
};
};
plutipServerFor = system:
let
pkgs = import inputs.plutip-nixpkgs {
inherit system;
overlays = [
inputs.haskell-nix.overlay
(import "${inputs.iohk-nix}/overlays/crypto")
];
};
in
import ./plutip-server {
inherit pkgs;
inherit (inputs) plutip CHaP iohk-nix;
inherit (pkgs) system;
src = ./plutip-server;
};
in
{
overlay = builtins.trace
(
"warning: `cardano-transaction-lib.overlay` is deprecated and will be"
+ " removed in the next release. Please use"
+ " `cardano-transaction-lib.overlays.{runtime, purescript}`"
+ " directly instead"
)
nixpkgs.lib.composeManyExtensions
(nixpkgs.lib.attrValues self.overlays);
overlays = with inputs; {
purescript = final: prev: {
easy-ps = import inputs.easy-purescript-nix { pkgs = final; };
purescriptProject = import ./nix { pkgs = final; };
};
spago = final: prev: {
easy-ps = prev.easy-ps // {
spago = prev.easy-ps.spago.overrideAttrs (_: rec {
version = "0.20.7";
src =
if final.stdenv.isDarwin
then
final.fetchurl
{
url = "https://github.com/purescript/spago/releases/download/${version}/macOS.tar.gz";
sha256 = "0s5zgz4kqglsavyh7h70zmn16vayg30alp42w3nx0zwaqkp79xla";
}
else
final.fetchurl {
url = "https://github.com/purescript/spago/releases/download/${version}/Linux.tar.gz";
sha256 = "0bh15dr1fg306kifqipnakv3rxab7hjfpcfzabw7vmg0gsfx8xka";
};
});
};
};
runtime =
(
final: prev:
let
inherit (prev) system;
in
{
plutip-server =
(plutipServerFor system).hsPkgs.plutip-server.components.exes.plutip-server;
ogmios = ogmios.packages.${system}."ogmios:exe:ogmios";
kupo = inputs.kupo-nixos.packages.${system}.kupo;
cardano-db-sync = inputs.db-sync.packages.${system}.cardano-db-sync;
blockfrost-backend-ryo = inputs.blockfrost.packages.${system}.blockfrost-backend-ryo;
buildCtlRuntime = buildCtlRuntime final;
launchCtlRuntime = launchCtlRuntime final;
inherit cardano-configurations;
}
);
};
# flake from haskell.nix project
hsFlake = perSystem (system: (plutipServerFor system).flake { });
devShells = perSystem (system: {
# This is the default `devShell` and can be run without specifying
# it (i.e. `nix develop`)
default = (psProjectFor (nixpkgsFor system)).devShell;
# This can be used with `nix develop .#hsDevShell
hsDevShell = self.hsFlake.${system}.devShell;
});
packages = perSystem (system:
(psProjectFor (nixpkgsFor system)).packages
// ((plutipServerFor system).flake { }).packages
);
apps = perSystem (system:
let
pkgs = nixpkgsFor system;
in
(psProjectFor pkgs).apps // {
ctl-runtime = pkgs.launchCtlRuntime { };
ctl-runtime-blockfrost = pkgs.launchCtlRuntime { blockfrost.enable = true; };
default = self.apps.${system}.ctl-runtime;
vm = {
type = "app";
program =
"${self.nixosConfigurations.test.config.system.build.vm}/bin/run-nixos-vm";
};
});
# TODO
# Add a check that attempts to verify if the scaffolding template is
# reasonably up-to-date. See:
# https://github.com/Plutonomicon/cardano-transaction-lib/issues/839
checks = perSystem (system:
let
pkgs = nixpkgsFor system;
in
(psProjectFor pkgs).checks
// {
formatting-check = pkgs.runCommand "formatting-check"
{
nativeBuildInputs = with pkgs; [
easy-ps.purs-tidy
nixpkgs-fmt
nodePackages.prettier
nodePackages.eslint
fd
];
}
''
cd ${self}
make check-format
touch $out
'';
template-deps-json = pkgs.runCommand "template-deps-check"
{
ctlPackageJson = builtins.readFile ./package.json;
ctlScaffoldPackageJson = builtins.readFile ./templates/ctl-scaffold/package.json;
nativeBuildInputs = [ pkgs.jq ];
} ''
cd ${self}
diff <(jq -S .dependencies <<< $ctlPackageJson) <(jq -S .dependencies <<< $ctlScaffoldPackageJson)
# We don't want to include `doctoc` in the template dev dependencies.
diff \
<(jq -S '.devDependencies | del(.doctoc)' <<< $ctlPackageJson) \
<(jq -S .devDependencies <<< $ctlScaffoldPackageJson)
touch $out
'';
template-dhall-diff = pkgs.runCommand "template-dhall-diff-check"
(with builtins;
let
ctlPkgsExp = import ./spago-packages.nix { inherit pkgs; };
ctlScaffoldPkgsExp = import ./templates/ctl-scaffold/spago-packages.nix { inherit pkgs; };
ctlPs = attrValues ctlPkgsExp.inputs;
ctlScaffoldPs = filter (p: p.name != "cardano-transaction-lib")
(attrValues ctlScaffoldPkgsExp.inputs);
intersection = pkgs.lib.lists.intersectLists ctlPs ctlScaffoldPs;
scaffoldDisjoint = pkgs.lib.lists.subtractLists intersection ctlScaffoldPs;
ctlDisjoint = pkgs.lib.lists.subtractLists intersection ctlPs;
in
{
inherit ctlDisjoint scaffoldDisjoint;
nativeBuildInputs = [ ];
}
) ''
if [ -z "$ctlDisjoint" ] && [ -z "$scaffoldDisjoint" ];
then
touch $out
else
if [ -n "$ctlDisjoint" ];
then
echo "The following packages are in the main projects dependencies but not in the scaffold:"
for p in $ctlDisjoint; do
echo " $p"
done
fi
if [ -n "$scaffoldDisjoint" ];
then
echo "The following packages are in the scaffold projects dependencies but not in the main:"
for p in $scaffoldDisjoint; do
echo " $p"
done
fi
exit 1
fi
'';
template-version = pkgs.runCommand "template-consistent-version-check"
(
let
ctlScaffoldPackages = import ./templates/ctl-scaffold/spago-packages.nix { inherit pkgs; };
ctlScaffoldFlake = import ./templates/ctl-scaffold/flake.nix;
versionCheck = ctlScaffoldPackages.inputs."cardano-transaction-lib".version == ctlScaffoldFlake.inputs.ctl.rev;
in
{
packagesLibRev = ctlScaffoldPackages.inputs."cardano-transaction-lib".version;
flakeLibRev = ctlScaffoldFlake.inputs.ctl.rev;
nativeBuildInputs = [ ];
}
) ''
if [ $packagesLibRev != $flakeLibRev ]
then
echo "CTL revision in scaffold flake.nix ($flakeLibRev) doesn't match revision referenced in spago-packages.nix ($packagesLibRev). Please update flake.nix or packages.dhall and run spago2nix."
exit 1
fi
touch $out
'';
examples-imports-check = pkgs.runCommand "examples-imports-check" { }
''
cd ${self}
make check-examples-imports
touch $out
'';
});
templatePath = builtins.toString self + self.templates.ctl-scaffold.path;
check = perSystem (system:
(nixpkgsFor system).runCommand "combined-check"
{
combined =
builtins.attrValues self.checks.${system}
++ builtins.attrValues self.packages.${system};
}
''
echo $combined
touch $out
''
);
templates = {
default = self.templates.ctl-scaffold;
ctl-scaffold = {
path = ./templates/ctl-scaffold;
description = "A minimal CTL-based scaffold project";
welcomeText = ''
Welcome to your new CTL project!
To enter the Nix environment and start working on it, run `nix develop`
Please also see our
- [Documentation](https://github.com/Plutonomicon/cardano-transaction-lib/tree/develop/doc)
- [Generated docs](https://plutonomicon.github.io/cardano-transaction-lib/)
- [Discord server](https://discord.gg/JhbexnV9Pc)
If you encounter problems and/or want to report a bug, you can open
an issue [here](https://github.com/Plutonomicon/cardano-transaction-lib/issues).
Please search for existing issues beforehand!
'';
};
};
nixosConfigurations.test = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
inputs.cardano-node.nixosModules.cardano-node
inputs.ogmios-nixos.nixosModules.ogmios
{
services.ogmios.package =
inputs.ogmios.packages.x86_64-linux."ogmios:exe:ogmios";
}
inputs.kupo-nixos.nixosModules.kupo
./nix/test-nixos-configuration.nix
];
specialArgs = {
inherit (inputs) cardano-configurations;
};
};
herculesCI.ciSystems = [ "x86_64-linux" ];
};
}