From e10ce84e27a0ef42b885102d61e2f1831cede091 Mon Sep 17 00:00:00 2001 From: Izorkin Date: Sat, 21 Nov 2020 22:33:28 +0300 Subject: [PATCH 1/3] wsdd: init at 0.6.2 --- pkgs/servers/wsdd/default.nix | 30 ++++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 32 insertions(+) create mode 100644 pkgs/servers/wsdd/default.nix diff --git a/pkgs/servers/wsdd/default.nix b/pkgs/servers/wsdd/default.nix new file mode 100644 index 000000000000..059c401deadc --- /dev/null +++ b/pkgs/servers/wsdd/default.nix @@ -0,0 +1,30 @@ +{ stdenv, fetchFromGitHub, makeWrapper, python3 }: + +stdenv.mkDerivation rec { + pname = "wsdd"; + version = "0.6.2"; + + src = fetchFromGitHub { + owner = "christgau"; + repo = pname; + rev = "v${version}"; + sha256 = "0444xh1r5wd0zfch1hg1f9s4cw68srrm87hqx16qvlgx6jmz5j0p"; + }; + + nativeBuildInputs = [ makeWrapper ]; + + buildInputs = [ python3 ]; + + installPhase = '' + install -Dm0755 src/wsdd.py $out/bin/wsdd + wrapProgram $out/bin/wsdd --prefix PYTHONPATH : "$PYTHONPATH" + ''; + + meta = with stdenv.lib; { + homepage = "https://github.com/christgau/wsdd"; + description = "A Web Service Discovery (WSD) host daemon for SMB/Samba"; + maintainers = with maintainers; [ izorkin ]; + license = licenses.mit; + platforms = platforms.all; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 43ced1f6b2e5..dff3f86497b4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17581,6 +17581,8 @@ in webmetro = callPackage ../servers/webmetro { }; + wsdd = callPackage ../servers/wsdd { }; + webhook = callPackage ../servers/http/webhook { }; winstone = throw "Winstone is not supported anymore. Alternatives are Jetty or Tomcat."; From 03760ab82efff292a790876fd73a4c4904a2cf92 Mon Sep 17 00:00:00 2001 From: Izorkin Date: Sun, 22 Nov 2020 15:26:08 +0300 Subject: [PATCH 2/3] nixos/samba-wsdd: init service samba-wsdd --- nixos/doc/manual/release-notes/rl-2103.xml | 5 + nixos/modules/module-list.nix | 1 + .../network-filesystems/samba-wsdd.nix | 124 ++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 nixos/modules/services/network-filesystems/samba-wsdd.nix diff --git a/nixos/doc/manual/release-notes/rl-2103.xml b/nixos/doc/manual/release-notes/rl-2103.xml index 55c1229a164d..a77a60c46c20 100644 --- a/nixos/doc/manual/release-notes/rl-2103.xml +++ b/nixos/doc/manual/release-notes/rl-2103.xml @@ -56,6 +56,11 @@ section of the NixOS manual for more information. + + + Web Services Dynamic Discovery host daemon + + diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0a38fa317305..214d9356aa6a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -583,6 +583,7 @@ ./services/network-filesystems/orangefs/client.nix ./services/network-filesystems/rsyncd.nix ./services/network-filesystems/samba.nix + ./services/network-filesystems/samba-wsdd.nix ./services/network-filesystems/tahoe.nix ./services/network-filesystems/diod.nix ./services/network-filesystems/u9fs.nix diff --git a/nixos/modules/services/network-filesystems/samba-wsdd.nix b/nixos/modules/services/network-filesystems/samba-wsdd.nix new file mode 100644 index 000000000000..004d07064afd --- /dev/null +++ b/nixos/modules/services/network-filesystems/samba-wsdd.nix @@ -0,0 +1,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. + + If you use the firewall consider adding the following: + + networking.firewall.allowedTCPPorts = [ 5357 ]; + networking.firewall.allowedUDPPorts = [ 3702 ]; + + + ''; + 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" ]; + RestrictNamespaces = true; + LockPersonality = true; + MemoryDenyWriteExecute = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + PrivateMounts = true; + # System Call Filtering + SystemCallArchitectures = "native"; + SystemCallFilter = "~@clock @cpu-emulation @debug @module @mount @obsolete @privileged @raw-io @reboot @resources @swap"; + }; + }; + }; +} From 0aa34a03d000515370086d81686f4110a894751d Mon Sep 17 00:00:00 2001 From: Izorkin Date: Mon, 23 Nov 2020 17:13:22 +0300 Subject: [PATCH 3/3] nixos/tests/samba-wsdd: add check WSD Discovery --- nixos/tests/all-tests.nix | 1 + nixos/tests/samba-wsdd.nix | 44 +++++++++++++++++++++++++++++++++++ pkgs/servers/wsdd/default.nix | 6 ++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/samba-wsdd.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3c10d6215186..899509696e3c 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -315,6 +315,7 @@ in runInMachine = handleTest ./run-in-machine.nix {}; rxe = handleTest ./rxe.nix {}; samba = handleTest ./samba.nix {}; + samba-wsdd = handleTest ./samba-wsdd.nix {}; sanoid = handleTest ./sanoid.nix {}; sbt = handleTest ./sbt.nix {}; sbt-extras = handleTest ./sbt-extras.nix {}; diff --git a/nixos/tests/samba-wsdd.nix b/nixos/tests/samba-wsdd.nix new file mode 100644 index 000000000000..1edef6c0056d --- /dev/null +++ b/nixos/tests/samba-wsdd.nix @@ -0,0 +1,44 @@ +import ./make-test-python.nix ({ pkgs, ... }: + +{ + name = "samba-wsdd"; + meta.maintainers = with pkgs.stdenv.lib.maintainers; [ izorkin ]; + + nodes = { + client_wsdd = { pkgs, ... }: { + services.samba-wsdd = { + enable = true; + interface = "eth1"; + workgroup = "WORKGROUP"; + hostname = "CLIENT-WSDD"; + discovery = true; + extraOptions = [ "--no-host" ]; + }; + networking.firewall.allowedTCPPorts = [ 5357 ]; + networking.firewall.allowedUDPPorts = [ 3702 ]; + }; + + server_wsdd = { ... }: { + services.samba-wsdd = { + enable = true; + interface = "eth1"; + workgroup = "WORKGROUP"; + hostname = "SERVER-WSDD"; + }; + networking.firewall.allowedTCPPorts = [ 5357 ]; + networking.firewall.allowedUDPPorts = [ 3702 ]; + }; + }; + + testScript = '' + client_wsdd.start() + client_wsdd.wait_for_unit("samba-wsdd") + + server_wsdd.start() + server_wsdd.wait_for_unit("samba-wsdd") + + client_wsdd.wait_until_succeeds( + "echo list | ${pkgs.libressl.nc}/bin/nc -U /run/wsdd/wsdd.sock | grep -i SERVER-WSDD" + ) + ''; +}) diff --git a/pkgs/servers/wsdd/default.nix b/pkgs/servers/wsdd/default.nix index 059c401deadc..1411b6f3adcf 100644 --- a/pkgs/servers/wsdd/default.nix +++ b/pkgs/servers/wsdd/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchFromGitHub, makeWrapper, python3 }: +{ stdenv, fetchFromGitHub, makeWrapper, nixosTests, python3 }: stdenv.mkDerivation rec { pname = "wsdd"; @@ -20,6 +20,10 @@ stdenv.mkDerivation rec { wrapProgram $out/bin/wsdd --prefix PYTHONPATH : "$PYTHONPATH" ''; + passthru = { + tests.samba-wsdd = nixosTests.samba-wsdd; + }; + meta = with stdenv.lib; { homepage = "https://github.com/christgau/wsdd"; description = "A Web Service Discovery (WSD) host daemon for SMB/Samba";