games.scm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. (define-module (gnu services games)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services shepherd)
  22. #:use-module (gnu packages admin)
  23. #:use-module (gnu packages games)
  24. #:use-module (gnu system shadow)
  25. #:use-module ((gnu system file-systems) #:select (file-system-mapping))
  26. #:use-module (gnu build linux-container)
  27. #:autoload (guix least-authority) (least-authority-wrapper)
  28. #:use-module (guix gexp)
  29. #:use-module (guix modules)
  30. #:use-module (guix records)
  31. #:use-module (ice-9 match)
  32. #:export (wesnothd-configuration
  33. wesnothd-configuration?
  34. wesnothd-service-type))
  35. ;;;
  36. ;;; The Battle for Wesnoth server
  37. ;;;
  38. (define-record-type* <wesnothd-configuration>
  39. wesnothd-configuration make-wesnothd-configuration wesnothd-configuration?
  40. (package wesnothd-configuration-package
  41. (default wesnoth-server))
  42. (port wesnothd-configuration-port
  43. (default 15000)))
  44. (define %wesnothd-accounts
  45. (list (user-account
  46. (name "wesnothd")
  47. (group "wesnothd")
  48. (system? #t)
  49. (comment "Wesnoth daemon user")
  50. (home-directory "/var/empty")
  51. (shell (file-append shadow "/sbin/nologin")))
  52. (user-group
  53. (name "wesnothd")
  54. (system? #t))))
  55. (define wesnothd-shepherd-service
  56. (match-lambda
  57. (($ <wesnothd-configuration> package port)
  58. (let ((wesnothd (least-authority-wrapper
  59. (file-append package "/bin/wesnothd")
  60. #:name "wesnothd"
  61. #:mappings (list (file-system-mapping
  62. (source "/var/run/wesnothd")
  63. (target source)
  64. (writable? #t)))
  65. #:namespaces (delq 'net %namespaces))))
  66. (shepherd-service
  67. (documentation "The Battle for Wesnoth server")
  68. (provision '(wesnoth-daemon))
  69. (requirement '(networking))
  70. (start #~(make-forkexec-constructor
  71. (list #$wesnothd "-p" #$(number->string port))
  72. #:user "wesnothd" #:group "wesnothd"))
  73. (stop #~(make-kill-destructor)))))))
  74. (define wesnothd-activation
  75. (with-imported-modules '((guix build utils))
  76. #~(begin
  77. (use-modules (guix build utils))
  78. (let* ((user (getpw "wesnothd"))
  79. (directory "/var/run/wesnothd"))
  80. ;; wesnothd creates a Unix-domain socket in DIRECTORY.
  81. (mkdir-p directory)
  82. (chown directory (passwd:uid user) (passwd:gid user))))))
  83. (define wesnothd-service-type
  84. (service-type
  85. (name 'wesnothd)
  86. (description
  87. "Run The Battle for Wesnoth server @command{wesnothd}.")
  88. (extensions
  89. (list (service-extension account-service-type
  90. (const %wesnothd-accounts))
  91. (service-extension activation-service-type
  92. (const wesnothd-activation))
  93. (service-extension shepherd-root-service-type
  94. (compose list wesnothd-shepherd-service))))
  95. (default-value (wesnothd-configuration))))