unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob c1f9033d6352c5727b607a520ef16ceaaf8ef00e 11522 bytes (raw)
name: gnu/services/samba.scm 	 # note: path name is non-authoritative(*)

  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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
 
;;; 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-dir "/var/lib/samba")
            (log-dir "/var/log/samba")
            (run-dir "/var/run/samba")
            (lock-dir "/var/lock/samba")
            (cache-dir "/var/cache/samba")
            (etc-dir "/etc/samba")
            (smb.conf "/etc/samba/smb.conf"))
        #~(begin
            (use-modules (guix build utils))
            (mkdir-p #$etc-dir)
            (mkdir-p #$lib-dir)
            (mkdir-p/perms (string-append #$lib-dir "/private")
                           (getpwnam "root") #o700)
            (mkdir-p #$log-dir)
            (mkdir-p #$run-dir)
            (mkdir-p #$lock-dir)
            (mkdir-p #$cache-dir)
            (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)
                              "--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 "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.")
   (extensions
    (list (service-extension shepherd-root-service-type
                             samba-shepherd-services)
          (service-extension activation-service-type
                             samba-activation)
          (service-extension profile-service-type
                             (compose list samba-configuration-package))))
   (default-value (samba-configuration))))

\f
;;;
;;; WSDD
;;;

(define-record-type* <wsdd-configuration>
  wsdd-configuration
  make-wsdd-configuration
  wsdd-configuration?
  (package        wsdd-configuration-package
                  (default wsdd))
  (ipv4only?      wsdd-configuration-ipv4only?
                  (default #f))
  (ipv6only?      wsdd-configuration-ipv6only?
                  (default #f))
  (chroot         wsdd-configuration-chroot
                  (default #f))
  (hoplimit       wsdd-configuration-hoplimit
                  (default 1))
  (interfaces     wsdd-configuration-interfaces
                  (default '()))
  (uuid-device    wsdd-configuration-uuid-device
                  (default #f))
  (domain         wsdd-configuration-domain
                  (default #f))
  (hostname       wsdd-configuration-hostname
                  (default #f))
  (preserve-case? wsdd-configuration-preserve-case?
                  (default #f))
  (workgroup      wsdd-configuration-workgroup
                  (default "WORKGROUP")))

(define wsdd-accounts
  (list
   (user-group (name "wsdd"))
   (user-account (name "wsdd")
                 (group "wsdd")
                 (comment "Web Service Discovery user")
                 (home-directory "/var/empty")
                 (shell (file-append shadow "/sbin/nologin")))))

(define wsdd-shepherd-service
  (match-lambda
    (($ <wsdd-configuration> package ipv4only? ipv6only? chroot hoplimit
                             interfaces uuid-device domain hostname
                             preserve-case? workgroup)
     (list (shepherd-service
            (documentation "Run a Web Service Discovery service")
            (provision '(wsdd))
            (requirement '(networking))
            (start #~(make-forkexec-constructor
                      (list #$(file-append package "/bin/wsdd")
                            #$@(if ipv4only?
                                   #~("--ipv4only")
                                   '())
                            #$@(if ipv6only?
                                   #~("--ipv6only")
                                   '())
                            #$@(if chroot
                                   #~("--chroot" #$chroot)
                                   '())
                            #$@(if hoplimit
                                   #~("--hoplimit" #$(number->string hoplimit))
                                   '())
                            #$@(map (lambda (interfaces)
                                      (string-append "--interface=" interfaces))
                                    interfaces)
                            #$@(if uuid-device
                                   #~("--uuid" #$uuid-device)
                                   '())
                            #$@(if domain
                                   #~("--domain" #$domain)
                                   '())
                            #$@(if hostname
                                   #~("--hostname" #$hostname)
                                   '())
                            #$@(if preserve-case?
                                   #~("--preserve-case")
                                   '())
                            #$@(if workgroup
                                   #~("--workgroup" #$workgroup)
                                   '()))
                      #:user "wsdd"
                      #:group "wsdd"
                      #:log-file "/var/log/wsdd.log"))
            (stop #~(make-kill-destructor)))))))

(define wsdd-service-type
  (service-type
   (name 'wsdd)
   (description "Web Service Discovery Daemon")
   (extensions
    (list (service-extension shepherd-root-service-type
                             wsdd-shepherd-service)
          (service-extension account-service-type
                             (const wsdd-accounts))
          (service-extension profile-service-type
                             (compose list wsdd-configuration-package))))
   (default-value (wsdd-configuration))))

debug log:

solving c1f9033d63 ...
found c1f9033d63 in https://yhetil.org/guix-patches/20220808145643.3445-5-simon@netpanic.org/ ||
	https://yhetil.org/guix-patches/20220728222215.21126-5-simon@netpanic.org/
found 2c9e52a0b0 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 2c9e52a0b05a5aa4653e2ce522b91cbc6ce00824	gnu/services/samba.scm

applying [1/1] https://yhetil.org/guix-patches/20220808145643.3445-5-simon@netpanic.org/
diff --git a/gnu/services/samba.scm b/gnu/services/samba.scm
index 2c9e52a0b0..c1f9033d63 100644

Checking patch gnu/services/samba.scm...
Applied patch gnu/services/samba.scm cleanly.

skipping https://yhetil.org/guix-patches/20220728222215.21126-5-simon@netpanic.org/ for c1f9033d63
index at:
100644 c1f9033d6352c5727b607a520ef16ceaaf8ef00e	gnu/services/samba.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).