Allow forwarding of multiple ports

This commit is contained in:
bluepython508
2023-12-08 15:51:38 +00:00
parent 259f002a99
commit fb93da101a
2 changed files with 46 additions and 29 deletions

View File

@@ -48,12 +48,14 @@
type = bool;
default = true;
};
proto = mkOption {type = proto;};
dest = mkOption {type = str;};
hostProto = mkOption {type = proto;};
port = mkOption {type = port;};
forwards = mkOption {
type = listOf (submodule {
proto = mkOption {type = proto;};
port = mkOption {type = port;};
dest = mkOption {type = str;};
});
};
};
config.hostProto = mkDefault config.proto;
}));
};
};
@@ -65,10 +67,7 @@
};
in
lib.mapAttrs' (hostname: {
proto,
hostProto,
port,
dest,
forwards,
enable,
...
}: let
@@ -78,7 +77,7 @@
value = {
inherit enable;
script = ''
TS_AUTHKEY=$(cat $RUNTIME_DIRECTORY/authkey) ${lib.getExe self.packages.${pkgs.system}.default} ${hostProto} ${hostname} ${toString port} ${proto} ${dest}
TS_AUTHKEY=$(cat $RUNTIME_DIRECTORY/authkey) ${lib.getExe self.packages.${pkgs.system}.default} ${hostname} ${lib.concatMapStringsSep " " ({proto, port, dest}: "${proto}:${proto}:${dest}") forwards}
'';
wantedBy = ["multi-user.target"];
serviceConfig = {