Toggle diff (471 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 12ecc1b952..614d0a0e03 100644
@@ -106,6 +106,7 @@ Copyright @copyright{} 2022 Philip M@sup{c}Grath@*
Copyright @copyright{} 2022 Karl Hallsby@*
Copyright @copyright{} 2022 Justin Veilleux@*
Copyright @copyright{} 2022 Reily Siegel@*
+Copyright @copyright{} 2022 Simon Streit@*
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -385,6 +386,7 @@ Services
* DNS Services:: DNS daemons.
* VPN Services:: VPN daemons.
* Network File System:: NFS related services.
+* Samba Services:: Samba services.
* Continuous Integration:: Cuirass and Laminar services.
* Power Management Services:: Extending battery life.
* Audio Services:: The MPD.
@@ -17451,6 +17453,7 @@ declaration.
* DNS Services:: DNS daemons.
* VPN Services:: VPN daemons.
* Network File System:: NFS related services.
+* Samba Services:: Samba services.
* Continuous Integration:: Cuirass and Laminar services.
* Power Management Services:: Extending battery life.
* Audio Services:: The MPD.
@@ -31194,6 +31197,56 @@ The verbosity level of the daemon.
+@node Samba Services, Continuous Integration, Network File System, Services
+@subsection Samba Services
+The @code{(gnu services samba)} module provides service definitions for
+Samba as well as additional helper services. Currently it provides the
+@uref{https://www.samba.org, Samba} provides network shares for folders
+and printers using the SMB/CIFS protocol commonly used on Windows. It
+can also act as an Active Directory Domain Controller (AD DC) for other
+hosts in an heterougenious network with different types of Computer
+@defvar {Scheme variable} samba-service-type
+The service type to enable the samba services @code{samba}, @code{nmbd},
+@code{smbd} and @code{winbindd}. By default this service type does not
+run as an AD DC, hence @code{samba} remains disabled.
+@deftp{Data Type} samba-service-configuration
+Configuration record for the Samba suite.
+@item @code{package} (default: @code{samba})
+The samba package to use.
+@item @code{config-file} (default: @code{#f})
+@item @code{enable-samba?} (default: @code{#f})
+Manually enable the @code{samba} daemon.
+@item @code{enable-smbd?} (default: @code{#f})
+Manually enable the @code{smbd} daemon.
+@item @code{enable-nmbd?} (default: @code{#f})
+Manually enable the @code{nmbd} daemon.
+@item @code{enable-winbindd?} (default: @code{#f})
+Manually enable the @code{winbindd} daemon.
@node Continuous Integration
@subsection Continuous Integration
diff --git a/gnu/local.mk b/gnu/local.mk
index 72637761d5..9c1f5ff5b8 100644
@@ -676,6 +676,7 @@ GNU_SYSTEM_MODULES = \
+ %D%/services/samba.scm \
@@ -754,6 +755,7 @@ GNU_SYSTEM_MODULES = \
%D%/tests/package-management.scm \
%D%/tests/reconfigure.scm \
%D%/tests/security-token.scm \
%D%/tests/singularity.scm \
diff --git a/gnu/services/samba.scm b/gnu/services/samba.scm
index 0000000000..2c9e52a0b0
+++ b/gnu/services/samba.scm
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
+;;; This file is part of GNU Guix.
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+(define-module (gnu services samba)
+ #:use-module (gnu packages)
+ #:use-module (gnu packages base)
+ #:use-module (gnu packages admin)
+ #:use-module (gnu packages samba)
+ #:use-module (gnu services)
+ #:use-module (gnu services configuration)
+ #:use-module (gnu services shepherd)
+ #:use-module (gnu services base)
+ #:use-module (gnu system shadow)
+ #:use-module (guix gexp)
+ #:use-module (guix packages)
+ #:use-module (guix modules)
+ #:use-module (guix records)
+ #:use-module (ice-9 format)
+ #:use-module (ice-9 match)
+ #:use-module (ice-9 textual-ports)
+ #:use-module (srfi srfi-1)
+ #:export (samba-service-type
+ (plain-file "smb.conf" "[global]
+ server string = Samba Server
+ server role = standalone server
+ log file = /var/log/samba/log.%m
+(define-record-type* <samba-configuration>
+ make-samba-configuration
+ (package samba-configuration-package
+ (config-file samba-configuration-config-file
+ (enable-samba? samba-configuration-enable-samba?
+ (enable-smbd? samba-configuration-enable-smbd?
+ (enable-nmbd? samba-configuration-enable-nmbd?
+ (enable-winbindd? samba-configuration-enable-winbindd?
+(define (samba-activation config)
+ (let ((package (samba-configuration-package config))
+ (config-file (samba-configuration-config-file config)))
+ (with-imported-modules '((guix build utils))
+ (let ((lib-dir "/var/lib/samba")
+ (log-dir "/var/log/samba")
+ (run-dir "/var/run/samba")
+ (lock-dir "/var/lock/samba")
+ (cache-dir "/var/cache/samba")
+ (smb.conf "/etc/samba/smb.conf"))
+ (use-modules (guix build utils))
+ (mkdir-p/perms (string-append #$lib-dir "/private")
+ (getpwnam "root") #o700)
+ (copy-file #$config-file #$smb.conf)
+ (invoke #$(file-append package "/bin/testparm")
+ "--suppress-prompt" #$smb.conf))))))
+(define (samba-samba-shepherd-service config)
+ (let ((package (samba-configuration-package config))
+ (config-file (samba-configuration-config-file config)))
+ (list (shepherd-service
+ (documentation "Run Samba")
+ (provision '(samba-samba))
+ (requirement '(networking))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/sbin/samba")
+ (string-append "--configfile=" #$config-file)
+ "--no-process-group")))
+ (stop #~(make-kill-destructor))))))
+(define (samba-nmbd-shepherd-service config)
+ (let ((package (samba-configuration-package config))
+ (config-file (samba-configuration-config-file config)))
+ (list (shepherd-service
+ (documentation "Run NMBD")
+ (provision '(samba-nmbd))
+ (requirement '(networking))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/sbin/nmbd")
+ (string-append "--configfile=" #$config-file)
+ "--no-process-group")))
+ (stop #~(make-kill-destructor))))))
+(define (samba-smbd-shepherd-service config)
+ (let ((package (samba-configuration-package config))
+ (config-file (samba-configuration-config-file config)))
+ (list (shepherd-service
+ (documentation "Run SMBD")
+ (provision '(samba-smbd))
+ (requirement '(networking))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/sbin/smbd")
+ (string-append "--configfile=" #$config-file)
+ "--no-process-group")))
+ (stop #~(make-kill-destructor))))))
+(define (samba-winbindd-shepherd-service config)
+ (let ((package (samba-configuration-package config))
+ (config-file (samba-configuration-config-file config)))
+ (list (shepherd-service
+ (documentation "Run Winnbindd for Name Service Switch")
+ (provision '(samba-winbindd))
+ (requirement '(networking))
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/sbin/winbindd")
+ (string-append "--configfile=" #$config-file)
+ "--no-process-group")))
+ (stop #~(make-kill-destructor))))))
+(define (samba-shepherd-services config)
+ (append (if (samba-configuration-enable-samba? config)
+ (samba-samba-shepherd-service config)
+ (if (samba-configuration-enable-nmbd? config)
+ (samba-nmbd-shepherd-service config)
+ (if (samba-configuration-enable-smbd? config)
+ (samba-smbd-shepherd-service config)
+ (if (samba-configuration-enable-winbindd? config)
+ (samba-winbindd-shepherd-service config)
+(define samba-service-type
+ (description "Run @uref{https://www.samba.org/, Samba}, a network file and
+print service for all clients using the SMB/CIFS protocol. Samba is an
+important component to seamlessly integrate Linux/Unix Servers and Desktops
+into Active Directory environments. It can function both as a domain
+controller or as a regular domain member.")
+ (list (service-extension shepherd-root-service-type
+ samba-shepherd-services)
+ (service-extension activation-service-type
+ (service-extension profile-service-type
+ (compose list samba-configuration-package))))
+ (default-value (samba-configuration))))
diff --git a/gnu/tests/samba.scm b/gnu/tests/samba.scm
index 0000000000..27d7ea49c3
+++ b/gnu/tests/samba.scm
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2022 Simon Streit <simon@netpanic.org>
+;;; This file is part of GNU Guix.
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+(define-module (gnu tests samba)
+ #:use-module (gnu tests)
+ #:use-module (gnu system)
+ #:use-module (gnu system vm)
+ #:use-module (gnu services)
+ #:use-module (gnu services networking)
+ #:use-module (gnu services samba)
+ #:use-module (gnu packages samba)
+ #:use-module (guix gexp)
+ #:use-module (guix store)
+ #:export (%test-samba))
+ (let ((base-os (simple-operating-system
+ (simple-service 'create-target-directory activation-service-type
+ (mkdir-p "/srv/samba/guest")
+ (chown "/srv/samba/guest"
+ (passwd:uid (getpw "nobody"))
+ (passwd:gid (getpw "nobody")))))
+ (service dhcp-client-service-type)
+ (service samba-service-type
+ (config-file (plain-file "smb.conf" "
+ server string = Samba Server
+ server role = standalone server
+ log file = /var/log/samba/log.%m
+ path = /srv/samba/guest
+ (packages (cons samba (operating-system-packages base-os))))))
+(define* (run-samba-test)
+ "Return a test of an OS running Samba service."
+ (operating-system (marionette-operating-system
+ #:imported-modules '((gnu services herd))))
+ (port-forwardings '((8135 . 135)
+ (with-imported-modules '((gnu build marionette))
+ (use-modules (gnu build marionette)
+ (make-marionette '(#$vm)))
+ (test-runner-current (system-test-runner #$output))
+ (test-assert "samba-smbd running"
+ (use-modules (gnu services herd))
+ (start-service 'samba-smbd))
+ (test-assert "samba-nmbd running"
+ (use-modules (gnu services herd))
+ (start-service 'samba-nmbd))
+ (test-assert "samba-winbindd running"
+ (use-modules (gnu services herd))
+ (start-service 'samba-winbindd))
+ (test-assert "smbd service process id"
+ (number->string (wait-for-file "/var/run/samba/smbd.pid"
+ (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
+ (test-assert "nmbd service process id"
+ (number->string (wait-for-file "/var/run/samba/nmbd.pid"
+ (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
+ (test-assert "winbindd service process id"
+ (number->string (wait-for-file "/var/run/samba/winbindd.pid"
+ (marionette-eval `(file-exists? (string-append "/proc/" ,pid))
+ (test-assert "samba-smbd is listening for peers"
+ (wait-for-tcp-port 445 marionette))
+ (test-equal "smbclient connect"
+ '(system* #$(file-append samba "/bin/smbclient")
+ "--list=localhost" "--no-pass")
+ (test-equal "smbclient connect"
+ '(system* #$(file-append samba "/bin/smbclient")
+ "--list=localhost" "--no-pass")
+ (gexp->derivation "samba-test" test))
+ (description "Connect to a running Samba daemon.")
+ (value (run-samba-test))))
diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in
index f50dd00422..9088a627ff 100644
--- a/po/guix/POTFILES.in
+++ b/po/guix/POTFILES.in
@@ -6,6 +6,7 @@ gnu/services.scm
gnu/services/configuration.scm
gnu/services/shepherd.scm
gnu/home/services/ssh.scm
gnu/home/services/symlink-manager.scm