1{
2 config,
3 lib,
4 ...
5}: let
6 cfg = config.services.tangled-spindle;
7in
8 with lib; {
9 options = {
10 services.tangled-spindle = {
11 enable = mkOption {
12 type = types.bool;
13 default = false;
14 description = "Enable a tangled spindle";
15 };
16 package = mkOption {
17 type = types.package;
18 description = "Package to use for the spindle";
19 };
20
21 server = {
22 listenAddr = mkOption {
23 type = types.str;
24 default = "0.0.0.0:6555";
25 description = "Address to listen on";
26 };
27
28 dbPath = mkOption {
29 type = types.path;
30 default = "/var/lib/spindle/spindle.db";
31 description = "Path to the database file";
32 };
33
34 hostname = mkOption {
35 type = types.str;
36 example = "spindle.tangled.sh";
37 description = "Hostname for the server (required)";
38 };
39
40 jetstreamEndpoint = mkOption {
41 type = types.str;
42 default = "wss://jetstream1.us-west.bsky.network/subscribe";
43 description = "Jetstream endpoint to subscribe to";
44 };
45
46 dev = mkOption {
47 type = types.bool;
48 default = false;
49 description = "Enable development mode (disables signature verification)";
50 };
51
52 owner = mkOption {
53 type = types.str;
54 example = "did:plc:qfpnj4og54vl56wngdriaxug";
55 description = "DID of owner (required)";
56 };
57 };
58
59 pipelines = {
60 nixery = mkOption {
61 type = types.str;
62 default = "nixery.tangled.sh";
63 description = "Nixery instance to use";
64 };
65
66 workflowTimeout = mkOption {
67 type = types.str;
68 default = "5m";
69 description = "Timeout for each step of a pipeline";
70 };
71 };
72 };
73 };
74
75 config = mkIf cfg.enable {
76 virtualisation.docker.enable = true;
77
78 systemd.services.spindle = {
79 description = "spindle service";
80 after = ["network.target" "docker.service"];
81 wantedBy = ["multi-user.target"];
82 serviceConfig = {
83 LogsDirectory = "spindle";
84 StateDirectory = "spindle";
85 Environment = [
86 "SPINDLE_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}"
87 "SPINDLE_SERVER_DB_PATH=${cfg.server.dbPath}"
88 "SPINDLE_SERVER_HOSTNAME=${cfg.server.hostname}"
89 "SPINDLE_SERVER_JETSTREAM=${cfg.server.jetstreamEndpoint}"
90 "SPINDLE_SERVER_DEV=${lib.boolToString cfg.server.dev}"
91 "SPINDLE_SERVER_OWNER=${cfg.server.owner}"
92 "SPINDLE_PIPELINES_NIXERY=${cfg.pipelines.nixery}"
93 "SPINDLE_PIPELINES_WORKFLOW_TIMEOUT=${cfg.pipelines.workflowTimeout}"
94 ];
95 ExecStart = "${cfg.package}/bin/spindle";
96 Restart = "always";
97 };
98 };
99 };
100 }