···
homeDir = "/var/lib/nylon";
11
-
configFile = pkgs.writeText "nylon.conf" ''
11
+
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}
25
+
nylonOpts = { name, config, ... }: {
···
Enables nylon as a running service upon activation.
40
+
description = "The name of this nylon instance.";
nrConnections = mkOption {
···
110
+
config = { name = mkDefault name; };
113
+
mkNamedNylon = cfg: {
114
+
"nylon-${cfg.name}" = {
115
+
description = "Nylon, a lightweight SOCKS proxy server";
116
+
after = [ "network.target" ];
117
+
wantedBy = [ "multi-user.target" ];
122
+
WorkingDirectory = homeDir;
123
+
ExecStart = "${pkgs.nylon}/bin/nylon -f -c ${configFile cfg}";
128
+
anyNylons = collect (p: p ? enable) cfg;
129
+
enabledNylons = filter (p: p.enable == true) anyNylons;
130
+
nylonUnits = map (nylon: mkNamedNylon nylon) enabledNylons;
140
+
services.nylon = mkOption {
142
+
description = "Collection of named nylon instances";
143
+
type = with types; loaOf (submodule nylonOpts);
145
+
options = [ nylonOpts ];
114
-
config = mkIf cfg.enable {
152
+
config = mkIf (length(enabledNylons) > 0) {
116
-
users.extraUsers.nylon= {
154
+
users.extraUsers.nylon = {
description = "Nylon SOCKS Proxy";
···
users.extraGroups.nylon.gid = config.ids.gids.nylon;
126
-
systemd.services.nylon = {
127
-
description = "Nylon, a lightweight SOCKS proxy server";
128
-
after = [ "network.target" ];
129
-
wantedBy = [ "multi-user.target" ];
134
-
WorkingDirectory = homeDir;
135
-
ExecStart = "${pkgs.nylon}/bin/nylon -f -c ${configFile}";
164
+
systemd.services = fold (a: b: a // b) {} nylonUnits;