1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2018 Arun Isaac <arunisaac@systemreboot.net>
3 ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
5 ;;; This file is part of GNU Guix.
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;;; GNU General Public License for more details.
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20 (define-module (gnu services games)
21 #:use-module (gnu services)
22 #:use-module (gnu services shepherd)
23 #:use-module (gnu packages admin)
24 #:use-module (gnu packages games)
25 #:use-module (gnu system shadow)
26 #:use-module ((gnu system file-systems) #:select (file-system-mapping))
27 #:use-module (gnu build linux-container)
28 #:autoload (guix least-authority) (least-authority-wrapper)
29 #:use-module (guix gexp)
30 #:use-module (guix modules)
31 #:use-module (guix records)
32 #:use-module (ice-9 match)
33 #:export (wesnothd-configuration
34 wesnothd-configuration?
35 wesnothd-service-type))
38 ;;; The Battle for Wesnoth server
41 (define-record-type* <wesnothd-configuration>
42 wesnothd-configuration make-wesnothd-configuration wesnothd-configuration?
43 (package wesnothd-configuration-package
44 (default wesnoth-server))
45 (port wesnothd-configuration-port
48 (define %wesnothd-accounts
53 (comment "Wesnoth daemon user")
54 (home-directory "/var/empty")
55 (shell (file-append shadow "/sbin/nologin")))
60 (define wesnothd-shepherd-service
62 (($ <wesnothd-configuration> package port)
63 (let ((wesnothd (least-authority-wrapper
64 (file-append package "/bin/wesnothd")
66 #:mappings (list (file-system-mapping
67 (source "/var/run/wesnothd")
70 #:namespaces (delq 'net %namespaces))))
72 (documentation "The Battle for Wesnoth server")
73 (provision '(wesnoth-daemon))
74 (requirement '(networking))
75 (start #~(make-forkexec-constructor
76 (list #$wesnothd "-p" #$(number->string port))
77 #:user "wesnothd" #:group "wesnothd"))
78 (stop #~(make-kill-destructor)))))))
80 (define wesnothd-activation
81 (with-imported-modules '((guix build utils))
83 (use-modules (guix build utils))
85 (let* ((user (getpw "wesnothd"))
86 (directory "/var/run/wesnothd"))
87 ;; wesnothd creates a Unix-domain socket in DIRECTORY.
89 (chown directory (passwd:uid user) (passwd:gid user))))))
91 (define wesnothd-service-type
95 "Run The Battle for Wesnoth server @command{wesnothd}.")
97 (list (service-extension account-service-type
98 (const %wesnothd-accounts))
99 (service-extension activation-service-type
100 (const wesnothd-activation))
101 (service-extension shepherd-root-service-type
102 (compose list wesnothd-shepherd-service))))
103 (default-value (wesnothd-configuration))))