aboutsummaryrefslogtreecommitdiff
;;; 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 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

            wsdd-service-type
            wsdd-configuration))

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


;;;
;;; 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))
  (hop-limit      wsdd-configuration-hop-limit
                  (default 1))
  (interfaces     wsdd-configuration-interfaces
                  (default '()))
  (uuid-device    wsdd-configuration-uuid-device
                  (default #f))
  (domain         wsdd-configuration-domain
                  (default #f))
  (host-name      wsdd-configuration-host-name
                  (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 config)
  (match-record config <wsdd-configuration>
    (package ipv4only? ipv6only? chroot hop-limit interfaces uuid-device
     domain host-name preserve-case? workgroup)
     (list (shepherd-service
            (documentation "The Web Service Discovery daemon enables (Samba) hosts,
like your local NAS device, to be found by Web Service Discovery Clients
like Windows.")
            (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 hop-limit
                                   #~("--hoplimit" #$(number->string hop-limit))
                                   '())
                            #$@(map (lambda (interfaces)
                                      (string-append "--interface=" interfaces))
                                    interfaces)
                            #$@(if uuid-device
                                   #~("--uuid" #$uuid-device)
                                   '())
                            #$@(if domain
                                   #~("--domain" #$domain)
                                   '())
                            #$@(if host-name
                                   #~("--hostname" #$host-name)
                                   '())
                            #$@(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))))
lass='msg-avail'>...* gnu/packages/syncthing.scm (go-github-com-audriusbutkevicius-recli): Move from here ... * gnu/packages/golang-xyz.scm: ... to here. Change-Id: I1494e60367873ba5ddbfe0725cd8a0ed02d8cb9e Sharlatan Hellseher 2024-06-27gnu: go-github-com-audriusbutkevicius-pfilter: Move to golang-web....* gnu/packages/syncthing.scm (go-github-com-audriusbutkevicius-pfilter): Move from here ... * gnu/packages/golang-web.scm: ... to here. Change-Id: Ie148e31dde805b79956553988431153159598acc Sharlatan Hellseher 2024-06-27gnu: Remove go-github-com-bkaradzic-go-lz4....* gnu/packages/syncthing.scm (go-github-com-bkaradzic-go-lz4): Delete variable. Change-Id: Idb01a1909d4fe3d4360350e891fd97349db05a6f Sharlatan Hellseher 2024-06-27gnu: go-github-com-sasha-s-go-deadlock: Move to golang-check....* gnu/packages/syncthing.scm (go-github-com-sasha-s-go-deadlock): Move from here ... * gnu/packages/golang-check.scm: ... to here. Change-Id: Id3d101897b4ac056cfe48a52289dd3e4f51402d8 Sharlatan Hellseher 2024-06-27gnu: go-github-com-petermattis-goid: Move to golang-check....* gnu/packages/syncthing.scm (go-github-com-petermattis-goid): Move from here ... * gnu/packages/golang-check.scm: ... to here. Change-Id: I68182d8131afdcb346076d4f1e69ccf680b48cdb Sharlatan Hellseher 2024-05-07gnu: go-github-com-matttproud-golang-protobuf-extensions-pbutil: Update to 2.......* gnu/packages/syncthing.scm (go-github-com-matttproud-golang-protobuf-extensions-pbutil): Update to 2.0.0. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ia9f1acacd337b95526ee0b9b7b31f1de598f30d3 Jesse Eisses 2024-05-05gnu: Revmoe go-github-com-syndtr-goleveldb....This package is a duplicate to go-github-com-syndtr-goleveldb-leveldb. * gnu/packages/ipfs.scm: Revmoe (gnu packages syncthing) module. (kubo) [inputs]: Replace go-github-com-syndtr-goleveldb with go-github-com-syndtr-goleveldb-leveldb. * gnu/packages/syncthing.scm (go-github-com-syndtr-goleveldb): Remove variable. Change-Id: I8641a18a3d97f570f3bbbd849f7dabdea4e41b01 Sharlatan Hellseher 2024-04-24gnu: go-github-com-jackpal-go-nat-pmp: Move to golang-web....gnu/packages/syncthing.scm (go-github-com-jackpal-go-nat-pmp): Move from here ... gnu/packages/golang-web.scm: ... to here. Change-Id: Ib58a2f2d1f6bb279cd74d8460a7e02a5e4849c52 Sharlatan Hellseher 2024-04-14gnu: go-github-com-golang-groupcache: Move to golang-web....* gnu/packages/syncthing.scm (go-github-com-golang-groupcache): Move from here ... * gnu/packages/golang-web.scm: ... to here. Change-Id: I3e5393d13630529a0cf309e08b9e7dc9d5cba18a Sharlatan Hellseher 2024-04-14gnu: go-github-com-golang-groupcache-lru: Import all go modules....Rename go-github-com-golang-groupcache-lru to go-github-com-golang-groupcache to reflect go.mod import path as seen in <https://pkg.go.dev/github.com/golang/groupcache>. It will provide other available submodules together with main module groupcache: lru, singleflight, groupcachepb and consistenthash. * gnu/packages/syncthing.scm (go-github-com-golang-groupcache): [arguments]: Remove <#:unpack-path>, update <#:import-path> to make other modules available. [propagated-inputs]: Add go-github-com-golang-protobuf-proto. * gnu/packages/ipfs.scm (kubo): [inputs]: Remove go-github-com-golang-groupcache-lru, add go-github-com-golang-groupcache. Change-Id: I455eecd2ebeff5f456f83621aa85b4de7d60304e Sharlatan Hellseher 2024-04-12gnu: go-github-com-gobwas-glob: Move to golang-xyz....* gnu/packages/syncthing.scm (go-github-com-gobwas-glob): Move from here ... * gnu/packages/golang-xyz.scm: ... to here. * gnu/packages/textutils.scm: Remove (gnu packages syncthing) module. Change-Id: I131830e6edcdb666aeb3cd9bbdf6982df938ccd4 Sharlatan Hellseher