| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (gnu services samba)
|
| 20 | #:use-module (gnu packages)
|
| 21 | #:use-module (gnu packages base)
|
| 22 | #:use-module (gnu packages admin)
|
| 23 | #:use-module (gnu packages samba)
|
| 24 |
|
| 25 | #:use-module (gnu services)
|
| 26 | #:use-module (gnu services shepherd)
|
| 27 | #:use-module (gnu services base)
|
| 28 | #:use-module (gnu system shadow)
|
| 29 |
|
| 30 | #:use-module (guix gexp)
|
| 31 | #:use-module (guix packages)
|
| 32 | #:use-module (guix modules)
|
| 33 | #:use-module (guix records)
|
| 34 |
|
| 35 | #:use-module (ice-9 format)
|
| 36 | #:use-module (ice-9 match)
|
| 37 | #:use-module (ice-9 textual-ports)
|
| 38 | #:use-module (srfi srfi-1)
|
| 39 |
|
| 40 | #:export (samba-service-type
|
| 41 | samba-configuration
|
| 42 |
|
| 43 | wsdd-service-type
|
| 44 | wsdd-configuration))
|
| 45 |
|
| 46 | (define-record-type* <samba-configuration>
|
| 47 | samba-configuration
|
| 48 | make-samba-configuration
|
| 49 | samba-configuration?
|
| 50 | (package samba-configuration-package
|
| 51 | (default samba))
|
| 52 | (config-file samba-configuration-config-file
|
| 53 | (default #f))
|
| 54 | (enable-samba? samba-configuration-enable-samba?
|
| 55 | (default #f))
|
| 56 | (enable-smbd? samba-configuration-enable-smbd?
|
| 57 | (default #t))
|
| 58 | (enable-nmbd? samba-configuration-enable-nmbd?
|
| 59 | (default #t))
|
| 60 | (enable-winbindd? samba-configuration-enable-winbindd?
|
| 61 | (default #t)))
|
| 62 |
|
| 63 | (define (samba-activation config)
|
| 64 | (let ((package (samba-configuration-package config))
|
| 65 | (config-file (samba-configuration-config-file config)))
|
| 66 | (with-imported-modules '((guix build utils))
|
| 67 | (let ((lib-dir "/var/lib/samba")
|
| 68 | (log-dir "/var/log/samba")
|
| 69 | (run-dir "/var/run/samba")
|
| 70 | (lock-dir "/var/lock/samba")
|
| 71 | (cache-dir "/var/cache/samba")
|
| 72 | (etc-dir "/etc/samba")
|
| 73 | (smb.conf "/etc/samba/smb.conf"))
|
| 74 | #~(begin
|
| 75 | (use-modules (guix build utils))
|
| 76 | (mkdir-p #$etc-dir)
|
| 77 | (mkdir-p #$lib-dir)
|
| 78 | (mkdir-p/perms (string-append #$lib-dir "/private")
|
| 79 | (getpwnam "root") #o700)
|
| 80 | (mkdir-p #$log-dir)
|
| 81 | (mkdir-p #$run-dir)
|
| 82 | (mkdir-p #$lock-dir)
|
| 83 | (mkdir-p #$cache-dir)
|
| 84 | (copy-file #$config-file #$smb.conf)
|
| 85 | (invoke #$(file-append package "/bin/testparm")
|
| 86 | "--suppress-prompt" #$smb.conf))))))
|
| 87 |
|
| 88 | (define (samba-samba-shepherd-service config)
|
| 89 | (let ((package (samba-configuration-package config))
|
| 90 | (config-file (samba-configuration-config-file config)))
|
| 91 | (list (shepherd-service
|
| 92 | (documentation "Run Samba")
|
| 93 | (provision '(samba-samba))
|
| 94 | (requirement '(user-processes networking))
|
| 95 | (start #~(make-forkexec-constructor
|
| 96 | (list #$(file-append package "/sbin/samba")
|
| 97 | (string-append "--configfile=" #$config-file)
|
| 98 | "--foreground"
|
| 99 | "--no-process-group")))
|
| 100 | (stop #~(make-kill-destructor))))))
|
| 101 |
|
| 102 | (define (samba-nmbd-shepherd-service config)
|
| 103 | (let ((package (samba-configuration-package config))
|
| 104 | (config-file (samba-configuration-config-file config)))
|
| 105 | (list (shepherd-service
|
| 106 | (documentation "Run NMBD")
|
| 107 | (provision '(samba-nmbd))
|
| 108 | (requirement '(user-processes networking))
|
| 109 | (start #~(make-forkexec-constructor
|
| 110 | (list #$(file-append package "/sbin/nmbd")
|
| 111 | (string-append "--configfile=" #$config-file)
|
| 112 | "--foreground"
|
| 113 | "--no-process-group")))
|
| 114 | (stop #~(make-kill-destructor))))))
|
| 115 |
|
| 116 | (define (samba-smbd-shepherd-service config)
|
| 117 | (let ((package (samba-configuration-package config))
|
| 118 | (config-file (samba-configuration-config-file config)))
|
| 119 | (list (shepherd-service
|
| 120 | (documentation "Run SMBD")
|
| 121 | (provision '(samba-smbd))
|
| 122 | (requirement '(user-processes networking))
|
| 123 | (start #~(make-forkexec-constructor
|
| 124 | (list #$(file-append package "/sbin/smbd")
|
| 125 | (string-append "--configfile=" #$config-file)
|
| 126 | "--foreground"
|
| 127 | "--no-process-group")))
|
| 128 | (stop #~(make-kill-destructor))))))
|
| 129 |
|
| 130 | (define (samba-winbindd-shepherd-service config)
|
| 131 | (let ((package (samba-configuration-package config))
|
| 132 | (config-file (samba-configuration-config-file config)))
|
| 133 | (list (shepherd-service
|
| 134 | (documentation "Run Winnbindd for Name Service Switch")
|
| 135 | (provision '(samba-winbindd))
|
| 136 | (requirement '(user-processes networking))
|
| 137 | (start #~(make-forkexec-constructor
|
| 138 | (list #$(file-append package "/sbin/winbindd")
|
| 139 | (string-append "--configfile=" #$config-file)
|
| 140 | "--foreground"
|
| 141 | "--no-process-group")))
|
| 142 | (stop #~(make-kill-destructor))))))
|
| 143 |
|
| 144 | (define (samba-shepherd-services config)
|
| 145 | (append (if (samba-configuration-enable-samba? config)
|
| 146 | (samba-samba-shepherd-service config)
|
| 147 | '())
|
| 148 | (if (samba-configuration-enable-nmbd? config)
|
| 149 | (samba-nmbd-shepherd-service config)
|
| 150 | '())
|
| 151 | (if (samba-configuration-enable-smbd? config)
|
| 152 | (samba-smbd-shepherd-service config)
|
| 153 | '())
|
| 154 | (if (samba-configuration-enable-winbindd? config)
|
| 155 | (samba-winbindd-shepherd-service config)
|
| 156 | '())))
|
| 157 |
|
| 158 | (define samba-service-type
|
| 159 | (service-type
|
| 160 | (name 'samba)
|
| 161 | (description "Run @uref{https://www.samba.org/, Samba}, a network file and
|
| 162 | print service for all clients using the SMB/CIFS protocol. Samba is an
|
| 163 | important component to seamlessly integrate Linux/Unix Servers and Desktops
|
| 164 | into Active Directory environments. It can function both as a domain
|
| 165 | controller or as a regular domain member.")
|
| 166 | (extensions
|
| 167 | (list (service-extension shepherd-root-service-type
|
| 168 | samba-shepherd-services)
|
| 169 | (service-extension activation-service-type
|
| 170 | samba-activation)
|
| 171 | (service-extension profile-service-type
|
| 172 | (compose list samba-configuration-package))))
|
| 173 | (default-value (samba-configuration))))
|
| 174 |
|
| 175 |
|
| 176 | |
| 177 | |
| 178 | |
| 179 |
|
| 180 | (define-record-type* <wsdd-configuration>
|
| 181 | wsdd-configuration
|
| 182 | make-wsdd-configuration
|
| 183 | wsdd-configuration?
|
| 184 | (package wsdd-configuration-package
|
| 185 | (default wsdd))
|
| 186 | (ipv4only? wsdd-configuration-ipv4only?
|
| 187 | (default #f))
|
| 188 | (ipv6only? wsdd-configuration-ipv6only?
|
| 189 | (default #f))
|
| 190 | (chroot wsdd-configuration-chroot
|
| 191 | (default #f))
|
| 192 | (hop-limit wsdd-configuration-hop-limit
|
| 193 | (default 1))
|
| 194 | (interfaces wsdd-configuration-interfaces
|
| 195 | (default '()))
|
| 196 | (uuid-device wsdd-configuration-uuid-device
|
| 197 | (default #f))
|
| 198 | (domain wsdd-configuration-domain
|
| 199 | (default #f))
|
| 200 | (host-name wsdd-configuration-host-name
|
| 201 | (default #f))
|
| 202 | (preserve-case? wsdd-configuration-preserve-case?
|
| 203 | (default #f))
|
| 204 | (workgroup wsdd-configuration-workgroup
|
| 205 | (default "WORKGROUP")))
|
| 206 |
|
| 207 | (define wsdd-accounts
|
| 208 | (list
|
| 209 | (user-group (name "wsdd"))
|
| 210 | (user-account (name "wsdd")
|
| 211 | (group "wsdd")
|
| 212 | (comment "Web Service Discovery user")
|
| 213 | (home-directory "/var/empty")
|
| 214 | (shell (file-append shadow "/sbin/nologin")))))
|
| 215 |
|
| 216 | (define (wsdd-shepherd-service config)
|
| 217 | (match-record config <wsdd-configuration>
|
| 218 | (package ipv4only? ipv6only? chroot hop-limit interfaces uuid-device
|
| 219 | domain host-name preserve-case? workgroup)
|
| 220 | (list (shepherd-service
|
| 221 | (documentation "The Web Service Discovery daemon enables (Samba) hosts,
|
| 222 | like your local NAS device, to be found by Web Service Discovery Clients
|
| 223 | like Windows.")
|
| 224 | (provision '(wsdd))
|
| 225 | (requirement '(user-processes networking))
|
| 226 | (start #~(make-forkexec-constructor
|
| 227 | (list #$(file-append package "/bin/wsdd")
|
| 228 | #$@(if ipv4only?
|
| 229 | #~("--ipv4only")
|
| 230 | '())
|
| 231 | #$@(if ipv6only?
|
| 232 | #~("--ipv6only")
|
| 233 | '())
|
| 234 | #$@(if chroot
|
| 235 | #~("--chroot" #$chroot)
|
| 236 | '())
|
| 237 | #$@(if hop-limit
|
| 238 | #~("--hoplimit" #$(number->string hop-limit))
|
| 239 | '())
|
| 240 | #$@(map (lambda (interfaces)
|
| 241 | (string-append "--interface=" interfaces))
|
| 242 | interfaces)
|
| 243 | #$@(if uuid-device
|
| 244 | #~("--uuid" #$uuid-device)
|
| 245 | '())
|
| 246 | #$@(if domain
|
| 247 | #~("--domain" #$domain)
|
| 248 | '())
|
| 249 | #$@(if host-name
|
| 250 | #~("--hostname" #$host-name)
|
| 251 | '())
|
| 252 | #$@(if preserve-case?
|
| 253 | #~("--preserve-case")
|
| 254 | '())
|
| 255 | #$@(if workgroup
|
| 256 | #~("--workgroup" #$workgroup)
|
| 257 | '()))
|
| 258 | #:user "wsdd"
|
| 259 | #:group "wsdd"
|
| 260 | #:log-file "/var/log/wsdd.log"))
|
| 261 | (stop #~(make-kill-destructor))))))
|
| 262 |
|
| 263 | (define wsdd-service-type
|
| 264 | (service-type
|
| 265 | (name 'wsdd)
|
| 266 | (description "Web Service Discovery Daemon")
|
| 267 | (extensions
|
| 268 | (list (service-extension shepherd-root-service-type
|
| 269 | wsdd-shepherd-service)
|
| 270 | (service-extension account-service-type
|
| 271 | (const wsdd-accounts))
|
| 272 | (service-extension profile-service-type
|
| 273 | (compose list wsdd-configuration-package))))
|
| 274 | (default-value (wsdd-configuration))))
|