unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Simon Streit <simon@netpanic.org>
To: 54561@debbugs.gnu.org
Subject: [bug#54561] [PATCH 1/4] services: Add samba service.
Date: Fri, 25 Mar 2022 10:00:26 +0100	[thread overview]
Message-ID: <yguils28l05.fsf@netpanic.org> (raw)
In-Reply-To: <yguwngi8ljt.fsf@netpanic.org>


* gnu/services/samba.scm (<samba-configuration>): New record.
(samba-service-type): New variable.
(samba-shepherd-services): New Procedure.
---
 gnu/services/samba.scm | 173 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 173 insertions(+)
 create mode 100644 gnu/services/samba.scm

diff --git a/gnu/services/samba.scm b/gnu/services/samba.scm
new file mode 100644
index 0000000000..ffbf20fdbc
--- /dev/null
+++ b/gnu/services/samba.scm
@@ -0,0 +1,173 @@
+;;; 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
+            samba-configuration
+            samba-smb-conf
+
+            wsdd-service-type
+            wsdd-configuration))
+
+(define %smb-conf
+  (plain-file "smb.conf" "[global]
+    workgroup = WORKGROUP
+    server string = Samba Server
+    server role = standalone server
+    log file = /var/log/samba/log.%m
+    logging = file
+"))
+
+(define-record-type* <samba-configuration>
+  samba-configuration
+  make-samba-configuration
+  samba-configuration?
+  (package              samba-configuration-package
+                        (default samba))
+  (config-file          samba-configuration-config-file
+                        (default #f))
+  (enable-samba?        samba-configuration-enable-samba?
+                        (default #f))
+  (enable-smbd?         samba-configuration-enable-smbd?
+                        (default #t))
+  (enable-nmbd?         samba-configuration-enable-nmbd?
+                        (default #t))
+  (enable-winbindd?     samba-configuration-enable-winbindd?
+                        (default #t)))
+
+(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-directory "/var/lib/samba")
+            (log-directory "/var/log/samba")
+            (run-directory "/var/run/samba")
+            (smb.conf "/etc/samba/smb.conf"))
+        #~(begin
+            (use-modules (guix build utils))
+
+            (mkdir-p #$log-directory)
+            (mkdir-p #$run-directory)
+            (mkdir-p (string-append #$lib-directory "/private"))
+            (mkdir-p "/etc/samba")
+            (copy-file #$config-file #$smb.conf)
+            (system* (string-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)
+                              "--foreground"
+                              "--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)
+                              "--foreground"
+                              "--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)
+                              "--foreground"
+                              "--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)
+                              "--foreground"
+                              "--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
+  (service-type
+   (name 'samba)
+   (description "Samba")
+   (extensions
+    (list (service-extension shepherd-root-service-type
+                             samba-shepherd-services)
+          (service-extension activation-service-type
+                             samba-activation)))
+   (default-value (samba-configuration))))
--
2.34.0




  parent reply	other threads:[~2022-03-25 11:51 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  8:48 [bug#54561] [PATCH 0/4] Add service declarations for Samba Simon Streit
2022-03-24 21:10 ` [bug#54561] [PATCH 3/4] doc: Add documentation for WSDD service Simon Streit
2022-03-24 21:14 ` [bug#54561] [PATCH 4/4] services: Add wsdd service Simon Streit
2022-03-25  9:16   ` Simon Streit
2022-03-25 12:02     ` Simon Streit
2022-03-25  9:00 ` Simon Streit [this message]
2022-03-27  1:07   ` [bug#54561] [PATCH 1/4] services: Add samba service fesoj000
2022-03-27 14:13     ` Maxime Devos
2022-03-27 18:32       ` Simon Streit
2022-04-08 18:21       ` [bug#54561] v2 [PATCH 0/5] Add service declarations for Samba Simon Streit
2022-04-08 18:21         ` [bug#54561] v2 [PATCH 1/5] services: Add samba service Simon Streit
2022-04-08 21:26           ` [bug#54561] [PATCH 0/4] Add service declarations for Samba Ludovic Courtès
2022-04-08 18:21         ` [bug#54561] v2 [PATCH 2/5] doc: Add "Samba" chapter Simon Streit
2022-04-08 21:35           ` [bug#54561] [PATCH 0/4] Add service declarations for Samba Ludovic Courtès
2022-04-08 18:21         ` [bug#54561] v2 [PATCH 3/5] doc: Add documentation for WSDD service Simon Streit
2022-04-08 21:41           ` [bug#54561] [PATCH 0/4] Add service declarations for Samba Ludovic Courtès
2022-04-09  8:29           ` [bug#54561] v2 [PATCH 3/5] doc: Add documentation for WSDD service Maxime Devos
2022-04-08 18:21         ` [bug#54561] v2 [PATCH 4/5] services: Add wsdd service Simon Streit
2022-04-08 21:43           ` [bug#54561] [PATCH 0/4] Add service declarations for Samba Ludovic Courtès
2022-04-08 18:21         ` [bug#54561] v2 [PATCH 5/5] gnu: Add wsdd Simon Streit
2022-04-08 21:23         ` [bug#54561] [PATCH 0/4] Add service declarations for Samba Ludovic Courtès
2022-03-27 18:48     ` [bug#54561] [PATCH 1/4] services: Add samba service Simon Streit
2022-03-27 18:58       ` fesoj000
2022-03-25  9:01 ` [bug#54561] [PATCH 2/4] doc: Add "Samba" chapter Simon Streit
2022-03-27  1:07   ` fesoj000
2022-03-27 14:15   ` Maxime Devos
2022-03-27 18:51     ` Simon Streit
2022-03-25 15:14 ` [bug#54561] [PATCH] gnu: samba: Modify input list Simon Streit
2022-03-27 19:22 ` [bug#54561] [PATCH] gnu: libdaemon: fix build for riscv64 fesoj000
2022-03-27 19:23   ` fesoj000
2022-08-08 14:56 ` [bug#54561] [PATCH v3 0/4] Add samba and wsdd to services list simon
2022-08-08 14:56   ` [bug#54561] [PATCH v3 1/4] gnu: samba: Add avahi to inputs simon
2022-08-08 14:56   ` [bug#54561] [PATCH v3 2/4] services: Add samba service simon
2022-08-08 14:56   ` [bug#54561] [PATCH v3 3/4] gnu: Add wsdd simon
2022-08-08 14:56   ` [bug#54561] [PATCH v3 4/4] services: Add wsdd service simon
2022-09-24  7:48   ` bug#54561: [PATCH v3 0/4] Add samba and wsdd to services list Lars-Dominik Braun
2022-09-25  8:22     ` [bug#54561] " Lars-Dominik Braun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yguils28l05.fsf@netpanic.org \
    --to=simon@netpanic.org \
    --cc=54561@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).