-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
272 lines (249 loc) · 8.94 KB
/
Copy pathflake.nix
File metadata and controls
272 lines (249 loc) · 8.94 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
{
description = "Reusable NixOS modules and packaging for Frigate, the silent payments scanning server";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nix-bitcoin.url = "github:fort-nix/nix-bitcoin/release";
nix-bitcoin.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
nix-bitcoin,
}:
let
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
linuxSystems = [
"x86_64-linux"
"aarch64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
forAllLinux = nixpkgs.lib.genAttrs linuxSystems;
pkgsFor =
system:
import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
in
{
# Overlay attribute is `frigate-sparrowwallet` rather than the plain
# `frigate` to avoid silently colliding with nixpkgs's unrelated
# `pkgs.frigate` (blakeblackshear/frigate, an NVR camera). The module
# reads this name; consumers wanting overlay-based overrides set
# `frigate-sparrowwallet` in their own overlay too.
overlays.default = final: _prev: {
frigate-sparrowwallet = final.callPackage ./pkgs/frigate/package.nix { };
};
packages = forAllSystems (
system:
let
pkgs = pkgsFor system;
in
{
frigate = pkgs.frigate-sparrowwallet;
default = pkgs.frigate-sparrowwallet;
# frigate-bench: measure bitcoind RPC cost with frigate's actual
# call patterns and HTTP keep-alive (no fresh-curl-per-call TCP
# handshake artifacts). Run via `nix run .#frigate-bench` — see
# `apps.<system>.frigate-bench` below.
#
# Style/whitespace warnings (E501 line length, E226/E241 spacing,
# E265 block-comment style) are ignored — they fight with the
# script's print-table alignment and aren't worth contorting for.
frigate-bench = pkgs.writers.writePython3Bin "frigate-bench" {
flakeIgnore = [
"E501"
"E226"
"E241"
"E265"
];
} (builtins.readFile ./tools/frigate-bench/bench.py);
}
);
apps = forAllSystems (system: {
frigate-bench = {
type = "app";
program = "${self.packages.${system}.frigate-bench}/bin/frigate-bench";
};
});
nixosModules = {
frigate = ./modules/frigate.nix;
hetzner-bare-metal = ./modules/presets/hetzner-bare-metal.nix;
public-frigate = ./modules/presets/public-frigate.nix;
frigate-edge = ./modules/presets/frigate-edge.nix;
bitcoind-backend = ./modules/presets/bitcoind-backend.nix;
personal-frigate = ./modules/presets/personal-frigate.nix;
wireguard-mesh = ./modules/wireguard-mesh.nix;
# Batteries-included entry point for an all-in-one public
# Frigate node. Bundles nix-bitcoin so the consumer needs only
# `roost` in their flake inputs, and turns on the preset's
# manage flags so bitcoind and fulcrum are configured
# automatically. Use `nixosModules.public-frigate` directly if
# you operate bitcoind/fulcrum out of band.
default = {
imports = [
nix-bitcoin.nixosModules.default
./modules/presets/public-frigate.nix
];
services.public-frigate = {
bitcoind.manage = nixpkgs.lib.mkDefault true;
fulcrum.manage = nixpkgs.lib.mkDefault true;
};
};
# Batteries-included entry point for a bitcoind-backend host —
# bundles nix-bitcoin + the bitcoind-backend preset. Use this
# on the box that hosts bitcoind/fulcrum for a remote
# `frigate-edge` consumer; no frigate is configured here.
bitcoind-backend-host = {
imports = [
nix-bitcoin.nixosModules.default
./modules/presets/bitcoind-backend.nix
];
};
# Batteries-included entry point for a personal Frigate node.
# Bundles nix-bitcoin so the consumer needs only `roost` in
# their flake inputs, and turns on both manage flags so
# bitcoind and electrs are configured automatically. Use
# `nixosModules.personal-frigate` directly if you operate
# bitcoind/electrs out of band.
personal-frigate-host = {
imports = [
nix-bitcoin.nixosModules.default
./modules/presets/personal-frigate.nix
];
services.personal-frigate = {
bitcoind.manage = nixpkgs.lib.mkDefault true;
electrs.manage = nixpkgs.lib.mkDefault true;
};
};
};
formatter = forAllSystems (system: (pkgsFor system).nixfmt-tree);
lib = {
# VM-based end-to-end regtest against the bare frigate module.
# Parameterized so downstream consumers can run the same scenario
# with their own modules layered on top.
mkRegtestE2E =
{
pkgs,
nix-bitcoin,
extraModules ? [ ],
}:
import ./test/regtest-e2e.nix { inherit pkgs nix-bitcoin extraModules; };
# End-to-end test against `nixosModules.default` (the preset path
# with bitcoind/electrs/nginx-TLS managed automatically). The roost
# flake is captured here from the surrounding closure so consumers
# do not have to thread it through themselves.
mkRegtestPresetE2E =
{
pkgs,
extraModules ? [ ],
}:
import ./test/regtest-preset.nix {
inherit pkgs extraModules;
roost = self;
};
# Two-node test of the wireguard-mesh module. Boots two VMs on
# the test driver's shared virtual network, brings up the mesh,
# and verifies cross-mesh reachability + firewall scoping.
mkMeshTest =
{
pkgs,
extraModules ? [ ],
}:
import ./test/mesh.nix {
inherit pkgs extraModules;
roost = self;
};
# Two-VM end-to-end test for the frigate-edge preset. Boots a
# full nix-bitcoin stack on the `backend` node (with the
# public-frigate exposeBackends option enabled) and a slim
# frigate-edge consumer on the `edge` node, then exercises the
# edge's Electrum listeners.
mkRegtestEdgeE2E =
{
pkgs,
extraModules ? [ ],
}:
import ./test/regtest-edge.nix {
inherit pkgs extraModules;
roost = self;
};
# End-to-end test against `nixosModules.personal-frigate-host` —
# the single-box personal deployment with bitcoind + electrs +
# plaintext Electrum on loopback. Boots one VM, mines 101
# regtest blocks, then probes electrs and frigate over the
# Electrum protocol.
mkRegtestPersonalE2E =
{
pkgs,
extraModules ? [ ],
}:
import ./test/regtest-personal.nix {
inherit pkgs extraModules;
roost = self;
};
# Single-VM test for the bitcoind-backend preset. Verifies the
# backend stack (bitcoind RPC + ZMQ + fulcrum) comes up with
# the right bindings and that an external-looking RPC call
# using the configured rpcauth user succeeds.
mkRegtestBackend =
{
pkgs,
extraModules ? [ ],
}:
import ./test/regtest-backend.nix {
inherit pkgs extraModules;
roost = self;
};
};
checks = forAllLinux (system: {
regtest-e2e = self.lib.mkRegtestE2E {
pkgs = pkgsFor system;
inherit nix-bitcoin;
};
regtest-personal = self.lib.mkRegtestPersonalE2E {
pkgs = pkgsFor system;
};
regtest-preset = self.lib.mkRegtestPresetE2E {
pkgs = pkgsFor system;
};
regtest-edge = self.lib.mkRegtestEdgeE2E {
pkgs = pkgsFor system;
};
regtest-backend = self.lib.mkRegtestBackend {
pkgs = pkgsFor system;
};
wireguard-mesh = self.lib.mkMeshTest {
pkgs = pkgsFor system;
};
});
templates.default = {
path = ./templates/default;
description = "A starting point for a Frigate deployment";
};
templates.personal-frigate = {
path = ./templates/personal-frigate;
description = "A starting point for a personal Frigate deployment (single box, no TLS)";
};
devShells = forAllSystems (
system:
let
pkgs = pkgsFor system;
in
{
default = pkgs.mkShell {
packages = [
pkgs.nixos-rebuild
pkgs.nixos-anywhere
];
};
}
);
};
}