at 25.11-pre 2.0 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8let 9 inherit (lib) types; 10 cfg = config.services.goatcounter; 11 stateDir = "goatcounter"; 12in 13 14{ 15 options = { 16 services.goatcounter = { 17 enable = lib.mkEnableOption "goatcounter"; 18 19 package = lib.mkPackageOption pkgs "goatcounter" { }; 20 21 address = lib.mkOption { 22 type = types.str; 23 default = "127.0.0.1"; 24 description = "Web interface address."; 25 }; 26 27 port = lib.mkOption { 28 type = types.port; 29 default = 8081; 30 description = "Web interface port."; 31 }; 32 33 proxy = lib.mkOption { 34 type = types.bool; 35 default = false; 36 description = '' 37 Whether Goatcounter service is running behind a reverse proxy. Will listen for HTTPS if `false`. 38 Refer to [documentation](https://github.com/arp242/goatcounter?tab=readme-ov-file#running) for more details. 39 ''; 40 }; 41 42 extraArgs = lib.mkOption { 43 type = with types; listOf str; 44 default = [ ]; 45 description = '' 46 List of extra arguments to be passed to goatcounter cli. 47 See {command}`goatcounter help serve` for more information. 48 ''; 49 }; 50 }; 51 }; 52 53 config = lib.mkIf cfg.enable { 54 systemd.services.goatcounter = { 55 description = "Easy web analytics. No tracking of personal data."; 56 wantedBy = [ "multi-user.target" ]; 57 serviceConfig = { 58 ExecStart = lib.escapeShellArgs ( 59 [ 60 (lib.getExe cfg.package) 61 "serve" 62 "-listen" 63 "${cfg.address}:${toString cfg.port}" 64 ] 65 ++ lib.optionals cfg.proxy [ 66 "-tls" 67 "proxy" 68 ] 69 ++ cfg.extraArgs 70 ); 71 DynamicUser = true; 72 StateDirectory = stateDir; 73 WorkingDirectory = "%S/${stateDir}"; 74 Restart = "always"; 75 }; 76 }; 77 }; 78 79 meta.maintainers = with lib.maintainers; [ bhankas ]; 80}