summary refs log tree commit diff
path: root/nixos/modules/services/network-filesystems/samba-wsdd.nix
blob: 800ef448d37698d1576e43f80617151d136d8fe7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.samba-wsdd;

in {
  options = {
    services.samba-wsdd = {
      enable = mkEnableOption ''
        Enable 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.
        <note>
          <para>If you use the firewall consider adding the following:</para>
          <programlisting>
            networking.firewall.allowedTCPPorts = [ 5357 ];
            networking.firewall.allowedUDPPorts = [ 3702 ];
          </programlisting>
        </note>
      '';
      interface = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "eth0";
        description = "Interface or address to use.";
      };
      hoplimit = mkOption {
        type = types.nullOr types.int;
        default = null;
        example = 2;
        description = "Hop limit for multicast packets (default = 1).";
      };
      workgroup = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "HOME";
        description = "Set workgroup name (default WORKGROUP).";
      };
      hostname = mkOption {
        type = types.nullOr types.str;
        default = null;
        example = "FILESERVER";
        description = "Override (NetBIOS) hostname to be used (default hostname).";
      };
      domain = mkOption {
        type = types.nullOr types.str;
        default = null;
        description = "Set domain name (disables workgroup).";
      };
      discovery = mkOption {
        type = types.bool;
        default = false;
        description = "Enable discovery operation mode.";
      };
      listen = mkOption {
        type = types.str;
        default = "/run/wsdd/wsdd.sock";
        description = "Listen on path or localhost port in discovery mode.";
      };
      extraOptions = mkOption {
        type = types.listOf types.str;
        default = [ "--shortlog" ];
        example = [ "--verbose" "--no-http" "--ipv4only" "--no-host" ];
        description = "Additional wsdd options.";
      };
    };
  };

  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;
        RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
        RestrictNamespaces = true;
        LockPersonality = true;
        MemoryDenyWriteExecute = true;
        RestrictRealtime = true;
        RestrictSUIDSGID = true;
        PrivateMounts = true;
        # System Call Filtering
        SystemCallArchitectures = "native";
        SystemCallFilter = "~@cpu-emulation @debug @mount @obsolete @privileged @resources";
      };
    };
  };
}