OwOpointTracker/module.nix
2024-10-09 11:37:42 +02:00

96 lines
2.1 KiB
Nix

self: {config,pkgs, lib, ...}:
with lib;
let
cfg = config.services.owOPointTracker;
format = pkgs.formats.yaml {};
configFile = format.generate "settings.yml" cfg.configFile;
databaseOptionType = types.submodule {
options = {
database = mkOption {
default = "_env:YESOD_SQLITE_DATABASE:OwOpointTracker.sqlite3";
type = types.str;
};
poolsize = mkOption {
default = "_env:YESOD_SQLITE_POOLSIZE:10";
type = types.str;
};
};
};
stationType = types.submodule {
options = {
station-id = mkOption {
default = "Station";
type = types.str;
};
station-name = mkOption {
type = types.str;
};
};
};
in
{
imports = [];
options.services.owOPointTracker = {
enable = mkEnableOption "OwOPointTracker";
configFile = {
static-dir = mkOption {
type = types.path;
};
host = mkOption {
type = types.str;
default = "_env:YESOD_HOST:*4";
};
ad-files = mkOption {
type = types.path;
};
port = mkOption {
default = "_env:YESOD_PORT:3000";
type = types.str;
};
ip-from-header = mkOption {
default = "_env:YESOD_IP_FROM_HEADER:false";
type = types.str;
};
database = mkOption {
type = databaseOptionType;
default = {
database = "_env:YESOD_SQLITE_DATABASE:OwOpointTracker.sqlite3";
poolsize = "_env:YESOD_SQLITE_POOLSIZE:10";
};
};
copyright = mkOption {
default = "copyright for this mess?";
type = types.str;
};
stations = mkOption {
type = types.listOf stationType;
};
};
};
config = mkIf cfg.enable {
users.users.owopoint = {
isSystemUser = true;
group = "owopoint";
createHome = true;
home = "/var/owopoint";
};
users.groups = {
owopoint = {};
};
systemd.services.owOPointTracker = {
wantedBy = ["multi-user.target"];
after = ["network.target"];
serviceConfig = {
WorkingDirectory = "/var/owopoint/";
ExecStart = "${self.packages.${pkgs.system}.default}/bin/OwOpointTracker ${configFile}";
Restart = "always";
User = "owopoint";
Group = "owopoint";
};
};
};
}