-
Notifications
You must be signed in to change notification settings - Fork 2
/
flake.nix
187 lines (175 loc) · 5.85 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
{
description = "ctl-scaffold";
inputs = {
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
ctl = {
type = "github";
owner = "Plutonomicon";
repo = "cardano-transaction-lib";
rev = "205f25b591656b825186d2187fdcba1e00c3df87"; #v5.0.0
};
# To use the same version of `nixpkgs` as we do
nixpkgs.follows = "ctl/nixpkgs";
};
outputs = { self, nixpkgs, ctl, ... }@inputs:
let
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
perSystem = nixpkgs.lib.genAttrs supportedSystems;
# generate `pkgs` with CTL's overlays applied. This gives you access to
# various additional packages. The versions are the same as those that CTL uses.
nixpkgsFor = system: import nixpkgs {
inherit system;
overlays = [
ctl.overlays.purescript
ctl.overlays.runtime
ctl.overlays.spago
];
};
# The configuration for the CTL runtime, which will be passed to the
# expression that builds the JSON file used by Arion. This value can be
# shared between `buildCtlRuntime` and `launchCtlRuntime`, as shown below
#
# You can refer to the final configuration value by passing a function
# that takes a single arugment. Alternatively, you can pass an attrset
# directly.
#
# Here we demonstrate how to add `extraServices` and `extraDockerCompose`.
# For the other attributes, which have default values,
# consult `defaultConfig` in `nix/runtime.nix`.
runtimeConfig = { };
# runtimeConfig = final: with final; {
# # You can add new services to the runtime. These should correspond to
# # Arion's `service` definition. The default is the empty attribute set
# extraServices = {
# # an image from dockerhub
# foo = {
# service = {
# image = "bar:foo";
# command = [
# "baz"
# "--quux"
# ];
# };
# # Or a Nix-based image
# foo2 = {
# service = {
# useHostStore = true;
# command = [
# "${(nixpkgsFor system).baz}/bin/baz"
# "--quux"
# ];
# };
# };
# };
# };
# # This corresponds to `docker-compose.raw` from Arion. You can add new
# # volumes, etc... using this
# extraDockerCompose = { volumes = { someVol = { }; }; };
psProjectFor = pkgs:
pkgs.purescriptProject rec {
inherit pkgs;
projectName = "ctl-scaffold";
packageJson = ./package.json;
packageLock = ./package-lock.json;
src = builtins.path {
path = ./.;
name = "${projectName}-src";
# Adjust the `filter` as necessary
filter = path: ftype: !(pkgs.lib.hasSuffix ".md" path);
};
shell = {
withRuntime = true;
packageLockOnly = true;
packages = with pkgs; [
fd
nodePackages.eslint
nodePackages.prettier
];
};
};
in
{
# `buildCtlRuntime` will generate a Nix expression that, when built with
# `pkgs.arion.build`, outputs a JSON file compatible with Arion. This can
# be run directly with Arion or passed to another derivation. Or you can
# use `buildCtlRuntime` with `runArion` (from the `hercules-ci-effects`)
# library
#
# Use `nix build .#<PACKAGE>` to build. To run with Arion (i.e. in your
# shell): `arion --prebuilt-file ./result up`
packages = perSystem (system:
let
pkgs = nixpkgsFor system;
in
{
default = self.packages.${system}.ctl-scaffold-bundle-web;
ctl-scaffold-bundle-web = (psProjectFor pkgs).bundlePursProject {
main = "Scaffold.Main";
entrypoint = "index.js";
};
ctl-scaffold-runtime = pkgs.buildCtlRuntime runtimeConfig;
});
# `launchCtlRuntime` will generate a Nix expression from the provided
# config, build it into a JSON file, and then run it with Arion
#
# Use `nix run .#<APP>` to run the services (e.g. `nix run .#ctl-runtime`)
apps = perSystem (system:
let
pkgs = nixpkgsFor system;
in
{
default = self.apps.${system}.ctl-scaffold-runtime;
ctl-scaffold-runtime = pkgs.launchCtlRuntime runtimeConfig;
docs = (psProjectFor pkgs).launchSearchablePursDocs { };
});
checks = perSystem (system:
let
pkgs = nixpkgsFor system;
in
{
ctl-scaffold-plutip-test = (psProjectFor pkgs).runPlutipTest {
testMain = "Test.Scaffold.Main";
};
formatting-check = pkgs.runCommand "formatting-check"
{
nativeBuildInputs = with pkgs; [
fd
easy-ps.purs-tidy
nixpkgs-fmt
nodePackages.prettier
];
}
''
cd ${self}
purs-tidy check $(fd -epurs)
nixpkgs-fmt --check $(fd -enix --exclude='spago*')
prettier -c $(fd -ejs)
touch $out
'';
js-lint-check = pkgs.runCommand "js-lint-check"
{
nativeBuildInputs = [ pkgs.nodePackages.eslint pkgs.fd ];
}
''
cd ${self}
eslint $(fd -ejs)
touch $out
'';
});
devShells = perSystem (system:
let
pkgs = nixpkgsFor system;
in
{
default = (psProjectFor pkgs).devShell;
});
};
}