···
homeDir = "/var/lib/nylon";
+
configFile = cfg: pkgs.writeText "nylon-${cfg.name}.conf" ''
No-Simultaneous-Conn=${toString cfg.nrConnections}
Log=${if cfg.logging then "1" else "0"}
···
Deny-IP=${concatStringsSep " " cfg.deniedIPRanges}
+
nylonOpts = { name, config, ... }: {
···
Enables nylon as a running service upon activation.
+
description = "The name of this nylon instance.";
nrConnections = mkOption {
···
+
config = { name = mkDefault name; };
+
"nylon-${cfg.name}" = {
+
description = "Nylon, a lightweight SOCKS proxy server";
+
after = [ "network.target" ];
+
wantedBy = [ "multi-user.target" ];
+
WorkingDirectory = homeDir;
+
ExecStart = "${pkgs.nylon}/bin/nylon -f -c ${configFile cfg}";
+
anyNylons = collect (p: p ? enable) cfg;
+
enabledNylons = filter (p: p.enable == true) anyNylons;
+
nylonUnits = map (nylon: mkNamedNylon nylon) enabledNylons;
+
services.nylon = mkOption {
+
description = "Collection of named nylon instances";
+
type = with types; loaOf (submodule nylonOpts);
+
options = [ nylonOpts ];
+
config = mkIf (length(enabledNylons) > 0) {
+
users.extraUsers.nylon = {
description = "Nylon SOCKS Proxy";
···
users.extraGroups.nylon.gid = config.ids.gids.nylon;
+
systemd.services = fold (a: b: a // b) {} nylonUnits;