Monorepo for Tangled
at master 170 lines 5.6 kB view raw
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 = "my.spindle.com"; 37 description = "Hostname for the server (required)"; 38 }; 39 40 plcUrl = mkOption { 41 type = types.str; 42 default = "https://plc.directory"; 43 description = "atproto PLC directory"; 44 }; 45 46 jetstreamEndpoint = mkOption { 47 type = types.str; 48 default = "wss://jetstream1.us-west.bsky.network/subscribe"; 49 description = "Jetstream endpoint to subscribe to"; 50 }; 51 52 dev = mkOption { 53 type = types.bool; 54 default = false; 55 description = "Enable development mode (disables signature verification)"; 56 }; 57 58 owner = mkOption { 59 type = types.str; 60 example = "did:plc:qfpnj4og54vl56wngdriaxug"; 61 description = "DID of owner (required)"; 62 }; 63 64 maxJobCount = mkOption { 65 type = types.int; 66 default = 2; 67 example = 5; 68 description = "Maximum number of concurrent jobs to run"; 69 }; 70 71 queueSize = mkOption { 72 type = types.int; 73 default = 100; 74 example = 100; 75 description = "Maximum number of jobs queue up"; 76 }; 77 78 secrets = { 79 provider = mkOption { 80 type = types.str; 81 default = "sqlite"; 82 description = "Backend to use for secret management, valid options are 'sqlite', and 'openbao'."; 83 }; 84 85 openbao = { 86 proxyAddr = mkOption { 87 type = types.str; 88 default = "http://127.0.0.1:8200"; 89 description = "Address of the OpenBAO proxy server"; 90 }; 91 mount = mkOption { 92 type = types.str; 93 default = "spindle"; 94 description = "Mount path in OpenBAO to read secrets from"; 95 }; 96 }; 97 }; 98 }; 99 100 pipelines = { 101 nixery = mkOption { 102 type = types.str; 103 default = "nixery.tangled.sh"; # note: this is *not* on tangled.org yet 104 description = "Nixery instance to use"; 105 }; 106 107 workflowTimeout = mkOption { 108 type = types.str; 109 default = "5m"; 110 description = "Timeout for each step of a pipeline"; 111 }; 112 113 logBucket = mkOption { 114 type = types.str; 115 default = "tangled-logs"; 116 description = "S3 bucket for workflow logs"; 117 }; 118 }; 119 120 environmentFile = mkOption { 121 type = with types; nullOr path; 122 default = null; 123 example = "/etc/spindle.env"; 124 description = '' 125 Additional environment file as defined in {manpage}`systemd.exec(5)`. 126 127 Sensitive secrets such as {env}`AWS_SECRET_ACCESS_KEY`, 128 {env}`AWS_ACCESS_KEY_ID`, {env}`AWS_REGION` 129 may be passed to the service 130 without making them world readable in the nix store. 131 ''; 132 }; 133 }; 134 }; 135 136 config = mkIf cfg.enable { 137 virtualisation.docker.enable = true; 138 139 systemd.services.spindle = { 140 description = "spindle service"; 141 after = ["network.target" "docker.service"]; 142 wantedBy = ["multi-user.target"]; 143 serviceConfig = { 144 LogsDirectory = "spindle"; 145 StateDirectory = "spindle"; 146 EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; 147 148 Environment = [ 149 "SPINDLE_SERVER_LISTEN_ADDR=${cfg.server.listenAddr}" 150 "SPINDLE_SERVER_DB_PATH=${cfg.server.dbPath}" 151 "SPINDLE_SERVER_HOSTNAME=${cfg.server.hostname}" 152 "SPINDLE_SERVER_PLC_URL=${cfg.server.plcUrl}" 153 "SPINDLE_SERVER_JETSTREAM_ENDPOINT=${cfg.server.jetstreamEndpoint}" 154 "SPINDLE_SERVER_DEV=${lib.boolToString cfg.server.dev}" 155 "SPINDLE_SERVER_OWNER=${cfg.server.owner}" 156 "SPINDLE_SERVER_MAX_JOB_COUNT=${toString cfg.server.maxJobCount}" 157 "SPINDLE_SERVER_QUEUE_SIZE=${toString cfg.server.queueSize}" 158 "SPINDLE_SERVER_SECRETS_PROVIDER=${cfg.server.secrets.provider}" 159 "SPINDLE_SERVER_SECRETS_OPENBAO_PROXY_ADDR=${cfg.server.secrets.openbao.proxyAddr}" 160 "SPINDLE_SERVER_SECRETS_OPENBAO_MOUNT=${cfg.server.secrets.openbao.mount}" 161 "SPINDLE_NIXERY_PIPELINES_NIXERY=${cfg.pipelines.nixery}" 162 "SPINDLE_NIXERY_PIPELINES_WORKFLOW_TIMEOUT=${cfg.pipelines.workflowTimeout}" 163 "SPINDLE_S3_LOG_BUCKET=${cfg.pipelines.logBucket}" 164 ]; 165 ExecStart = "${cfg.package}/bin/spindle"; 166 Restart = "always"; 167 }; 168 }; 169 }; 170 }