Files
puppy-tracker/module.nix
T
Alexander Heldt 9207aaa4aa Store events and config in SQLite
Replace the JSON-file event and config stores with a SQLite database
(modernc.org/sqlite, pure-Go so the static build keeps CGO_ENABLED=0).
Last-write-wins now rides on the upsert's WHERE clause rather than a
Go-side map compare; the sync protocol and HTTP handlers are unchanged.

On first start the server auto-imports any legacy events.json/config.json
sitting in the data dir, renaming them to *.imported. The -data flag now
points at puppy.db; photos still live on the filesystem alongside it.
2026-07-09 16:56:35 +00:00

88 lines
2.6 KiB
Nix

self: { config, lib, pkgs, ... }:
let
cfg = config.services.puppy-tracker;
staticPkg = self.packages.${pkgs.system}.static;
serverPkg = self.packages.${pkgs.system}.server;
in
{
options.services.puppy-tracker = {
enable = lib.mkEnableOption "Puppy Tracker (offline-first puppy tracking app with sync server)";
address = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "Address the server listens on.";
};
port = lib.mkOption {
type = lib.types.port;
default = 8080;
description = "TCP port the server listens on.";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to open the configured port in the firewall.";
};
package = lib.mkOption {
type = lib.types.package;
default = serverPkg;
defaultText = lib.literalExpression "puppy-tracker.packages.\${system}.server";
description = "The puppy-tracker server package.";
};
staticPackage = lib.mkOption {
type = lib.types.package;
default = staticPkg;
defaultText = lib.literalExpression "puppy-tracker.packages.\${system}.static";
description = "The puppy-tracker static-site package (HTML/CSS/JS).";
};
};
config = lib.mkIf cfg.enable {
systemd.services.puppy-tracker = {
description = "Puppy Tracker server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = lib.concatStringsSep " " [
"${cfg.package}/bin/puppy-tracker-server"
"-addr ${cfg.address}:${toString cfg.port}"
"-static ${cfg.staticPackage}/share/puppy-tracker"
"-data /var/lib/puppy-tracker/puppy.db"
];
DynamicUser = true;
StateDirectory = "puppy-tracker";
StateDirectoryMode = "0750";
Restart = "on-failure";
RestartSec = "2s";
# Hardening
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
NoNewPrivileges = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectKernelLogs = true;
ProtectControlGroups = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@privileged @resources" ];
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
};
};
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
};
}