module.nix: init
This commit is contained in:
@@ -25,6 +25,12 @@
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
overlays.default = final: prev: {
|
||||||
|
inherit (self.packages.${final.system}) mclog2psql;
|
||||||
|
};
|
||||||
|
|
||||||
|
nixosModules.default = ./module.nix;
|
||||||
|
|
||||||
packages = forAllSystems (system: pkgs: {
|
packages = forAllSystems (system: pkgs: {
|
||||||
default = self.packages.${system}.mclog2psql;
|
default = self.packages.${system}.mclog2psql;
|
||||||
mclog2psql = pkgs.writers.writePython3Bin "mclog2psql" {
|
mclog2psql = pkgs.writers.writePython3Bin "mclog2psql" {
|
||||||
|
|||||||
+101
@@ -0,0 +1,101 @@
|
|||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.minecraft-heatmap;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.minecraft-heatmap = {
|
||||||
|
enable = lib.mkEnableOption "";
|
||||||
|
|
||||||
|
mclog2psqlPackage = lib.mkPackageOption pkgs "mclog2psql" { };
|
||||||
|
|
||||||
|
onCalendar = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "05:00:00";
|
||||||
|
description = "Systemd timer OnCalendar setting for the Minecraft Heatmap log ingester.";
|
||||||
|
};
|
||||||
|
|
||||||
|
minecraftLogsDir = lib.mkOption {
|
||||||
|
type = lib.types.path;
|
||||||
|
default = "/var/cache/minecraft-heatmap/logs";
|
||||||
|
description = "Directory containing Minecraft server log files to be ingested.";
|
||||||
|
};
|
||||||
|
|
||||||
|
database = {
|
||||||
|
host = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "localhost";
|
||||||
|
description = "Database host for Minecraft Heatmap.";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 5432;
|
||||||
|
description = "Database port for Minecraft Heatmap.";
|
||||||
|
};
|
||||||
|
|
||||||
|
name = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "minecraft_heatmap";
|
||||||
|
description = "Database name for Minecraft Heatmap.";
|
||||||
|
};
|
||||||
|
|
||||||
|
user = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "minecraft_heatmap";
|
||||||
|
description = "Database user for Minecraft Heatmap.";
|
||||||
|
};
|
||||||
|
|
||||||
|
passwordFile = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr path;
|
||||||
|
default = null;
|
||||||
|
description = "Path to the file containing the database password for Minecraft Heatmap.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
systemd.services.minecraft-heatmap-ingest-logs = {
|
||||||
|
description = "Minecraft Heatmap log ingester service";
|
||||||
|
environment = {
|
||||||
|
MINECRAFT_HEATMAP_DIR = cfg.minecraftLogsDir;
|
||||||
|
MINECRAFT_HEATMAP_DB_HOST = cfg.database.host;
|
||||||
|
MINECRAFT_HEATMAP_DB_PORT = toString cfg.database.port;
|
||||||
|
MINECRAFT_HEATMAP_DB_NAME = cfg.database.name;
|
||||||
|
MINECRAFT_HEATMAP_DB_USER = cfg.database.user;
|
||||||
|
MINECRAFT_HEATMAP_DB_PASSWORD_FILE = lib.optionalString (cfg.database.passwordFile != null) "%d/minecraft-heatmap-db-password";
|
||||||
|
};
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
ExecStart = "${cfg.mclog2psqlPackage}/bin/mclog2psql";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
|
||||||
|
User = "minecraft-heatmap";
|
||||||
|
Group = "minecraft-heatmap";
|
||||||
|
DynamicUser = true;
|
||||||
|
|
||||||
|
LoadCredential = lib.mkIf (cfg.database.passwordFile != null) [
|
||||||
|
"minecraft-heatmap-db-password:${cfg.database.passwordFile}"
|
||||||
|
];
|
||||||
|
|
||||||
|
CacheDirectory = "minecraft-heatmap";
|
||||||
|
CacheDirectoryMode = "0700";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.timers.minecraft-heatmap-ingest-logs = {
|
||||||
|
description = "Minecraft Heatmap log ingester timer";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = cfg.onCalendar;
|
||||||
|
Persistent = true;
|
||||||
|
RandomizedDelaySec = "1h";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# systemd.sockets.minecraft-heatmap-rest-endpoint = {};
|
||||||
|
|
||||||
|
# systemd.sockets.minecraft-heatmap-rest-endpoint = {};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user