-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
206 lines (193 loc) · 6.81 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
{
description = "A nix flake for purescript-hydra-sdk.";
nixConfig = {
extra-experimental-features = [ "flakes" "nix-command" ];
bash-prompt = "\\[\\e[0m\\][\\[\\e[0;2m\\]nix-develop \\[\\e[0;1m\\]hydra-sdk@\\[\\033[33m\\]$(git rev-parse --abbrev-ref HEAD) \\[\\e[0;32m\\]\\w\\[\\e[0m\\]]\\[\\e[0m\\]$ \\[\\e[0m\\]";
};
inputs = {
nixpkgs.follows = "ctl/nixpkgs";
hydra.url = "github:input-output-hk/hydra/0.19.0";
hydra-fixtures = {
url = "github:input-output-hk/hydra/85a210df73e15733c602a8c0c46aab2400d5323d";
flake = false;
};
cardano-node.url = "github:input-output-hk/cardano-node/10.1.3";
cardano-configurations = {
url = "github:input-output-hk/cardano-configurations?rev=a913d87246dc2484562a00c86e5f9c74a20e82ce";
flake = false;
};
ctl = {
url = "github:Plutonomicon/cardano-transaction-lib/4bae6a202f3c77952d6067f94d8ae63cb74f3c0f";
inputs = {
cardano-node.follows = "cardano-node";
cardano-configurations.follows = "cardano-configurations";
};
};
};
outputs = { self, nixpkgs, ctl, hydra, hydra-fixtures, ... }@inputs:
let
projectName = "purescript-hydra-sdk";
supportedSystems = [ "x86_64-linux" ];
pursBuildOptions = {
strictComp = true;
censorCodes = [
"ImplicitImport"
"ImplicitQualifiedImport"
"ImplicitQualifiedImportReExport"
"UserDefinedWarning"
"MissingKindDeclaration"
"MissingTypeDeclaration"
];
};
perSystem = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = system: import nixpkgs {
inherit system;
overlays = [
ctl.overlays.purescript
ctl.overlays.runtime
ctl.overlays.spago
(_: _: {
arion = (import ctl.inputs.nixpkgs-arion { inherit system; }).arion;
})
];
};
hydraFixturesFor = pkgs: pkgs.runCommand "hydra-fixtures" { buildInputs = [ pkgs.jq ]; }
''
mkdir $out
VALID_ADDR="KjgoiXJS2coTnqpCLHXFtd89Hv9ttjsE6yW4msyLXFNkykUpTsyBs85r2rDDia2uKrhdpGKCJnmFXwvPSWLe75564ixZWdTxRh7TnuaDLnHx"
for fixture in ${hydra-fixtures}/hydra-node/golden/ServerOutput/*; do
if [ -f "$fixture" ]; then
echo "Fixing Hydra fixture: $fixture"
jq --arg validAddr "$VALID_ADDR" \
'walk(if type == "object" and has("address") and (.address | test("^addr_test1|^addr1") | not)
then .address = $validAddr else . end)' \
"$fixture" > tmp
mv tmp "$out/$(basename "$fixture")"
fi
done
'';
minimalExampleFor = system: pkgs:
pkgs.purescriptProject rec {
inherit pkgs;
projectName = "purescript-hydra-sdk-example-minimal";
src = builtins.path {
path = ./.;
name = "${projectName}-src";
filter = path: ftype:
!(pkgs.lib.hasSuffix ".md" path) &&
(builtins.baseNameOf path != "flake.nix") &&
!(ftype == "directory" && builtins.baseNameOf path == "docker");
};
packageJson = ./example/minimal/package.json;
packageLock = ./example/minimal/package-lock.json;
spagoPackages = ./example/minimal/spago-packages.nix;
};
hydraSdkFor = system: pkgs: hydraFixtures:
pkgs.purescriptProject rec {
inherit pkgs projectName;
src = builtins.path {
path = ./.;
name = "${projectName}-src";
filter = path: ftype:
!(pkgs.lib.hasSuffix ".md" path) &&
(builtins.baseNameOf path != "flake.nix") &&
!(ftype == "directory" && builtins.baseNameOf path == "example");
};
packageJson = ./package.json;
packageLock = ./package-lock.json;
shell = {
withRuntime = true;
shellHook = "export HYDRA_FIXTURES=${hydraFixtures}";
packageLockOnly = true;
packages = with pkgs; [
fd
jq
hydra.packages.${system}.hydra-node
nixpkgs-fmt
nodePackages.prettier
nodePackages.purs-tidy
inputs.cardano-node.packages.${system}."preview/node"
inputs.cardano-node.packages.${system}."preprod/node"
];
};
};
in
{
devShells = perSystem (system:
let
pkgs = nixpkgsFor system;
hydraFixtures = hydraFixturesFor pkgs;
in
{
default = (hydraSdkFor system pkgs hydraFixtures).devShell;
}
);
packages = perSystem (system:
let
pkgs = nixpkgsFor system;
project = minimalExampleFor system pkgs;
minimalExample = project.buildPursProject {
inherit (pursBuildOptions) strictComp censorCodes;
};
in
{
hydra-sdk-example-minimal = pkgs.writeShellApplication {
name = "hydra-sdk-example-minimal";
text = ''
TEMPD=$(mktemp -d)
cd "$TEMPD"
cp -r ${minimalExample}/* .
ln -sfn ${project.nodeModules}/lib/node_modules node_modules
node --enable-source-maps -e 'import("./output/HydraSdk.Example.Minimal.Main/index.js").then(m => m.main())' \
-- hydra-sdk-example-minimal "$@"
'';
};
}
);
apps = perSystem (system:
let
pkgs = nixpkgsFor system;
runtimeConfig = final: with final; {
network.name = "preprod";
};
in
{
ctl-runtime = pkgs.launchCtlRuntime runtimeConfig;
}
);
checks = perSystem (system:
let
pkgs = nixpkgsFor system;
hydraFixtures = hydraFixturesFor pkgs;
project = hydraSdkFor system pkgs hydraFixtures;
builtProject = project.buildPursProject {
inherit (pursBuildOptions) strictComp censorCodes;
};
in
{
hydra-sdk-unit-tests = project.runPursTest {
inherit builtProject;
name = "hydra-sdk-unit-tests";
testMain = "Test.Main";
env = { HYDRA_FIXTURES = "${hydraFixtures}"; };
};
hydra-sdk-formatting-check = pkgs.runCommand "hydra-sdk-formatting-check"
{
nativeBuildInputs = with pkgs; [
fd
easy-ps.purs-tidy
nixpkgs-fmt
nodePackages.prettier
];
}
''
cd ${self}
purs-tidy check $(fd -epurs)
prettier -c $(fd -ejs)
nixpkgs-fmt --check $(fd -enix --exclude='spago*')
touch $out
'';
}
);
};
}