2020-11-22 12:26:08 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.samba-wsdd;
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.samba-wsdd = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption ''
|
2022-11-09 21:45:00 +00:00
|
|
|
Web Services Dynamic Discovery host daemon. This enables (Samba) hosts, like your local NAS device,
|
2024-06-03 16:59:45 +00:00
|
|
|
to be found by Web Service Discovery Clients like Windows
|
2024-04-13 12:54:15 +00:00
|
|
|
'';
|
2020-11-22 12:26:08 +00:00
|
|
|
interface = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "eth0";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Interface or address to use.";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
hoplimit = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
|
|
|
default = null;
|
|
|
|
example = 2;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Hop limit for multicast packets (default = 1).";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
2023-07-13 18:06:44 +00:00
|
|
|
openFirewall = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = ''
|
2023-07-13 18:06:44 +00:00
|
|
|
Whether to open the required firewall ports in the firewall.
|
|
|
|
'';
|
|
|
|
default = false;
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
2020-11-22 12:26:08 +00:00
|
|
|
workgroup = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "HOME";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Set workgroup name (default WORKGROUP).";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
hostname = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
example = "FILESERVER";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Override (NetBIOS) hostname to be used (default hostname).";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
domain = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Set domain name (disables workgroup).";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
discovery = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Enable discovery operation mode.";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
listen = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/run/wsdd/wsdd.sock";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Listen on path or localhost port in discovery mode.";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
extraOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "--shortlog" ];
|
|
|
|
example = [ "--verbose" "--no-http" "--ipv4only" "--no-host" ];
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Additional wsdd options.";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.wsdd ];
|
|
|
|
|
|
|
|
systemd.services.samba-wsdd = {
|
|
|
|
description = "Web Services Dynamic Discovery host daemon";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.wsdd}/bin/wsdd ${optionalString (cfg.interface != null) "--interface '${cfg.interface}'"} \
|
|
|
|
${optionalString (cfg.hoplimit != null) "--hoplimit '${toString cfg.hoplimit}'"} \
|
|
|
|
${optionalString (cfg.workgroup != null) "--workgroup '${cfg.workgroup}'"} \
|
|
|
|
${optionalString (cfg.hostname != null) "--hostname '${cfg.hostname}'"} \
|
|
|
|
${optionalString (cfg.domain != null) "--domain '${cfg.domain}'"} \
|
|
|
|
${optionalString cfg.discovery "--discovery --listen '${cfg.listen}'"} \
|
|
|
|
${escapeShellArgs cfg.extraOptions}
|
|
|
|
'';
|
|
|
|
# Runtime directory and mode
|
|
|
|
RuntimeDirectory = "wsdd";
|
|
|
|
RuntimeDirectoryMode = "0750";
|
|
|
|
# Access write directories
|
|
|
|
UMask = "0027";
|
|
|
|
# Capabilities
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
# Security
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
# Sandboxing
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = false;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
2020-12-17 17:52:30 +00:00
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
|
2020-11-22 12:26:08 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
# System Call Filtering
|
|
|
|
SystemCallArchitectures = "native";
|
2021-05-13 12:29:25 +00:00
|
|
|
SystemCallFilter = "~@cpu-emulation @debug @mount @obsolete @privileged @resources";
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
};
|
2023-07-13 18:06:44 +00:00
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 5357 ];
|
|
|
|
allowedUDPPorts = [ 3702 ];
|
|
|
|
};
|
2020-11-22 12:26:08 +00:00
|
|
|
};
|
|
|
|
}
|