nixos/goatcounter: init

This commit is contained in:
Payas Relekar 2024-07-15 00:44:11 +05:30
parent f11a6a01cb
commit aebb3d3474
6 changed files with 130 additions and 9 deletions

View File

@ -20,6 +20,8 @@
- [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr), proxy server to bypass Cloudflare protection. Available as [services.flaresolverr](#opt-services.flaresolverr.enable) service.
- [Goatcounter](https://www.goatcounter.com/), Easy web analytics. No tracking of personal data. Available as [services.goatcounter](options.html#opt-services.goatcocunter.enable).
- [Open-WebUI](https://github.com/open-webui/open-webui), a user-friendly WebUI
for LLMs. Available as [services.open-webui](#opt-services.open-webui.enable)
service.

View File

@ -1397,6 +1397,7 @@
./services/web-apps/gotosocial.nix
./services/web-apps/grocy.nix
./services/web-apps/pixelfed.nix
./services/web-apps/goatcounter.nix
./services/web-apps/guacamole-client.nix
./services/web-apps/guacamole-server.nix
./services/web-apps/healthchecks.nix

View File

@ -0,0 +1,80 @@
{
config,
lib,
pkgs,
...
}:
let
inherit (lib) types;
cfg = config.services.goatcounter;
stateDir = "goatcounter";
in
{
options = {
services.goatcounter = {
enable = lib.mkEnableOption "goatcounter";
package = lib.mkPackageOption pkgs "goatcounter" { };
address = lib.mkOption {
type = types.str;
default = "127.0.0.1";
description = "Web interface address.";
};
port = lib.mkOption {
type = types.port;
default = 8081;
description = "Web interface port.";
};
proxy = lib.mkOption {
type = types.bool;
default = false;
description = ''
Whether Goatcounter service is running behind a reverse proxy. Will listen for HTTPS if `false`.
Refer to [documentation](https://github.com/arp242/goatcounter?tab=readme-ov-file#running) for more details.
'';
};
extraArgs = lib.mkOption {
type = with types; listOf str;
default = [ ];
description = ''
List of extra arguments to be passed to goatcounter cli.
See {command}`goatcounter help serve` for more information.
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.services.goatcounter = {
description = "Easy web analytics. No tracking of personal data.";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = lib.escapeShellArgs (
[
(lib.getExe cfg.package)
"serve"
"-listen"
"${cfg.address}:${toString cfg.port}"
]
++ lib.optionals cfg.proxy [
"-tls"
"proxy"
]
++ cfg.extraArgs
);
DynamicUser = true;
StateDirectory = stateDir;
WorkingDirectory = "%S/${stateDir}";
Restart = "always";
};
};
};
meta.maintainers = with lib.maintainers; [ bhankas ];
}

View File

@ -375,6 +375,7 @@ in {
gnome-xorg = handleTest ./gnome-xorg.nix {};
gns3-server = handleTest ./gns3-server.nix {};
gnupg = handleTest ./gnupg.nix {};
goatcounter = handleTest ./goatcounter.nix {};
go-neb = handleTest ./go-neb.nix {};
gobgpd = handleTest ./gobgpd.nix {};
gocd-agent = handleTest ./gocd-agent.nix {};

View File

@ -0,0 +1,32 @@
import ./make-test-python.nix (
{ lib, pkgs, ... }:
{
name = "goatcounter";
meta.maintainers = with lib.maintainers; [ bhankas ];
nodes.machine =
{ config, ... }:
{
virtualisation.memorySize = 2048;
services.goatcounter = {
enable = true;
proxy = true;
};
};
testScript = ''
start_all()
machine.wait_for_unit("goatcounter.service")
# wait for goatcounter to fully come up
with subtest("goatcounter service starts"):
machine.wait_until_succeeds(
"curl -sSfL http://localhost:8081/ > /dev/null",
timeout=30
)
'';
}
)

View File

@ -1,8 +1,10 @@
{ lib
, buildGoModule
, fetchFromGitHub
, testers
, goatcounter
{
lib,
buildGoModule,
fetchFromGitHub,
testers,
goatcounter,
nixosTests,
}:
buildGoModule rec {
@ -31,10 +33,13 @@ buildGoModule rec {
"-X zgo.at/goatcounter/v2.Version=${src.rev}"
];
passthru.tests.version = testers.testVersion {
package = goatcounter;
command = "goatcounter version";
version = "v${version}";
passthru.tests = {
moduleTest = nixosTests.goatcounter;
version = testers.testVersion {
package = goatcounter;
command = "goatcounter version";
version = "v${version}";
};
};
meta = {