nixos: nylon, use named instances
This commit is contained in:
parent
612333a770
commit
b08524bf01
@ -8,7 +8,7 @@ let
|
|||||||
|
|
||||||
homeDir = "/var/lib/nylon";
|
homeDir = "/var/lib/nylon";
|
||||||
|
|
||||||
configFile = pkgs.writeText "nylon.conf" ''
|
configFile = cfg: pkgs.writeText "nylon-${cfg.name}.conf" ''
|
||||||
[General]
|
[General]
|
||||||
No-Simultaneous-Conn=${toString cfg.nrConnections}
|
No-Simultaneous-Conn=${toString cfg.nrConnections}
|
||||||
Log=${if cfg.logging then "1" else "0"}
|
Log=${if cfg.logging then "1" else "0"}
|
||||||
@ -22,16 +22,10 @@ let
|
|||||||
Deny-IP=${concatStringsSep " " cfg.deniedIPRanges}
|
Deny-IP=${concatStringsSep " " cfg.deniedIPRanges}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
nylonOpts = { name, config, ... }: {
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
###### interface
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.nylon = {
|
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
@ -40,6 +34,12 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
name = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
description = "The name of this nylon instance.";
|
||||||
|
};
|
||||||
|
|
||||||
nrConnections = mkOption {
|
nrConnections = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
default = 10;
|
default = 10;
|
||||||
@ -107,13 +107,51 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
config = { name = mkDefault name; };
|
||||||
|
};
|
||||||
|
|
||||||
|
mkNamedNylon = cfg: {
|
||||||
|
"nylon-${cfg.name}" = {
|
||||||
|
description = "Nylon, a lightweight SOCKS proxy server";
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig =
|
||||||
|
{
|
||||||
|
User = "nylon";
|
||||||
|
Group = "nylon";
|
||||||
|
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;
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
services.nylon = mkOption {
|
||||||
|
default = {};
|
||||||
|
description = "Collection of named nylon instances";
|
||||||
|
type = with types; loaOf (submodule nylonOpts);
|
||||||
|
internal = true;
|
||||||
|
options = [ nylonOpts ];
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf (length(enabledNylons) > 0) {
|
||||||
|
|
||||||
users.extraUsers.nylon= {
|
users.extraUsers.nylon = {
|
||||||
group = "nylon";
|
group = "nylon";
|
||||||
description = "Nylon SOCKS Proxy";
|
description = "Nylon SOCKS Proxy";
|
||||||
home = homeDir;
|
home = homeDir;
|
||||||
@ -123,17 +161,7 @@ in
|
|||||||
|
|
||||||
users.extraGroups.nylon.gid = config.ids.gids.nylon;
|
users.extraGroups.nylon.gid = config.ids.gids.nylon;
|
||||||
|
|
||||||
systemd.services.nylon = {
|
systemd.services = fold (a: b: a // b) {} nylonUnits;
|
||||||
description = "Nylon, a lightweight SOCKS proxy server";
|
|
||||||
after = [ "network.target" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
serviceConfig =
|
|
||||||
{
|
|
||||||
User = "nylon";
|
|
||||||
Group = "nylon";
|
|
||||||
WorkingDirectory = homeDir;
|
|
||||||
ExecStart = "${pkgs.nylon}/bin/nylon -f -c ${configFile}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user