forked from Plutonomicon/cardano-transaction-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
375 lines (336 loc) · 12.1 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
{
description = "cardano-transaction-lib";
inputs = {
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
# for the purescript project
ogmios = {
url = "github:mlabs-haskell/ogmios/9c04524d45de2c417ddda9e7ab0d587a54954c57";
inputs = {
haskell-nix.follows = "haskell-nix";
nixpkgs.follows = "nixpkgs";
};
};
plutip.url = "github:mlabs-haskell/plutip/8364c43ac6bc9ea140412af9a23c691adf67a18b";
ogmios-datum-cache.url = "github:mlabs-haskell/ogmios-datum-cache/880a69a03fbfd06a4990ba8873f06907d4cd16a7";
# 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/d56c436a66ec2a8a93b309c83693cef1507dca7a";
flake = false;
};
# for the haskell server
iohk-nix.url = "github:input-output-hk/iohk-nix";
haskell-nix.follows = "plutip/haskell-nix";
nixpkgs.follows = "plutip/nixpkgs";
};
outputs =
{ self
, nixpkgs
, haskell-nix
, iohk-nix
, 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 (haskell-nix) config;
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) [ "server" "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
haskellPackages.fourmolu
nixpkgs-fmt
nodePackages.eslint
nodePackages.prettier
];
};
};
exportOgmiosFixtures =
''
export OGMIOS_FIXTURES="${ogmiosFixtures}"
'';
in
rec {
packages = {
ctl-example-bundle-web = project.bundlePursProject {
main = "Examples.ByUrl";
entrypoint = "examples/index.js";
};
ctl-runtime = pkgs.arion.build {
inherit pkgs;
modules = [ (buildCtlRuntime pkgs { }) ];
};
docs = project.buildSearchablePursDocs {
packageName = projectName;
};
};
checks = {
ctl-plutip-test = project.runPlutipTest {
name = "ctl-plutip-test";
testMain = "Test.Plutip";
# After updating `PlutipConfig` this can be set for now:
# withCtlServer = false;
env = { OGMIOS_FIXTURES = "${ogmiosFixtures}"; };
};
ctl-unit-test = project.runPursTest {
name = "ctl-unit-test";
testMain = "Ctl.Test.Unit";
env = { OGMIOS_FIXTURES = "${ogmiosFixtures}"; };
};
};
devShell = project.devShell;
apps = {
docs = project.launchSearchablePursDocs {
builtDocs = packages.docs;
};
};
};
hsProjectFor = pkgs: import ./server/nix {
inherit inputs pkgs;
inherit (pkgs) system;
src = ./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, ctl-server}`"
+ " 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; };
};
# This is separate from the `runtime` overlay below because it is
# optional (it's only required if using CTL's `applyArgs` effect).
# Including it by default in the `overlays.runtime` also requires that
# `prev` include `haskell-nix.overlay` and `iohk-nix.overlays.crypto`;
# this is not ideal to force upon all users
ctl-server = nixpkgs.lib.composeManyExtensions [
(
final: prev:
# if `haskell-nix.overlay` has not been applied, we cannot use the
# package set to build the `hsProjectFor`. We don't want to always
# add haskell.nix's overlay or use the `ctl-server` from our own
# `outputs.packages` because this might lead to conflicts with the
# `hackage.nix` version being used (this might also happen with the
# Ogmios and Plutip packages, but at least we have direct control over
# our own haskell.nix project)
#
# We can check for the necessary attribute and then apply the
# overlay if necessary
nixpkgs.lib.optionalAttrs (!(prev ? haskell-nix))
(haskell-nix.overlay final prev)
)
(
final: prev:
# Similarly, we need to make sure that `libsodium-vrf` is available
# for the Haskell server
nixpkgs.lib.optionalAttrs (!(prev ? libsodium-vrf))
(iohk-nix.overlays.crypto final prev)
)
(
final: prev: {
ctl-server =
(hsProjectFor final).hsPkgs.ctl-server.components.exes.ctl-server;
}
)
];
runtime = nixpkgs.lib.composeManyExtensions [
(
final: prev:
let
inherit (prev) system;
in
{
plutip-server =
inputs.plutip.packages.${system}."plutip:exe:plutip-server";
ogmios-datum-cache =
inputs.ogmios-datum-cache.defaultPackage.${system};
ogmios = ogmios.packages.${system}."ogmios:exe:ogmios";
buildCtlRuntime = buildCtlRuntime final;
launchCtlRuntime = launchCtlRuntime final;
inherit cardano-configurations;
}
)
(
final: prev: nixpkgs.lib.optionalAttrs (!(prev ? ctl-server))
(
builtins.trace
(
"Warning: `ctl-server` has moved to `overlays.ctl-server`"
+ " and will be removed from `overlays.runtime` soon"
)
(self.overlays.ctl-server final prev)
)
)
];
};
# flake from haskell.nix project
hsFlake = perSystem (system: (hsProjectFor (nixpkgsFor 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;
# It might be a good idea to keep this as a separate shell; if you're
# working on the PS frontend, it doesn't make a lot of sense to pull
# in all of the Haskell dependencies
#
# This can be used with `nix develop .#hsDevShell
hsDevShell = self.hsFlake.${system}.devShell;
});
packages = perSystem (system:
self.hsFlake.${system}.packages
// (psProjectFor (nixpkgsFor system)).packages
);
apps = perSystem (system:
let
pkgs = nixpkgsFor system;
in
(psProjectFor pkgs).apps // {
inherit (self.hsFlake.${system}.apps) "ctl-server:exe:ctl-server";
ctl-runtime = pkgs.launchCtlRuntime { };
default = self.apps.${system}.ctl-runtime;
});
# 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
// self.hsFlake.${system}.checks
// {
formatting-check = pkgs.runCommand "formatting-check"
{
nativeBuildInputs = with pkgs; [
easy-ps.purs-tidy
haskellPackages.fourmolu
nixpkgs-fmt
nodePackages.prettier
nodePackages.eslint
fd
];
}
''
cd ${self}
make check-format
touch $out
'';
});
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/c8kZWxzJ)
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!
'';
};
};
hydraJobs = perSystem (system:
self.checks.${system}
// self.packages.${system}
// self.devShells.${system}
);
};
}