forked from mlabs-haskell/ply
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
330 lines (294 loc) · 9.96 KB
/
flake.nix
File metadata and controls
330 lines (294 loc) · 9.96 KB
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
{
description = "Ply - A helper library for working with compiled, parameterized Plutus Scripts";
inputs = rec {
haskell-nix.url = "github:input-output-hk/haskell.nix";
nixpkgs.follows = "haskell-nix/nixpkgs-unstable";
extra-hackage.url = "github:mlabs-haskell/haskell-nix-extra-hackage";
extra-hackage.inputs.haskell-nix.follows = "haskell-nix";
extra-hackage.inputs.nixpkgs.follows = "nixpkgs";
iohk-nix.url = "github:input-output-hk/iohk-nix";
iohk-nix.flake = false; # Bad Nix code
plutarch.url = "github:Plutonomicon/plutarch-plutus";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
plutus = {
url =
"github:input-output-hk/plutus/b39a526e983cb931d0cc49b7d073d6d43abd22b5";
flake = false;
};
cardano-base = {
url =
"github:input-output-hk/cardano-base/0f3a867493059e650cda69e20a5cbf1ace289a57";
flake = false;
};
cardano-crypto = {
url =
"github:input-output-hk/cardano-crypto/07397f0e50da97eaa0575d93bee7ac4b2b2576ec";
flake = false;
};
cardano-prelude = {
url =
"github:input-output-hk/cardano-prelude/fd773f7a58412131512b9f694ab95653ac430852";
flake = false;
};
flat = {
url =
"github:input-output-hk/flat/ee59880f47ab835dbd73bea0847dab7869fc20d8";
flake = false;
};
};
outputs = inputs@{ self, nixpkgs, haskell-nix, extra-hackage, iohk-nix, plutarch, pre-commit-hooks, ... }:
let
# https://github.com/input-output-hk/haskell.nix/issues/1177
nonReinstallablePkgs = [
"array"
"array"
"base"
"binary"
"bytestring"
"Cabal"
"containers"
"deepseq"
"directory"
"exceptions"
"filepath"
"ghc"
"ghc-bignum"
"ghc-boot"
"ghc-boot"
"ghc-boot-th"
"ghc-compact"
"ghc-heap"
# "ghci"
# "haskeline"
"ghcjs-prim"
"ghcjs-th"
"ghc-prim"
"ghc-prim"
"hpc"
"integer-gmp"
"integer-simple"
"mtl"
"parsec"
"pretty"
"process"
"rts"
"stm"
"template-haskell"
"terminfo"
"text"
"time"
"transformers"
"unix"
"Win32"
"xhtml"
];
myhackages = system: compiler-nix-name: extra-hackage.mkHackagesFor system compiler-nix-name (
[
"${inputs.flat}"
"${inputs.cardano-prelude}/cardano-prelude"
"${inputs.cardano-crypto}"
"${inputs.cardano-base}/binary"
"${inputs.cardano-base}/cardano-crypto-class"
"${inputs.plutus}/plutus-core"
"${inputs.plutus}/plutus-ledger-api"
"${inputs.plutus}/plutus-tx"
"${inputs.plutus}/prettyprinter-configurable"
"${inputs.plutus}/word-array"
]
);
# 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 "${iohk-nix}/overlays/crypto")
];
inherit (haskell-nix) config;
};
nixpkgsFor' = system: import nixpkgs { inherit system; };
pre-commit-check-for = system: pre-commit-hooks.lib.${system}.run {
src = ./.;
settings = {
ormolu.defaultExtensions = [
"TypeApplications"
"PatternSynonyms"
];
};
hooks = {
nixpkgs-fmt.enable = true;
cabal-fmt.enable = true;
fourmolu.enable = true;
hlint.enable = true;
};
};
mkDevEnv = system:
# Generic environment bringing generic utilities. To be used only as a
# shell. Include as a dependency to other shells to have the same
# utilities in the shell.
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
in
pkgs.stdenv.mkDerivation {
name = "Standard-Dev-Environment-with-Utils";
buildInputs = [
pkgs'.bashInteractive
pkgs'.cabal-install
pkgs'.fd
pkgs'.git
pkgs'.gnumake
pkgs'.haskellPackages.apply-refact
pkgs'.haskellPackages.cabal-fmt
pkgs'.haskellPackages.fourmolu
pkgs'.hlint
pkgs'.nixpkgs-fmt
];
shellHook = (pre-commit-check-for system).shellHook +
''
echo $name
'';
};
# Ply core
ply-core = rec {
ghcVersion = "8107";
compiler-nix-name = "ghc${ghcVersion}";
projectFor = system:
let
pkgs = nixpkgsFor system;
pkgs' = nixpkgsFor' system;
stdDevEnv = mkDevEnv system;
h = myhackages system compiler-nix-name;
in
(nixpkgsFor system).haskell-nix.cabalProject' {
inherit compiler-nix-name;
inherit (h) extra-hackages extra-hackage-tarballs;
src = ./.;
cabalProjectFileName = "cabal.project.core";
cabalProjectLocal = ''
allow-newer: size-based:template-haskell
'';
modules = [
({ pkgs, ... }:
{
packages = {
cardano-crypto-praos.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
cardano-crypto-class.components.library.pkgconfig = pkgs.lib.mkForce [ [ pkgs.libsodium-vrf ] ];
};
}
)
] ++ h.modules;
shell = {
withHoogle = true;
exactDeps = true;
buildInputs = stdDevEnv.buildInputs;
tools.haskell-language-server = { };
shellHook = ''
export NIX_SHELL_TARGET="core"
ln -fs cabal.project.core cabal.project
'' + (pre-commit-check-for system).shellHook;
};
};
};
# Ply x Plutarch
ply-plutarch = rec {
ghcVersion = "923";
compiler-nix-name = "ghc${ghcVersion}";
projectFor = system:
let
pkgs = import plutarch.inputs.nixpkgs {
inherit system;
inherit (plutarch.inputs.haskell-nix) config;
overlays = [
plutarch.inputs.haskell-nix.overlay
(import "${plutarch.inputs.iohk-nix}/overlays/crypto")
];
};
stdDevEnv = mkDevEnv system; # TODO: parametrize with pkgs rather?
hls = (plutarch.hlsFor compiler-nix-name system);
myPlutarchHackages = plutarch.inputs.haskell-nix-extra-hackage.mkHackagesFor system compiler-nix-name [
"${inputs.plutarch}"
];
in
pkgs.haskell-nix.cabalProject' (plutarch.applyPlutarchDep pkgs {
inherit compiler-nix-name;
src = ./.;
cabalProjectFileName = "cabal.project.plutarch";
index-state = "2022-06-01T00:00:00Z";
inherit (myPlutarchHackages) extra-hackages extra-hackage-tarballs modules;
shell = {
withHoogle = true;
exactDeps = true;
buildInputs = stdDevEnv.buildInputs ++ [ hls ];
additional = ps: [
ps.plutarch
ps.plutus-ledger-api
];
shellHook = ''
export NIX_SHELL_TARGET="plutarch"
ln -fs cabal.project.plutarch cabal.project
${(pre-commit-check-for system).shellHook}
'';
};
});
};
in
{
inherit nixpkgsFor;
ply-core = {
project = perSystem ply-core.projectFor;
flake = perSystem (system: (ply-core.projectFor system).flake { });
};
ply-plutarch = {
project = perSystem ply-plutarch.projectFor;
flake = perSystem (system: (ply-plutarch.projectFor system).flake { });
};
build-all = perSystem (system:
(nixpkgsFor system).runCommand "build-all"
(self.ply-core.flake.${system}.packages // self.ply-plutarch.flake.${system}.packages)
"touch $out");
test-core = perSystem (system:
let pkgs = nixpkgsFor system;
in
pkgs.runCommand "test-core"
(pkgs.lib.attrsets.getAttrs
[ "ply-core:test:ply-core-test" ]
self.ply-core.flake.${system}.checks) "touch $out");
test-plutarch = perSystem (system:
let pkgs = nixpkgsFor system;
in
pkgs.runCommand "test-plutarch"
(pkgs.lib.attrsets.getAttrs
[ "ply-plutarch:test:ply-plutarch-test" ]
self.ply-plutarch.flake.${system}.checks) "touch $out");
packages = perSystem
(system:
self.ply-core.flake.${system}.packages //
self.ply-plutarch.flake.${system}.packages //
{ devEnv = mkDevEnv system; }
);
checks = perSystem (system:
self.ply-core.flake.${system}.checks // self.ply-plutarch.flake.${system}.checks
// { formatting-checks = pre-commit-check-for system; });
check = perSystem (system:
(nixpkgsFor system).runCommand "combined-test"
{
checksss = builtins.attrValues self.checks.${system}
++ builtins.attrValues self.packages.${system} ++ [
self.devShells.${system}.ply-core.inputDerivation
];
} ''
echo $checksss
touch $out
'');
apps = perSystem (system: self.ply-core.flake.${system}.apps // self.ply-plutarch.flake.${system}.apps);
devShells = perSystem (system: rec {
default = devEnv;
core = self.ply-core.flake.${system}.devShell;
plutarch = self.ply-plutarch.flake.${system}.devShell;
devEnv = self.packages.${system}.devEnv;
});
};
}