2024-04-19 17:11:03 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2023-01-22 01:25:07 +00:00
|
|
|
|
2023-01-22 19:03:11 +00:00
|
|
|
let
|
|
|
|
tracktrain-config = ''
|
|
|
|
dbstring: "dbname=tracktrain"
|
2023-05-17 15:49:56 +00:00
|
|
|
gtfs: /persist/gtfs.zip
|
2023-03-16 14:03:13 +00:00
|
|
|
assets: ${pkgs.tracktrain}/assets
|
2023-01-22 19:03:11 +00:00
|
|
|
|
|
|
|
warp:
|
|
|
|
port: 4000
|
|
|
|
|
|
|
|
login:
|
|
|
|
enable: true
|
|
|
|
url: https://login.infra4future.de
|
2024-07-05 21:12:20 +00:00
|
|
|
clientName: tracktrain
|
|
|
|
# clientSecret defined in env file
|
2024-05-01 02:08:16 +00:00
|
|
|
|
|
|
|
logging:
|
2024-07-05 21:12:20 +00:00
|
|
|
ntfyTopic: ping.stuebinm.eu/monit
|
2024-05-01 02:08:16 +00:00
|
|
|
name: ilztalbahn
|
2023-01-22 19:03:11 +00:00
|
|
|
'';
|
|
|
|
in
|
2023-01-22 01:25:07 +00:00
|
|
|
{
|
2023-05-03 21:04:13 +00:00
|
|
|
sops.secrets = {
|
|
|
|
"tracktrain/env" = {};
|
|
|
|
};
|
|
|
|
|
2023-01-22 01:25:07 +00:00
|
|
|
services.nginx.virtualHosts."tracktrain.ilztalbahn.eu" = {
|
2023-01-22 19:03:11 +00:00
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
2024-04-19 17:11:03 +00:00
|
|
|
proxyPass = "http://${config.containers.tracktrain.localAddress}:4000";
|
2023-01-22 01:25:07 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
2023-01-22 19:03:11 +00:00
|
|
|
# note: this shadows the /metrics endpoint of tracktrain
|
|
|
|
# in case you remove this, please consider putting something
|
|
|
|
# else here to keep it from being publicly scrapable
|
|
|
|
locations."/metrics/" = {
|
2024-04-19 17:11:03 +00:00
|
|
|
proxyPass = "http://${config.containers.tracktrain.localAddress}:2342";
|
2023-01-22 19:03:11 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
extraConfig = ''
|
|
|
|
rewrite ^/metrics/(.*) /$1 break;
|
|
|
|
'';
|
|
|
|
};
|
2023-01-22 01:25:07 +00:00
|
|
|
};
|
|
|
|
|
2024-04-19 17:11:03 +00:00
|
|
|
hacc.containers.tracktrain = {
|
|
|
|
bindSecrets = true;
|
2023-01-22 19:03:11 +00:00
|
|
|
|
2024-04-19 17:11:03 +00:00
|
|
|
config = { config, lib, pkgs, ... }: {
|
2023-01-22 19:03:11 +00:00
|
|
|
|
2023-01-22 01:25:07 +00:00
|
|
|
systemd.services.tracktrain = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
description = "tracks trains, hopefully";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2023-02-16 00:35:05 +00:00
|
|
|
requires = [ "network.target" ];
|
2023-01-22 01:25:07 +00:00
|
|
|
after = [ "network.target" ];
|
2023-01-22 19:03:11 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2023-05-17 15:49:28 +00:00
|
|
|
EnvironmentFile = "/secrets/env";
|
2024-05-01 02:08:16 +00:00
|
|
|
DynamicUser = true;
|
2023-01-22 19:03:11 +00:00
|
|
|
};
|
2024-05-01 02:08:16 +00:00
|
|
|
path = [ pkgs.wget pkgs.ntfy-sh ];
|
2023-01-22 01:25:07 +00:00
|
|
|
script = ''
|
2024-05-01 02:08:16 +00:00
|
|
|
cd /tmp
|
2023-01-22 19:03:11 +00:00
|
|
|
ln -sf ${pkgs.writeText "tracktrain-config.yaml" tracktrain-config} config.yaml
|
|
|
|
${pkgs.tracktrain}/bin/tracktrain +RTS -T
|
2023-01-22 01:25:07 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
services.postgresql = {
|
|
|
|
enable = true;
|
2023-12-11 23:10:35 +00:00
|
|
|
package = pkgs.postgresql_15;
|
2023-01-22 01:25:07 +00:00
|
|
|
ensureDatabases = [ "tracktrain" ];
|
|
|
|
ensureUsers = [ {
|
|
|
|
name = "tracktrain";
|
2023-11-30 16:43:48 +00:00
|
|
|
ensureDBOwnership = true;
|
2023-01-22 01:25:07 +00:00
|
|
|
} ];
|
|
|
|
authentication = ''
|
2024-05-01 02:08:16 +00:00
|
|
|
local all all trust
|
2023-01-22 01:25:07 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-01-22 19:03:11 +00:00
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
|
|
|
port = 9001;
|
|
|
|
scrapeConfigs = [ {
|
|
|
|
job_name = "tracktrain";
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "0.0.0.0:4000" ];
|
|
|
|
}];
|
|
|
|
} ];
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.grafana.serviceConfig.EnvironmentFile =
|
2023-05-03 21:04:13 +00:00
|
|
|
"/secrets/env";
|
2024-01-31 22:30:06 +00:00
|
|
|
hacc.bindToPersist = [ "/var/lib/grafana" ];
|
2024-04-19 17:11:03 +00:00
|
|
|
};
|
2023-01-22 01:25:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|