nixos/services.samba-wsdd: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-28 21:18:59 +02:00 committed by Jörg Thalheim
parent 442fa2e366
commit 4174027fe9

View File

@ -1,65 +1,62 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
with lib;
let let
cfg = config.services.samba-wsdd; cfg = config.services.samba-wsdd;
in { in {
options = { options = {
services.samba-wsdd = { services.samba-wsdd = {
enable = mkEnableOption '' enable = lib.mkEnableOption ''
Web Services Dynamic Discovery host daemon. This enables (Samba) hosts, like your local NAS device, Web Services Dynamic Discovery host daemon. This enables (Samba) hosts, like your local NAS device,
to be found by Web Service Discovery Clients like Windows to be found by Web Service Discovery Clients like Windows
''; '';
interface = mkOption { interface = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "eth0"; example = "eth0";
description = "Interface or address to use."; description = "Interface or address to use.";
}; };
hoplimit = mkOption { hoplimit = lib.mkOption {
type = types.nullOr types.int; type = lib.types.nullOr lib.types.int;
default = null; default = null;
example = 2; example = 2;
description = "Hop limit for multicast packets (default = 1)."; description = "Hop limit for multicast packets (default = 1).";
}; };
openFirewall = mkOption { openFirewall = lib.mkOption {
description = '' description = ''
Whether to open the required firewall ports in the firewall. Whether to open the required firewall ports in the firewall.
''; '';
default = false; default = false;
type = lib.types.bool; type = lib.types.bool;
}; };
workgroup = mkOption { workgroup = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "HOME"; example = "HOME";
description = "Set workgroup name (default WORKGROUP)."; description = "Set workgroup name (default WORKGROUP).";
}; };
hostname = mkOption { hostname = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
example = "FILESERVER"; example = "FILESERVER";
description = "Override (NetBIOS) hostname to be used (default hostname)."; description = "Override (NetBIOS) hostname to be used (default hostname).";
}; };
domain = mkOption { domain = lib.mkOption {
type = types.nullOr types.str; type = lib.types.nullOr lib.types.str;
default = null; default = null;
description = "Set domain name (disables workgroup)."; description = "Set domain name (disables workgroup).";
}; };
discovery = mkOption { discovery = lib.mkOption {
type = types.bool; type = lib.types.bool;
default = false; default = false;
description = "Enable discovery operation mode."; description = "Enable discovery operation mode.";
}; };
listen = mkOption { listen = lib.mkOption {
type = types.str; type = lib.types.str;
default = "/run/wsdd/wsdd.sock"; default = "/run/wsdd/wsdd.sock";
description = "Listen on path or localhost port in discovery mode."; description = "Listen on path or localhost port in discovery mode.";
}; };
extraOptions = mkOption { extraOptions = lib.mkOption {
type = types.listOf types.str; type = lib.types.listOf lib.types.str;
default = [ "--shortlog" ]; default = [ "--shortlog" ];
example = [ "--verbose" "--no-http" "--ipv4only" "--no-host" ]; example = [ "--verbose" "--no-http" "--ipv4only" "--no-host" ];
description = "Additional wsdd options."; description = "Additional wsdd options.";
@ -67,7 +64,7 @@ in {
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.wsdd ]; environment.systemPackages = [ pkgs.wsdd ];
@ -79,13 +76,13 @@ in {
DynamicUser = true; DynamicUser = true;
Type = "simple"; Type = "simple";
ExecStart = '' ExecStart = ''
${pkgs.wsdd}/bin/wsdd ${optionalString (cfg.interface != null) "--interface '${cfg.interface}'"} \ ${pkgs.wsdd}/bin/wsdd ${lib.optionalString (cfg.interface != null) "--interface '${cfg.interface}'"} \
${optionalString (cfg.hoplimit != null) "--hoplimit '${toString cfg.hoplimit}'"} \ ${lib.optionalString (cfg.hoplimit != null) "--hoplimit '${toString cfg.hoplimit}'"} \
${optionalString (cfg.workgroup != null) "--workgroup '${cfg.workgroup}'"} \ ${lib.optionalString (cfg.workgroup != null) "--workgroup '${cfg.workgroup}'"} \
${optionalString (cfg.hostname != null) "--hostname '${cfg.hostname}'"} \ ${lib.optionalString (cfg.hostname != null) "--hostname '${cfg.hostname}'"} \
${optionalString (cfg.domain != null) "--domain '${cfg.domain}'"} \ ${lib.optionalString (cfg.domain != null) "--domain '${cfg.domain}'"} \
${optionalString cfg.discovery "--discovery --listen '${cfg.listen}'"} \ ${lib.optionalString cfg.discovery "--discovery --listen '${cfg.listen}'"} \
${escapeShellArgs cfg.extraOptions} ${lib.escapeShellArgs cfg.extraOptions}
''; '';
# Runtime directory and mode # Runtime directory and mode
RuntimeDirectory = "wsdd"; RuntimeDirectory = "wsdd";
@ -121,7 +118,7 @@ in {
}; };
}; };
networking.firewall = mkIf cfg.openFirewall { networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ 5357 ]; allowedTCPPorts = [ 5357 ];
allowedUDPPorts = [ 3702 ]; allowedUDPPorts = [ 3702 ];
}; };