This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
{
|
||||
inputs,
|
||||
flake,
|
||||
self,
|
||||
}:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
cfg = config.hectic.services.routine-server;
|
||||
system = pkgs.stdenv.hostPlatform.system;
|
||||
in {
|
||||
options.hectic.services.routine-server = {
|
||||
enable = lib.mkEnableOption "daily, weekly, and monthly routine server";
|
||||
|
||||
address = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address on which the routine server listens.";
|
||||
};
|
||||
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8090;
|
||||
description = "Port on which the routine server listens.";
|
||||
};
|
||||
|
||||
generationDays = lib.mkOption {
|
||||
type = lib.types.ints.unsigned;
|
||||
default = 62;
|
||||
description = "Number of future routine days to materialize.";
|
||||
};
|
||||
|
||||
databaseName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "routine-server";
|
||||
description = "PostgreSQL database used by the routine server.";
|
||||
};
|
||||
|
||||
databaseUser = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "routine-server";
|
||||
description = "PostgreSQL and dynamic system user used by the routine server.";
|
||||
};
|
||||
|
||||
databaseSocket = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/run/postgresql";
|
||||
description = "PostgreSQL Unix socket directory.";
|
||||
};
|
||||
|
||||
timezone = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "UTC";
|
||||
description = "Timezone used for dates and reminder times.";
|
||||
};
|
||||
|
||||
environmentFile = lib.mkOption {
|
||||
type = with lib.types; nullOr path;
|
||||
default = null;
|
||||
description = ''
|
||||
Optional secret environment file. Supported variables:
|
||||
ROUTINE_API_TOKEN=
|
||||
ROUTINE_TELEGRAM_BOT_TOKEN=
|
||||
ROUTINE_TELEGRAM_CHAT_ID=
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [ cfg.databaseName ];
|
||||
ensureUsers = [
|
||||
{
|
||||
name = cfg.databaseUser;
|
||||
ensureDBOwnership = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.routine-server = {
|
||||
description = "Personal routine task server";
|
||||
after = [ "network-online.target" "postgresql.service" ];
|
||||
wants = [ "network-online.target" ];
|
||||
requires = [ "postgresql.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
environment = {
|
||||
ROUTINE_BIND = "${cfg.address}:${toString cfg.port}";
|
||||
ROUTINE_DATABASE_URL = "host=${cfg.databaseSocket} dbname=${cfg.databaseName} user=${cfg.databaseUser}";
|
||||
ROUTINE_GENERATION_DAYS = toString cfg.generationDays;
|
||||
TZ = cfg.timezone;
|
||||
};
|
||||
|
||||
serviceConfig = lib.mkMerge [
|
||||
{
|
||||
Type = "simple";
|
||||
ExecStart = "${self.packages.${system}.routine-server}/bin/routine-server";
|
||||
Restart = "on-failure";
|
||||
RestartSec = "5s";
|
||||
DynamicUser = true;
|
||||
User = cfg.databaseUser;
|
||||
Group = cfg.databaseUser;
|
||||
UMask = "0077";
|
||||
NoNewPrivileges = true;
|
||||
PrivateTmp = true;
|
||||
ProtectHome = true;
|
||||
ProtectSystem = "strict";
|
||||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
|
||||
}
|
||||
(lib.mkIf (cfg.environmentFile != null) {
|
||||
EnvironmentFile = cfg.environmentFile;
|
||||
})
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user