haccfiles/parsons/tracktrain.nix

103 lines
2.5 KiB
Nix
Raw Normal View History

{ 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"
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
clientName: tracktrain
# clientSecret defined in env file
logging:
ntfyTopic: ping.stuebinm.eu/monit
name: ilztalbahn
2023-01-22 19:03:11 +00:00
'';
in
2023-01-22 01:25:07 +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."/" = {
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/" = {
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
};
hacc.containers.tracktrain = {
bindSecrets = true;
2023-01-22 19:03:11 +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" ];
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";
EnvironmentFile = "/secrets/env";
DynamicUser = true;
2023-01-22 19:03:11 +00:00
};
path = [ pkgs.wget pkgs.ntfy-sh ];
2023-01-22 01:25:07 +00:00
script = ''
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";
ensureDBOwnership = true;
2023-01-22 01:25:07 +00:00
} ];
authentication = ''
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 =
"/secrets/env";
hacc.bindToPersist = [ "/var/lib/grafana" ];
};
2023-01-22 01:25:07 +00:00
};
}