From 680b2b036d358546d41c6da1275aa3573043f537 Mon Sep 17 00:00:00 2001 From: ahuston-0 Date: Fri, 16 Aug 2024 08:59:15 -0400 Subject: [PATCH] introduce lib.rad-dev.mapAttrsToString, fix mc-router Signed-off-by: ahuston-0 --- lib/default.nix | 15 +++++++++++++++ systems/palatine-hill/docker/minecraft.nix | 13 ++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index bda2197..860d1dd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -58,5 +58,20 @@ # fileList :: Path -> String -> [Path] fileList = dir: map (file: dir + "/${file}") (ls dir); + # reduce an attribute set to a string + # + # example: + # given attrset {host1 = "palatine-hill"; host2 = "jeeves";} + # and func (host: hostname: host + " is " + hostname + ", " ) + # mapAttrsToString would return 'host1 is palatine-hill, host2 is jeeves, ' + # + # args: + # func: an function to apply to attrSet to turn each entry into one string + # attrSet: an attribute set to reduce + # + # type: + # mapAttrsToString :: AttrSet -> (String -> Any -> String) -> String + mapAttrsToString = + func: attrSet: (lib.foldl' (cur: next: cur + next) "" (lib.mapAttrsToList func attrSet)); }; } diff --git a/systems/palatine-hill/docker/minecraft.nix b/systems/palatine-hill/docker/minecraft.nix index 21c49cd..26088b5 100644 --- a/systems/palatine-hill/docker/minecraft.nix +++ b/systems/palatine-hill/docker/minecraft.nix @@ -21,7 +21,7 @@ let USE_AIKAR_FLAGS = "true"; MEMORY = "8GB"; ALLOW_FLIGHT = "true"; - MAX_TICK_TIME = -1; + MAX_TICK_TIME = "-1"; }; defaultOptions = [ @@ -32,7 +32,7 @@ let ]; in { - virtualisation.oci-containers = { + virtualisation.oci-containers.containers = { mc-router = { image = "itzg/mc-router:latest"; extraOptions = [ @@ -40,9 +40,12 @@ in "--network=haproxy-net" "--network=minecraft-net" ]; - command = - "--mapping=mc.alicehuston.xyz=${defaultServer}:25565" - + (lib.mapAttrs (hostname: url: ",${url}=${hostname}:25565") servers); + cmd = [ + ( + "--mapping=mc.alicehuston.xyz=${defaultServer}:25565" + + (lib.rad-dev.mapAttrsToString (hostname: url: "," + url + "=" + hostname + ":25565") servers) + ) + ]; }; rlcraft = { image = "itzg/minecraft-server:java8";