forked from input-output-hk/purescript-bridge
-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
251 lines (224 loc) · 8.99 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
{
description = "Generate PureScript data types from Haskell data types";
nixConfig.bash-prompt = "\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]purescript-bridge \\[\\e[0;93m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
inputs = {
haskell-nix.url = "github:mlabs-haskell/haskell.nix/2b4c58932d6c19a0c6b4bcde0a8c0581574c0d25";
flake-utils.url = "github:numtide/flake-utils";
easy-ps = {
url = "github:justinwoo/easy-purescript-nix";
flake = false;
};
# Needed for crypto overlay
iohk-nix = {
url = "github:input-output-hk/iohk-nix";
flake = false;
};
cardano-transaction-lib.url = github:Plutonomicon/cardano-transaction-lib/develop; # path:/<some_local_path>/cardano-transaction-lib;
# We're reusing inputs from bot-plutus-interface as it's currently the source of nix truth.
bot-plutus-interface.url = "github:mlabs-haskell/bot-plutus-interface";
# Our servant-purescript fork
servant-purescript = {
url = "github:mlabs-haskell/servant-purescript";
flake = false;
};
plutus-extra = {
url = "github:Liqwid-Labs/plutus-extra";
flake = false;
};
};
outputs = inputs@{ self, flake-utils, haskell-nix, ... }:
{ herculesCI.ciSystems = [ "x86_64-linux" ]; } //
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
# TODO: Perhaps cleanSource
src = ./.;
# Nixpkgs from bot-plutus-interface
inherit (inputs.bot-plutus-interface.inputs) nixpkgs;
# Reliably cached
pkgs = import nixpkgs { inherit system; };
# # Poor caching due to overlay
pkgs' = import nixpkgs {
overlays =
[ haskell-nix.overlay (import "${inputs.iohk-nix}/overlays/crypto") ];
inherit system;
inherit (haskell-nix) config;
};
easy-ps = import inputs.easy-ps { inherit pkgs; };
# Haskell.nix project and flake
# Filter out purescript-bridge
extraSources' = builtins.filter (e: e.src.rev != "47a1f11825a0f9445e0f98792f79172efef66c00") inputs.bot-plutus-interface.extraSources;
# Use our servant-purescript fork
extraSources'' = builtins.map
(e:
if e.src.rev == "44e7cacf109f84984cd99cd3faf185d161826963"
then { src = inputs.servant-purescript; subdirs = e.subdirs; }
else e)
extraSources';
extraSources =
[
{
src = inputs.plutus-extra;
subdirs = [
"quickcheck-plutus-instances"
];
}
]
++ extraSources'';
haskellProject = import ./nix/haskell.nix {
inherit src system pkgs pkgs' easy-ps extraSources;
rtPurs = roundTripTestPursFlake.packages.roundtrip-test-run-with-node;
};
haskellFlake = haskellProject.flake { };
# Code quality
cq = import ./nix/code-quality.nix { inherit pkgs easy-ps; };
fileCheckers = cq.checkers pkgs;
fileFixers = cq.fixers pkgs;
pursVersion = "purs-0_14_5";
# Generated plutus-ledger-api Purescript typelib
generatedLedgerPursFiles = pkgs.runCommand "generate-plutus-ledger-api-purs-files"
{
cli = haskellProject.getComponent "purescript-bridge:exe:cli";
}
''
mkdir $out
$cli/bin/cli generate-types --generated-dir $out
'';
generatedLedgerTypelib =
let
spago = easy-ps.spago;
ctl = inputs.cardano-transaction-lib;
purs = easy-ps.${pursVersion};
typelibName = "generated-ledger";
in
import ./nix/purescript-bridge.nix ctl {
inherit pkgs purs spago typelibName;
generatedPursFiles = generatedLedgerPursFiles;
};
sampleLedgerTypelib =
let
spago = easy-ps.spago;
ctl = inputs.cardano-transaction-lib;
purs = easy-ps.${pursVersion};
typelibName = "sample-ledger";
in
import ./nix/purescript-bridge.nix ctl {
inherit pkgs purs spago typelibName;
generatedPursFiles = ./generated;
};
# Purescript - Haskell round trip generated typelib
generatedRoundTripPursFiles = pkgs.runCommand "generate-roundtrip-test-purescript-files"
{
cli = haskellProject.getComponent "purescript-bridge:exe:roundtrip";
}
''
mkdir $out
$cli/bin/roundtrip generate-types --generated-dir $out
'';
generatedRoundTripTypelib =
let
spago = easy-ps.spago;
ctl = inputs.cardano-transaction-lib;
purs = easy-ps.${pursVersion};
typelibName = "roundtrip-test";
in
import ./nix/purescript-bridge.nix ctl {
inherit pkgs purs spago typelibName;
generatedPursFiles = generatedRoundTripPursFiles;
};
# Purescript - Haskell round trip test purs flake
roundTripTestPursFlake =
let
inherit pkgs easy-ps;
src = ./roundtrip/RoundTripPurs;
workDir = "./roundtrip/RoundTripPurs";
pursSubDirs = [ "/src" ];
pursSubDirsTest = [ "/test" ];
nodejs = pkgs.nodejs-14_x;
spagoLocalPkgs = [ inputs.cardano-transaction-lib generatedRoundTripTypelib ];
purs = easy-ps.${pursVersion};
projectName = "roundtrip-test";
in
import ./nix/purescript-flake.nix {
inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs
nodejs purs projectName;
};
# purescript-bridge.nix flake
purescriptBridgeNixFlake =
let
inherit pkgs easy-ps;
src = ./nix/purescript-bridge-nix-spago;
workDir = "./nix/purescript-bridge-nix-spago";
pursSubDirs = [ "/src" ];
pursSubDirsTest = [ "/test" ];
nodejs = pkgs.nodejs-14_x;
spagoLocalPkgs = [ inputs.cardano-transaction-lib ];
purs = easy-ps.${pursVersion};
mainModule = "PureScriptBridge.Main";
projectName = "purescript-bridge-nix";
in
import ./nix/purescript-flake.nix {
inherit src workDir pursSubDirs pursSubDirsTest pkgs system easy-ps spagoLocalPkgs
nodejs purs mainModule projectName;
};
in
rec
{
# Useful attributes
inherit pkgs easy-ps haskellProject haskellFlake;
# Flake standard attributes
packages = haskellFlake.packages // purescriptBridgeNixFlake.packages // roundTripTestPursFlake.packages // {
sample-plutus-ledger-api-typelib = sampleLedgerTypelib;
plutus-ledger-api-typelib = generatedLedgerTypelib;
};
checks = haskellFlake.checks // purescriptBridgeNixFlake.checks // roundTripTestPursFlake.checks;
devShells = {
default = roundTripTestPursFlake.devShellComposeWith haskellFlake.devShell;
typelibNix = purescriptBridgeNixFlake.devShell;
};
# Used by CI
build-all = pkgs.runCommand "build-all"
(self.packages.${system} // self.devShells.${system})
"touch $out";
test-all = pkgs.runCommand "check-all"
{
nativeBuildInputs = builtins.attrValues self.checks.${system};
} "touch $out";
# Check files
check-files = pkgs.runCommand "check-files"
({
checks = [
(fileCheckers.checkNixFiles src)
(fileCheckers.checkHaskellFiles src)
(fileCheckers.checkCabalFiles src)
(fileCheckers.checkShellFiles src)
(fileCheckers.checkDhallFiles src)
(fileCheckers.checkPurescriptFiles ./generated)
(fileCheckers.checkPurescriptFiles ./roundtrip/RoundTripPurs)
];
})
"touch $out";
# Fix files
fix-files = cq.makeBundle {
myScriptName = "fix-files";
myScript = ''
${fileFixers.fixNixFiles}/bin/fix-nix-files-bundle $@
${fileFixers.fixHaskellFiles}/bin/fix-haskell-files-bundle $@
${fileFixers.fixCabalFiles}/bin/fix-cabal-files-bundle $@
${fileFixers.fixShellFiles}/bin/fix-shell-files-bundle $@
${fileFixers.fixDhallFiles}/bin/fix-dhall-files-bundle $@
${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/generated
${fileFixers.fixPurescriptFiles}/bin/fix-purescript-files-bundle $@/roundtrip/RoundTripPurs
'';
};
# Purescript and bridge Nix libs
lib = {
bridgeTypelib = (import ./nix/purescript-bridge.nix) inputs.cardano-transaction-lib;
pursFlake = import ./nix/purescript-flake.nix;
pursLib = import ./nix/purescript-lib.nix;
};
hydraJobs = {
inherit build-all checks check-files;
};
}
);
}