1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-25 02:26:19 +03:00

nixos/services.nylon: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-30 00:47:09 +02:00
parent 2bf4393a9b
commit 2d4a4c110a

View file

@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.nylon; cfg = config.services.nylon;
@ -18,78 +15,78 @@ let
Binding-Interface=${cfg.acceptInterface} Binding-Interface=${cfg.acceptInterface}
Connecting-Interface=${cfg.bindInterface} Connecting-Interface=${cfg.bindInterface}
Port=${toString cfg.port} Port=${toString cfg.port}
Allow-IP=${concatStringsSep " " cfg.allowedIPRanges} Allow-IP=${lib.concatStringsSep " " cfg.allowedIPRanges}
Deny-IP=${concatStringsSep " " cfg.deniedIPRanges} Deny-IP=${lib.concatStringsSep " " cfg.deniedIPRanges}
''; '';
nylonOpts = { name, ... }: { nylonOpts = { name, ... }: {
options = { options = {
enable = mkOption { enable = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Enables nylon as a running service upon activation. Enables nylon as a running service upon activation.
''; '';
}; };
name = mkOption { name = lib.mkOption {
type = types.str; type = lib.types.str;
default = ""; default = "";
description = "The name of this nylon instance."; description = "The name of this nylon instance.";
}; };
nrConnections = mkOption { nrConnections = lib.mkOption {
type = types.int; type = lib.types.int;
default = 10; default = 10;
description = '' description = ''
The number of allowed simultaneous connections to the daemon, default 10. The number of allowed simultaneous connections to the daemon, default 10.
''; '';
}; };
logging = mkOption { logging = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Enable logging, default is no logging. Enable logging, default is no logging.
''; '';
}; };
verbosity = mkOption { verbosity = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = '' description = ''
Enable verbose output, default is to not be verbose. Enable verbose output, default is to not be verbose.
''; '';
}; };
acceptInterface = mkOption { acceptInterface = lib.mkOption {
type = types.str; type = lib.types.str;
default = "lo"; default = "lo";
description = '' description = ''
Tell nylon which interface to listen for client requests on, default is "lo". Tell nylon which interface to listen for client requests on, default is "lo".
''; '';
}; };
bindInterface = mkOption { bindInterface = lib.mkOption {
type = types.str; type = lib.types.str;
default = "enp3s0f0"; default = "enp3s0f0";
description = '' description = ''
Tell nylon which interface to use as an uplink, default is "enp3s0f0". Tell nylon which interface to use as an uplink, default is "enp3s0f0".
''; '';
}; };
port = mkOption { port = lib.mkOption {
type = types.port; type = lib.types.port;
default = 1080; default = 1080;
description = '' description = ''
What port to listen for client requests, default is 1080. What port to listen for client requests, default is 1080.
''; '';
}; };
allowedIPRanges = mkOption { allowedIPRanges = lib.mkOption {
type = with types; listOf str; type = with lib.types; listOf str;
default = [ "192.168.0.0/16" "127.0.0.1/8" "172.16.0.1/12" "10.0.0.0/8" ]; default = [ "192.168.0.0/16" "127.0.0.1/8" "172.16.0.1/12" "10.0.0.0/8" ];
description = '' description = ''
Allowed client IP ranges are evaluated first, defaults to ARIN IPv4 private ranges: Allowed client IP ranges are evaluated first, defaults to ARIN IPv4 private ranges:
@ -97,8 +94,8 @@ let
''; '';
}; };
deniedIPRanges = mkOption { deniedIPRanges = lib.mkOption {
type = with types; listOf str; type = with lib.types; listOf str;
default = [ "0.0.0.0/0" ]; default = [ "0.0.0.0/0" ];
description = '' description = ''
Denied client IP ranges, these gets evaluated after the allowed IP ranges, defaults to all IPv4 addresses: Denied client IP ranges, these gets evaluated after the allowed IP ranges, defaults to all IPv4 addresses:
@ -107,7 +104,7 @@ let
''; '';
}; };
}; };
config = { name = mkDefault name; }; config = { name = lib.mkDefault name; };
}; };
mkNamedNylon = cfg: { mkNamedNylon = cfg: {
@ -125,8 +122,8 @@ let
}; };
}; };
anyNylons = collect (p: p ? enable) cfg; anyNylons = lib.collect (p: p ? enable) cfg;
enabledNylons = filter (p: p.enable == true) anyNylons; enabledNylons = lib.filter (p: p.enable == true) anyNylons;
nylonUnits = map (nylon: mkNamedNylon nylon) enabledNylons; nylonUnits = map (nylon: mkNamedNylon nylon) enabledNylons;
in in
@ -137,10 +134,10 @@ in
options = { options = {
services.nylon = mkOption { services.nylon = lib.mkOption {
default = {}; default = {};
description = "Collection of named nylon instances"; description = "Collection of named nylon instances";
type = with types; attrsOf (submodule nylonOpts); type = with lib.types; attrsOf (submodule nylonOpts);
internal = true; internal = true;
}; };
@ -148,7 +145,7 @@ in
###### implementation ###### implementation
config = mkIf (length(enabledNylons) > 0) { config = lib.mkIf (lib.length(enabledNylons) > 0) {
users.users.nylon = { users.users.nylon = {
group = "nylon"; group = "nylon";
@ -160,7 +157,7 @@ in
users.groups.nylon.gid = config.ids.gids.nylon; users.groups.nylon.gid = config.ids.gids.nylon;
systemd.services = foldr (a: b: a // b) {} nylonUnits; systemd.services = lib.foldr (a: b: a // b) {} nylonUnits;
}; };
} }