attic.nix (2000B)
1 { 2 config, 3 lib, 4 ... 5 }: let 6 cfg = config.services.haravara.attic; 7 in { 8 options.services.haravara.attic = { 9 enable = lib.mkEnableOption "Attic Nix binary cache"; 10 domain = lib.mkOption { 11 type = lib.types.str; 12 description = "Domain name for the Attic server"; 13 }; 14 s3Endpoint = lib.mkOption { 15 type = lib.types.str; 16 description = "S3 endpoint for Attic"; 17 }; 18 s3Bucket = lib.mkOption { 19 type = lib.types.str; 20 default = "attic"; 21 description = "S3 bucket name for Attic"; 22 }; 23 s3Region = lib.mkOption { 24 type = lib.types.str; 25 default = "us-east-1"; 26 description = "S3 region for Attic"; 27 }; 28 credentialsFile = lib.mkOption { 29 type = lib.types.path; 30 description = "Path to environment file with ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64 and AWS credentials"; 31 }; 32 signingKeyFile = lib.mkOption { 33 type = lib.types.path; 34 description = "Path to the Nix signing private key file (generated with nix-store --generate-binary-cache-key)"; 35 }; 36 port = lib.mkOption { 37 type = lib.types.port; 38 default = 7381; 39 description = "Port for Attic to listen on"; 40 }; 41 }; 42 43 config = lib.mkIf cfg.enable { 44 users.users.atticd = { 45 isSystemUser = true; 46 group = "atticd"; 47 }; 48 users.groups.atticd = {}; 49 50 services.atticd = { 51 enable = true; 52 user = "atticd"; 53 group = "atticd"; 54 settings = { 55 listen = "127.0.0.1:${toString cfg.port}"; 56 storage = { 57 type = "s3"; 58 bucket = cfg.s3Bucket; 59 endpoint = cfg.s3Endpoint; 60 region = cfg.s3Region; 61 }; 62 }; 63 environmentFile = cfg.credentialsFile; 64 }; 65 66 systemd.services.atticd.serviceConfig = { 67 Environment = ["S3_ADDRESSING_STYLE=path"]; 68 DynamicUser = lib.mkForce false; 69 }; 70 71 services.caddy.virtualHosts."${cfg.domain}".extraConfig = '' 72 reverse_proxy 127.0.0.1:${toString cfg.port} 73 ''; 74 }; 75 }