From 78cd5b3fec156409ab5ae12bbf0c8027e7c11be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 12 Jan 2024 14:25:31 +0100 Subject: [PATCH] zt-tcp-relay: add clan module + test --- checks/flake-module.nix | 1 + checks/zt-tcp-relay/default.nix | 20 ++++++++++++++++++++ clanModules/flake-module.nix | 1 + clanModules/zt-tcp-relay.nix | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 checks/zt-tcp-relay/default.nix create mode 100644 clanModules/zt-tcp-relay.nix diff --git a/checks/flake-module.nix b/checks/flake-module.nix index 6c4dd259..af78f7ac 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -19,6 +19,7 @@ container = import ./container nixosTestArgs; deltachat = import ./deltachat nixosTestArgs; meshnamed = import ./meshnamed nixosTestArgs; + zt-tcp-relay = import ./zt-tcp-relay nixosTestArgs; borgbackup = import ./borgbackup nixosTestArgs; syncthing = import ./syncthing nixosTestArgs; wayland-proxy-virtwl = import ./wayland-proxy-virtwl nixosTestArgs; diff --git a/checks/zt-tcp-relay/default.nix b/checks/zt-tcp-relay/default.nix new file mode 100644 index 00000000..a4fcea4a --- /dev/null +++ b/checks/zt-tcp-relay/default.nix @@ -0,0 +1,20 @@ +(import ../lib/container-test.nix) ({ pkgs, ... }: { + name = "zt-tcp-relay"; + + nodes.machine = { self, ... }: { + imports = [ + self.nixosModules.clanCore + self.clanModules.zt-tcp-relay + { + clanCore.machineName = "machine"; + clanCore.clanDir = ./.; + } + ]; + }; + testScript = '' + start_all() + machine.wait_for_unit("zt-tcp-relay.service") + out = machine.succeed("${pkgs.netcat}/bin/nc -z -v localhost 4443") + print(out) + ''; +}) diff --git a/clanModules/flake-module.nix b/clanModules/flake-module.nix index e620178d..e6c76b49 100644 --- a/clanModules/flake-module.nix +++ b/clanModules/flake-module.nix @@ -10,5 +10,6 @@ xfce = ./xfce.nix; borgbackup = ./borgbackup.nix; syncthing = ./syncthing.nix; + zt-tcp-relay = ./zt-tcp-relay.nix; }; } diff --git a/clanModules/zt-tcp-relay.nix b/clanModules/zt-tcp-relay.nix new file mode 100644 index 00000000..d48d550f --- /dev/null +++ b/clanModules/zt-tcp-relay.nix @@ -0,0 +1,23 @@ +{ pkgs, lib, config, ... }: { + options.clan.zt-tcp-relay = { + port = lib.mkOption { + type = lib.types.port; + default = 4443; + description = "Port to listen on"; + }; + }; + config = { + networking.firewall.allowedTCPPorts = [ config.clan.zt-tcp-relay.port ]; + + systemd.services.zt-tcp-relay = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + serviceConfig = { + ExecStart = "${pkgs.callPackage ../pkgs/zt-tcp-relay {}}/bin/zt-tcp-relay --listen [::]:${builtins.toString config.clan.zt-tcp-relay.port}"; + Restart = "always"; + RestartSec = "5"; + dynamicUsers = true; + }; + }; + }; +}