-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
executable file
·259 lines (241 loc) · 8.38 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
{
inputs = {
plutip.url = github:mlabs-haskell/plutip/8364c43ac6bc9ea140412af9a23c691adf67a18b;
cardano-transaction-lib.url = github:Plutonomicon/cardano-transaction-lib/v5.0.0;
nixpkgs.follows = "cardano-transaction-lib/nixpkgs";
haskell-nix.follows = "plutip/haskell-nix";
};
outputs = inputs@{ self, nixpkgs, haskell-nix, cardano-transaction-lib, plutip, ... }:
let
# COMMON
supportedSystems = [ "x86_64-linux" ];
perSystem = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = system: import nixpkgs {
inherit system;
overlays = [
haskell-nix.overlay
cardano-transaction-lib.overlays.purescript
cardano-transaction-lib.overlays.runtime
];
#TODO : this triggers a core dump but may be needed for plutip?
# inherit (haskell-nix) config;
};
nixpkgsFor' = system: import nixpkgs { inherit system; };
formatCheckFor = system:
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
nativeBuildInputs = [
pkgs'.fd
pkgs'.git
pkgs'.nixpkgs-fmt
pkgs.easy-ps.purs-tidy
pkgs'.haskell.packages.${on-chain.ghcVersion}.cabal-fmt
pkgs'.haskell.packages.${on-chain.ghcVersion}.fourmolu
];
inherit (pkgs'.lib) concatStringsSep;
otherBuildInputs = [ pkgs'.bash pkgs'.coreutils pkgs'.findutils pkgs'.gnumake pkgs'.nix ];
format = pkgs.writeScript "format"
''
export PATH=${concatStringsSep ":" (map (b: "${b}/bin") (otherBuildInputs ++ nativeBuildInputs))}
export FOURMOLU_EXTENSIONS="-o -XTypeApplications -o -XTemplateHaskell -o -XImportQualifiedPost -o -XPatternSynonyms -o -fplugin=RecordDotPreprocessor"
set -x
purs-tidy format-in-place $(fd -epurs)
fourmolu $FOURMOLU_EXTENSIONS --mode inplace --check-idempotence $(find on-chain/{exporter,src} -iregex ".*.hs")
nixpkgs-fmt $(fd -enix)
cabal-fmt --inplace $(fd -ecabal)
'';
in
{
inherit format;
}
;
# ON-CHAIN: PlutusTx, Cardano.Api
on-chain = rec {
ghcVersion = "ghc8107";
inherit (plutip.inputs) nixpkgs haskell-nix;
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; inherit (haskell-nix) config; };
projectFor = system:
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
in
pkgs.haskell-nix.cabalProject {
src = ./on-chain;
compiler-nix-name = ghcVersion;
index-state = "2022-05-25T00:00:00Z";
cabalProject = ''
packages: ./.
'';
inherit (plutip) cabalProjectLocal;
extraSources = plutip.extraSources ++ [
{
src = "${plutip}";
subdirs = [ "." ];
}
];
modules = plutip.haskellModules;
shell = {
withHoogle = true;
exactDeps = true;
nativeBuildInputs = with pkgs'; [
git
haskellPackages.apply-refact
fd
cabal-install
hlint
haskellPackages.cabal-fmt
haskellPackages.fourmolu
nixpkgs-fmt
];
tools.haskell-language-server = { };
additional = ps:
with ps; [
cardano-api
plutus-ledger
plutus-ledger-api
plutus-script-utils
plutus-tx
plutus-tx-plugin
serialise
];
};
};
script-export = system:
let
pkgs' = nixpkgsFor' system;
exporter = ((projectFor system).flake { }).packages."seath:exe:script-export";
in
pkgs'.runCommandLocal "script-export" { }
''
ln -s ${exporter}/bin/script-export $out
'';
exported-scripts = system:
let
pkgs' = nixpkgsFor' system;
exporter = ((projectFor system).flake { }).packages."seath:exe:script-export";
in
pkgs'.runCommand "exported-scripts" { }
''
set -e
mkdir $out
${exporter}/bin/script-export
'';
};
# OFF-CHAIN: CTL, Plutip
off-chain = {
projectFor = system:
let
pkgs = nixpkgsFor system;
exporter = ((on-chain.projectFor system).flake { }).packages."seath:exe:script-export";
in
pkgs.purescriptProject {
inherit pkgs;
projectName = "seath-off-chain";
strictComp = false; # TODO: this should be eventually removed
src = pkgs.runCommandLocal "generated-source" { }
''
set -e
cp -r ${./off-chain} $out
chmod -R +w $out
'';
# ${exporter}/bin/script-export $out/src
# ^^^ moved out from script above (it was last command in the script)
# as we have path argument hardcoded for now and module already generated
packageJson = ./off-chain/package.json;
packageLock = ./off-chain/package-lock.json;
shell = {
packageLockOnly = true;
packages = with pkgs; [
bashInteractive
docker
fd
nodePackages.eslint
nodePackages.prettier
ogmios
plutip-server
easy-ps.purs-tidy
];
shellHook =
''
export LC_CTYPE=C.UTF-8
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
'';
};
};
};
in
{
inherit nixpkgsFor;
on-chain = {
project = perSystem on-chain.projectFor;
flake = perSystem (system: (on-chain.projectFor system).flake { });
};
off-chain = {
project = perSystem off-chain.projectFor;
flake = perSystem (system: (off-chain.projectFor system).flake { });
};
packages = perSystem (system:
self.on-chain.flake.${system}.packages
// {
script-export = on-chain.script-export system;
# exported-scripts = on-chain.exported-scripts system;
}
);
checks = perSystem (system:
self.on-chain.flake.${system}.checks
// {
plutip-tests = self.off-chain.project.${system}.runPlutipTest {
testMain = "Seath.Test.Main";
};
formatting = (nixpkgsFor system).runCommand "formatting-check"
{
nativeBuildInputs = [
(nixpkgsFor system).easy-ps.purs-tidy
(nixpkgsFor system).fd
];
}
''
cd ${./.}/off-chain
make check-format
touch $out
'';
}
);
devShells = perSystem (system: {
on-chain = self.on-chain.flake.${system}.devShell;
off-chain = self.off-chain.project.${system}.devShell;
});
apps = perSystem (system: {
default-ctl-runtime = (nixpkgsFor system).launchCtlRuntime { };
preprod-ctl-runtime = (nixpkgsFor system).launchCtlRuntime {
network = {
name = "preprod";
magic = 1;
};
};
docs = self.off-chain.project.${system}.launchSearchablePursDocs { };
ctl-docs = cardano-transaction-lib.apps.${system}.docs;
script-export = {
# nix run .#script-export
type = "app";
program = (on-chain.script-export system).outPath;
};
# FIXME: fix formatting and add check to CI
# https://github.com/mlabs-haskell/seath/issues/7
# format = {
# type = "app";
# program = (formatCheckFor system).format.outPath;
# };
});
};
}