services: guix-build-coordinator: Fix passing parallel-hooks.
[jackhill/guix/guix.git] / gnu / services / games.scm
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>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
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.
11 ;;;
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.
16 ;;;
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/>.
19
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))
36
37 ;;;
38 ;;; The Battle for Wesnoth server
39 ;;;
40
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
46 (default 15000)))
47
48 (define %wesnothd-accounts
49 (list (user-account
50 (name "wesnothd")
51 (group "wesnothd")
52 (system? #t)
53 (comment "Wesnoth daemon user")
54 (home-directory "/var/empty")
55 (shell (file-append shadow "/sbin/nologin")))
56 (user-group
57 (name "wesnothd")
58 (system? #t))))
59
60 (define wesnothd-shepherd-service
61 (match-lambda
62 (($ <wesnothd-configuration> package port)
63 (let ((wesnothd (least-authority-wrapper
64 (file-append package "/bin/wesnothd")
65 #:name "wesnothd"
66 #:mappings (list (file-system-mapping
67 (source "/var/run/wesnothd")
68 (target source)
69 (writable? #t)))
70 #:namespaces (delq 'net %namespaces))))
71 (shepherd-service
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)))))))
79
80 (define wesnothd-activation
81 (with-imported-modules '((guix build utils))
82 #~(begin
83 (use-modules (guix build utils))
84
85 (let* ((user (getpw "wesnothd"))
86 (directory "/var/run/wesnothd"))
87 ;; wesnothd creates a Unix-domain socket in DIRECTORY.
88 (mkdir-p directory)
89 (chown directory (passwd:uid user) (passwd:gid user))))))
90
91 (define wesnothd-service-type
92 (service-type
93 (name 'wesnothd)
94 (description
95 "Run The Battle for Wesnoth server @command{wesnothd}.")
96 (extensions
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))))