Loading nixos/modules/services/networking/kresd.nix +27 −30 Original line number Diff line number Diff line { config, lib, pkgs, ... }: with lib; let cfg = config.services.kresd; Loading @@ -12,11 +9,11 @@ let al_v4 = builtins.match "([0-9.]+):([0-9]+)($)" addr; al_v6 = builtins.match "\\[(.+)]:([0-9]+)(%.*|$)" addr; al_portOnly = builtins.match "(^)([0-9]+)" addr; al = findFirst (a: a != null) al = lib.findFirst (a: a != null) (throw "services.kresd.*: incorrect address specification '${addr}'") [ al_v4 al_v6 al_portOnly ]; port = elemAt al 1; addrSpec = if al_portOnly == null then "'${head al}${elemAt al 2}'" else "{'::', '0.0.0.0'}"; port = lib.elemAt al 1; addrSpec = if al_portOnly == null then "'${lib.head al}${lib.elemAt al 2}'" else "{'::', '0.0.0.0'}"; in # freebind is set for compatibility with earlier kresd services; # it could be configurable, for example. '' Loading @@ -25,30 +22,30 @@ let configFile = pkgs.writeText "kresd.conf" ( "" + concatMapStrings (mkListen "dns") cfg.listenPlain + concatMapStrings (mkListen "tls") cfg.listenTLS + concatMapStrings (mkListen "doh2") cfg.listenDoH + lib.concatMapStrings (mkListen "dns") cfg.listenPlain + lib.concatMapStrings (mkListen "tls") cfg.listenTLS + lib.concatMapStrings (mkListen "doh2") cfg.listenDoH + cfg.extraConfig ); in { meta.maintainers = [ maintainers.vcunat /* upstream developer */ ]; meta.maintainers = [ lib.maintainers.vcunat /* upstream developer */ ]; imports = [ (mkChangedOptionModule [ "services" "kresd" "interfaces" ] [ "services" "kresd" "listenPlain" ] (lib.mkChangedOptionModule [ "services" "kresd" "interfaces" ] [ "services" "kresd" "listenPlain" ] (config: let value = getAttrFromPath [ "services" "kresd" "interfaces" ] config; let value = lib.getAttrFromPath [ "services" "kresd" "interfaces" ] config; in map (iface: if elem ":" (stringToCharacters iface) then "[${iface}]:53" else "${iface}:53") # Syntax depends on being IPv6 or IPv4. (iface: if lib.elem ":" (lib.stringToCharacters iface) then "[${iface}]:53" else "${iface}:53") # Syntax depends on being IPv6 or IPv4. value ) ) (mkRemovedOptionModule [ "services" "kresd" "cacheDir" ] "Please use (bind-)mounting instead.") (lib.mkRemovedOptionModule [ "services" "kresd" "cacheDir" ] "Please use (bind-)mounting instead.") ]; ###### interface options.services.kresd = { enable = mkOption { type = types.bool; enable = lib.mkOption { type = lib.types.bool; default = false; description = '' Whether to enable knot-resolver domain name server. Loading @@ -57,18 +54,18 @@ in { and give commands interactively to kresd@1.service. ''; }; package = mkPackageOption pkgs "knot-resolver" { package = lib.mkPackageOption pkgs "knot-resolver" { example = "knot-resolver.override { extraFeatures = true; }"; }; extraConfig = mkOption { type = types.lines; extraConfig = lib.mkOption { type = lib.types.lines; default = ""; description = '' Extra lines to be added verbatim to the generated configuration file. ''; }; listenPlain = mkOption { type = with types; listOf str; listenPlain = lib.mkOption { type = with lib.types; listOf str; default = [ "[::1]:53" "127.0.0.1:53" ]; example = [ "53" ]; description = '' Loading @@ -76,8 +73,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; listenTLS = mkOption { type = with types; listOf str; listenTLS = lib.mkOption { type = with lib.types; listOf str; default = []; example = [ "198.51.100.1:853" "[2001:db8::1]:853" "853" ]; description = '' Loading @@ -85,8 +82,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; listenDoH = mkOption { type = with types; listOf str; listenDoH = lib.mkOption { type = with lib.types; listOf str; default = []; example = [ "198.51.100.1:443" "[2001:db8::1]:443" "443" ]; description = '' Loading @@ -94,8 +91,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; instances = mkOption { type = types.ints.unsigned; instances = lib.mkOption { type = lib.types.ints.unsigned; default = 1; description = '' The number of instances to start. They will be called kresd@{1,2,...}.service. Loading @@ -107,10 +104,10 @@ in { }; ###### implementation config = mkIf cfg.enable { config = lib.mkIf cfg.enable { environment.etc."knot-resolver/kresd.conf".source = configFile; # not required networking.resolvconf.useLocalResolver = mkDefault true; networking.resolvconf.useLocalResolver = lib.mkDefault true; users.users.knot-resolver = { isSystemUser = true; Loading @@ -124,7 +121,7 @@ in { systemd.targets.kresd = { # configure units started by default wantedBy = [ "multi-user.target" ]; wants = [ "kres-cache-gc.service" ] ++ map (i: "kresd@${toString i}.service") (range 1 cfg.instances); ++ map (i: "kresd@${toString i}.service") (lib.range 1 cfg.instances); }; systemd.services."kresd@".serviceConfig = { ExecStart = "${cfg.package}/bin/kresd --noninteractive " Loading Loading
nixos/modules/services/networking/kresd.nix +27 −30 Original line number Diff line number Diff line { config, lib, pkgs, ... }: with lib; let cfg = config.services.kresd; Loading @@ -12,11 +9,11 @@ let al_v4 = builtins.match "([0-9.]+):([0-9]+)($)" addr; al_v6 = builtins.match "\\[(.+)]:([0-9]+)(%.*|$)" addr; al_portOnly = builtins.match "(^)([0-9]+)" addr; al = findFirst (a: a != null) al = lib.findFirst (a: a != null) (throw "services.kresd.*: incorrect address specification '${addr}'") [ al_v4 al_v6 al_portOnly ]; port = elemAt al 1; addrSpec = if al_portOnly == null then "'${head al}${elemAt al 2}'" else "{'::', '0.0.0.0'}"; port = lib.elemAt al 1; addrSpec = if al_portOnly == null then "'${lib.head al}${lib.elemAt al 2}'" else "{'::', '0.0.0.0'}"; in # freebind is set for compatibility with earlier kresd services; # it could be configurable, for example. '' Loading @@ -25,30 +22,30 @@ let configFile = pkgs.writeText "kresd.conf" ( "" + concatMapStrings (mkListen "dns") cfg.listenPlain + concatMapStrings (mkListen "tls") cfg.listenTLS + concatMapStrings (mkListen "doh2") cfg.listenDoH + lib.concatMapStrings (mkListen "dns") cfg.listenPlain + lib.concatMapStrings (mkListen "tls") cfg.listenTLS + lib.concatMapStrings (mkListen "doh2") cfg.listenDoH + cfg.extraConfig ); in { meta.maintainers = [ maintainers.vcunat /* upstream developer */ ]; meta.maintainers = [ lib.maintainers.vcunat /* upstream developer */ ]; imports = [ (mkChangedOptionModule [ "services" "kresd" "interfaces" ] [ "services" "kresd" "listenPlain" ] (lib.mkChangedOptionModule [ "services" "kresd" "interfaces" ] [ "services" "kresd" "listenPlain" ] (config: let value = getAttrFromPath [ "services" "kresd" "interfaces" ] config; let value = lib.getAttrFromPath [ "services" "kresd" "interfaces" ] config; in map (iface: if elem ":" (stringToCharacters iface) then "[${iface}]:53" else "${iface}:53") # Syntax depends on being IPv6 or IPv4. (iface: if lib.elem ":" (lib.stringToCharacters iface) then "[${iface}]:53" else "${iface}:53") # Syntax depends on being IPv6 or IPv4. value ) ) (mkRemovedOptionModule [ "services" "kresd" "cacheDir" ] "Please use (bind-)mounting instead.") (lib.mkRemovedOptionModule [ "services" "kresd" "cacheDir" ] "Please use (bind-)mounting instead.") ]; ###### interface options.services.kresd = { enable = mkOption { type = types.bool; enable = lib.mkOption { type = lib.types.bool; default = false; description = '' Whether to enable knot-resolver domain name server. Loading @@ -57,18 +54,18 @@ in { and give commands interactively to kresd@1.service. ''; }; package = mkPackageOption pkgs "knot-resolver" { package = lib.mkPackageOption pkgs "knot-resolver" { example = "knot-resolver.override { extraFeatures = true; }"; }; extraConfig = mkOption { type = types.lines; extraConfig = lib.mkOption { type = lib.types.lines; default = ""; description = '' Extra lines to be added verbatim to the generated configuration file. ''; }; listenPlain = mkOption { type = with types; listOf str; listenPlain = lib.mkOption { type = with lib.types; listOf str; default = [ "[::1]:53" "127.0.0.1:53" ]; example = [ "53" ]; description = '' Loading @@ -76,8 +73,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; listenTLS = mkOption { type = with types; listOf str; listenTLS = lib.mkOption { type = with lib.types; listOf str; default = []; example = [ "198.51.100.1:853" "[2001:db8::1]:853" "853" ]; description = '' Loading @@ -85,8 +82,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; listenDoH = mkOption { type = with types; listOf str; listenDoH = lib.mkOption { type = with lib.types; listOf str; default = []; example = [ "198.51.100.1:443" "[2001:db8::1]:443" "443" ]; description = '' Loading @@ -94,8 +91,8 @@ in { For detailed syntax see ListenStream in {manpage}`systemd.socket(5)`. ''; }; instances = mkOption { type = types.ints.unsigned; instances = lib.mkOption { type = lib.types.ints.unsigned; default = 1; description = '' The number of instances to start. They will be called kresd@{1,2,...}.service. Loading @@ -107,10 +104,10 @@ in { }; ###### implementation config = mkIf cfg.enable { config = lib.mkIf cfg.enable { environment.etc."knot-resolver/kresd.conf".source = configFile; # not required networking.resolvconf.useLocalResolver = mkDefault true; networking.resolvconf.useLocalResolver = lib.mkDefault true; users.users.knot-resolver = { isSystemUser = true; Loading @@ -124,7 +121,7 @@ in { systemd.targets.kresd = { # configure units started by default wantedBy = [ "multi-user.target" ]; wants = [ "kres-cache-gc.service" ] ++ map (i: "kresd@${toString i}.service") (range 1 cfg.instances); ++ map (i: "kresd@${toString i}.service") (lib.range 1 cfg.instances); }; systemd.services."kresd@".serviceConfig = { ExecStart = "${cfg.package}/bin/kresd --noninteractive " Loading