OwOpointTracker/module.nix

97 lines
2.1 KiB
Nix
Raw Normal View History

2024-10-09 09:47:08 +02:00
self: {config,pkgs, lib, ...}:
2024-10-09 08:14:47 +02:00
with lib;
let
cfg = config.services.owOPointTracker;
format = pkgs.formats.yaml {};
2024-10-09 10:08:17 +02:00
configFile = format.generate "settings.yml" cfg.configFile;
2024-10-09 08:14:47 +02:00
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 {
2024-10-09 10:14:24 +02:00
type = types.str;
2024-10-09 08:14:47 +02:00
};
};
};
2024-10-09 09:41:25 +02:00
in
2024-10-09 08:14:47 +02:00
{
imports = [];
options.services.owOPointTracker = {
enable = mkEnableOption "OwOPointTracker";
2024-10-09 09:44:28 +02:00
configFile = {
2024-10-09 08:14:47 +02:00
static-dir = mkOption {
type = types.path;
};
host = mkOption {
type = types.str;
default = "_env:YESOD_HOST:*4";
2024-10-09 09:45:49 +02:00
};
2024-10-09 08:14:47 +02:00
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;
};
2024-10-09 10:10:10 +02:00
database = mkOption {
2024-10-09 08:14:47 +02:00
type = databaseOptionType;
2024-10-09 10:12:54 +02:00
default = {
database = "_env:YESOD_SQLITE_DATABASE:OwOpointTracker.sqlite3";
poolsize = "_env:YESOD_SQLITE_POOLSIZE:10";
};
2024-10-09 08:14:47 +02:00
};
copyright = mkOption {
default = "copyright for this mess?";
type = types.str;
};
2024-10-09 11:37:42 +02:00
stations = mkOption {
2024-10-09 08:14:47 +02:00
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 = {
2024-10-09 11:28:15 +02:00
WorkingDirectory = "/var/owopoint/";
2024-10-09 10:20:59 +02:00
ExecStart = "${self.packages.${pkgs.system}.default}/bin/OwOpointTracker ${configFile}";
2024-10-09 10:07:13 +02:00
Restart = "always";
2024-10-09 08:14:47 +02:00
User = "owopoint";
Group = "owopoint";
};
};
};
}