-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
305 lines (263 loc) · 9.08 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
{
description = "singularitynet";
nixConfig.bash-prompt = "\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]singularitynet \\[\\e[0;93m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
inputs = {
nixpkgs.follows = "ctl/nixpkgs";
haskell-nix.follows = "ctl/haskell-nix";
plutip.url = "github:mlabs-haskell/plutip?rev=0b92bb7b913d213457713c09bacae06110c47bac";
plutarch.url = "github:CardaxDEX/plutarch?rev=e5a50283a0cb01ce1fee880943becda1ac19f3a0";
plutarch.inputs.haskell-nix.follows = "plutip/haskell-nix";
plutarch.inputs.nixpkgs.follows = "plutip/nixpkgs";
ctl = {
type = "github";
owner = "Plutonomicon";
repo = "cardano-transaction-lib";
# NOTE
# Keep this in sync with the rev in `frontend/packages.dhall`
rev = "16b9dea9c81d49a59f44d622653d3afc06ef2972";
};
};
outputs =
inputs@{ self
, nixpkgs
, haskell-nix
, plutarch
, plutip
, ctl
, ...
}:
let
# GENERAL
supportedSystems = with nixpkgs.lib.systems.supported; tier1 ++ tier2 ++ tier3;
perSystem = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = system: import nixpkgs {
inherit system;
overlays = [ haskell-nix.overlay (import "${plutip.inputs.iohk-nix}/overlays/crypto") ];
inherit (haskell-nix) config;
};
nixpkgsFor' = system: import nixpkgs {
inherit system;
overlays = [ ctl.overlay ];
};
formatCheckFor = system:
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
in
pkgs.runCommand "format-check"
{
nativeBuildInputs = [
pkgs'.git
pkgs'.fd
pkgs'.haskellPackages.cabal-fmt
pkgs'.nixpkgs-fmt
(pkgs.haskell-nix.tools onchain.ghcVersion { inherit (plutarch.tools) fourmolu; }).fourmolu
];
} ''
export LC_CTYPE=C.UTF-8
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
cd ${self}
make format_check
mkdir $out
''
;
deferPluginErrors = true;
# ONCHAIN / Plutarch
onchain = rec {
ghcVersion = "ghc921";
projectFor = system:
let pkgs = nixpkgsFor system; in
let pkgs' = nixpkgsFor' system; in
(nixpkgsFor system).haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = ghcVersion;
cabalProjectFileName = "cabal.project.onchain";
inherit (plutarch) cabalProjectLocal;
extraSources = plutarch.extraSources ++ [
{
src = inputs.plutarch;
subdirs = [ "." ];
}
];
modules = [ (plutarch.haskellModule system) ];
shell = {
withHoogle = true;
exactDeps = true;
# We use the ones from Nixpkgs, since they are cached reliably.
# Eventually we will probably want to build these with haskell.nix.
nativeBuildInputs = [
pkgs'.cabal-install
pkgs'.fd
pkgs'.haskellPackages.apply-refact
pkgs'.haskellPackages.cabal-fmt
pkgs'.hlint
pkgs'.nixpkgs-fmt
];
inherit (plutarch) tools;
additional = ps: [
ps.plutarch
ps.tasty-quickcheck
];
shellHook = ''
export NIX_SHELL_TARGET="onchain"
ln -fs cabal.project.onchain cabal.project
'';
};
};
};
# OFFCHAIN / Testnet, Cardano, ...
offchain = rec {
ghcVersion = "ghc8107";
projectFor = system:
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
plutipin = inputs.plutip.inputs;
fourmolu = pkgs.haskell-nix.tool "ghc921" "fourmolu" { };
project = pkgs.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = ghcVersion;
inherit (plutip) cabalProjectLocal;
cabalProjectFileName = "cabal.project.offchain";
extraSources = plutip.extraSources ++ [
{
src = "${plutip}";
subdirs = [ "." ];
}
];
modules = [
({ config, ... }: {
packages.singularitynet-offchain.components.tests.singularitynet-offchain-test.build-tools = [
project.hsPkgs.cardano-cli.components.exes.cardano-cli
project.hsPkgs.cardano-node.components.exes.cardano-node
];
})
] ++ plutip.haskellModules;
shell = {
withHoogle = true;
exactDeps = true;
# We use the ones from Nixpkgs, since they are cached reliably.
# Eventually we will probably want to build these with haskell.nix.
nativeBuildInputs = [
pkgs'.cabal-install
pkgs'.fd
pkgs'.haskellPackages.apply-refact
pkgs'.haskellPackages.cabal-fmt
pkgs'.hlint
pkgs'.nixpkgs-fmt
project.hsPkgs.cardano-cli.components.exes.cardano-cli
project.hsPkgs.cardano-node.components.exes.cardano-node
fourmolu
];
tools.haskell-language-server = { };
additional = ps: [ ps.plutip ];
shellHook = ''
export NIX_SHELL_TARGET="offchain"
ln -fs cabal.project.offchain cabal.project
'';
};
};
in
project;
};
frontend = {
projectFor = system:
let
pkgs = nixpkgsFor' system;
src = ./frontend;
project = pkgs.purescriptProject {
inherit src;
projectName = "singularitynet-frontend";
packageJson = ./frontend/package.json;
packageLock = ./frontend/package-lock.json;
nodejs = pkgs.nodejs-14_x;
shell.packages = [ pkgs.fd ];
};
in
{
flake = {
packages = {
frontend-bundle-web = project.bundlePursProject {
main = "Main";
};
};
apps = {
frontend-runtime = pkgs.launchCtlRuntime { };
};
checks = {
frontend = project.runPursTest {
testMain = "Test.Main";
};
format-check = pkgs.runCommand "formatting-check"
{
nativeBuildInputs = [
pkgs.easy-ps.purs-tidy
pkgs.fd
];
}
''
cd ${src}
purs-tidy check $(fd -epurs)
touch $out
'';
};
devShell = project.devShell;
};
};
};
in
{
inherit nixpkgsFor;
onchain = {
project = perSystem onchain.projectFor;
flake = perSystem (system: (onchain.projectFor system).flake { });
};
offchain = {
project = perSystem offchain.projectFor;
flake = perSystem (system: (offchain.projectFor system).flake { });
};
frontend = {
flake = perSystem (system: (frontend.projectFor system).flake);
};
packages = perSystem (system:
self.onchain.flake.${system}.packages
// self.offchain.flake.${system}.packages
// self.frontend.flake.${system}.packages
);
apps = perSystem (system: self.frontend.flake.${system}.apps);
checks = perSystem (system:
self.onchain.flake.${system}.checks
// self.offchain.flake.${system}.checks
// self.frontend.flake.${system}.checks # includes formatting check as well
// {
formatCheck = formatCheckFor system;
}
);
check = perSystem (system:
(nixpkgsFor system).runCommand "combined-test"
{
checksss =
builtins.attrValues self.checks.${system}
++ builtins.attrValues self.packages.${system}
++ [
self.devShells.${system}.onchain.inputDerivation
self.devShells.${system}.offchain.inputDerivation
self.devShells.${system}.frontend.inputDerivation
];
} ''
echo $checksss
touch $out
''
);
devShells = perSystem (system: {
onchain = self.onchain.flake.${system}.devShell;
offchain = self.offchain.flake.${system}.devShell;
frontend = self.frontend.flake.${system}.devShell;
});
hydraJobs = perSystem (system:
self.checks.${system} // {
inherit (self.packages.${system}) frontend-bundle-web;
});
};
}