From 9af819b4b87560c3f26d70f061044038d95ce18a Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 22 Jan 2023 02:25:07 +0100 Subject: [PATCH] init tracktrain --- flake.lock | 20 ++++- flake.nix | 2 + hosts/parsons/configuration.nix | 1 + pkgs/default.nix | 4 + services/tracktrain.nix | 134 ++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 services/tracktrain.nix diff --git a/flake.lock b/flake.lock index cfbe523..f27c340 100644 --- a/flake.lock +++ b/flake.lock @@ -763,7 +763,8 @@ "nix-hexchen": "nix-hexchen", "nixos-mailserver": "nixos-mailserver", "nixpkgs": "nixpkgs", - "nixpkgs-unstable": "nixpkgs-unstable" + "nixpkgs-unstable": "nixpkgs-unstable", + "tracktrain": "tracktrain" } }, "rotate-text": { @@ -836,6 +837,23 @@ "type": "github" } }, + "tracktrain": { + "flake": false, + "locked": { + "lastModified": 1674348451, + "narHash": "sha256-fkVvjRe8wKKjEdLiRJV62nns0svy2pngE5jvsZjIlvE=", + "ref": "main", + "rev": "3d0980811d61a78f265ec06dd5bd4ef2cde1cbdf", + "revCount": 78, + "type": "git", + "url": "https://stuebinm.eu/git/tracktrain" + }, + "original": { + "ref": "main", + "type": "git", + "url": "https://stuebinm.eu/git/tracktrain" + } + }, "ts-fold": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index 527af0f..b68697e 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,8 @@ nixpkgs-unstable.url = "nixpkgs/nixpkgs-unstable"; nix-hexchen.url = "gitlab:hexchen/nixfiles"; nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-22.05"; + tracktrain.url = "git+https://stuebinm.eu/git/tracktrain?ref=main"; + tracktrain.flake = false; deploy-rs.url = "github:serokell/deploy-rs"; deploy-rs.inputs.nixpkgs.follows = "nixpkgs"; diff --git a/hosts/parsons/configuration.nix b/hosts/parsons/configuration.nix index 3cae7e5..cd62e67 100644 --- a/hosts/parsons/configuration.nix +++ b/hosts/parsons/configuration.nix @@ -19,6 +19,7 @@ ../../services/gitea.nix ../../services/nginx-pages.nix ../../services/vaultwarden.nix + ../../services/tracktrain.nix ../../services/uffd.nix ./lxc.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index 2ecf20e..c01a636 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -10,6 +10,10 @@ let mattermost = callPackage ./mattermost {inherit sources;}; + tracktrain = import sources.tracktrain { + nixpkgs = pkgs; + }; + # a version of the lounge with some extra css that # hides things the hacc-voc doesn't need thelounge-hacked = pkgs.stdenv.mkDerivation { diff --git a/services/tracktrain.nix b/services/tracktrain.nix new file mode 100644 index 0000000..ded85e7 --- /dev/null +++ b/services/tracktrain.nix @@ -0,0 +1,134 @@ +{ config, lib, pkgs, inputs, evalConfig, ... }: + +{ + services.nginx.virtualHosts."tracktrain.ilztalbahn.eu" = { + locations."/api" = { + proxyPass = "http://192.168.42.41:4000"; + proxyWebsockets = true; + extraConfig = '' + add_header 'Access-Control-Allow-Origin' '*' always; + ''; + }; + # locations."/metrics/" = { + # proxyPass = "http://localhost:2342"; + # proxyWebsockets = true; + # extraConfig = '' + # rewrite ^/metrics/(.*) /$1 break; + # ''; + # }; + enableACME = true; + forceSSL = true; + }; + + # services.prometheus = { + # enable = true; + # port = 9001; + # scrapeConfigs = [ { + # job_name = "tracktrain"; + # static_configs = [{ + # targets = [ "192.168.42.41:4000" ]; + # }]; + # } ]; + # }; + + # services.grafana = { + # enable = true; + # settings.server = { + # serve_from_sub_path = true; + # domain = "tracktrain.ilztalbahn.eu"; + # root_url = "%(protocol)s://%(domain)s:/metrics/"; + # http_port = 2342; + # http_addr = "0.0.0.0"; + # }; + + # provision = { + # enable = true; + # datasources.settings.datasources = [ { + # url = "http://localhost:9001"; + # type = "prometheus"; + # name = "prometheus"; + # } ]; + # }; + # }; + + networking.firewall.allowedTCPPorts = [ 443 ]; + + containers.tracktrain = { + privateNetwork = true; + hostAddress = "192.168.42.40"; + localAddress = "192.168.42.41"; + autoStart = true; + + bindMounts = { + "/persist" = { + hostPath = "/persist/containers/tracktrain"; + isReadOnly = false; + }; + }; + path = (evalConfig { + hosts = { }; + groups = { }; + } ({ config, lib, pkgs, profiles, modules, sources, ... }: { + boot.isContainer = true; + networking.useDHCP = false; + users.users.root.hashedPassword = ""; + system.stateVersion = "21.11"; + + imports = [ sources.nix-hexchen.nixosModules.profiles.nopersist ]; + networking.firewall.enable = false; + networking.defaultGateway = { + address = "192.168.100.1"; + interface = "eth0"; + }; + + systemd.services.tracktrain = { + enable = true; + + description = "tracks trains, hopefully"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + serviceConfig.Type = "simple"; + path = [ pkgs.wget ]; + script = '' + cd /tmp + # wget "https://ilztalbahn.eu/wp-content/uploads/2020/07/gtfs.zip" + ${(pkgs.tracktrain + # have to remove version constraints because some aren't in 22.05 + .overrideAttrs (old: { patchPhase = '' + sed -i "s/base.*/base/g" *.cabal + sed -i "s/^>=.*//g" *.cabal + sed -i "s/>=.*//g" *.cabal + ''; })) + }/bin/tracktrain --dbString="dbname=tracktrain user=tracktrain" --warp.port=4000 +RTS -T + ''; + startAt = "daily"; + }; + + services.postgresql = { + enable = true; + + ensureDatabases = [ "tracktrain" ]; + ensureUsers = [ { + name = "tracktrain"; + ensurePermissions = { + "DATABASE tracktrain" = "ALL PRIVILEGES"; + }; + } ]; + authentication = '' + local all all trust + host all all 127.0.0.1/32 trust + ''; + }; + + services.coredns = { + enable = true; + config = '' + .:53 { + forward . 1.1.1.1 + } + ''; + }; + })).config.system.build.toplevel; + }; + +}