projects/guix·blob python-team · refs

112 lines · 4.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2023 Janneke Nieuwenhuizen <[email protected]>
3;;; Copyright © 2024, 2025 Ian Eure <[email protected]>
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 home services media)
21 #:use-module (srfi srfi-26)
22 #:use-module (gnu home services)
23 #:use-module (gnu home services desktop)
24 #:use-module (gnu home services shepherd)
25 #:use-module (gnu packages kodi)
26 #:use-module (gnu packages video)
27 #:use-module (gnu services configuration)
28 #:use-module (gnu services shepherd)
29 #:use-module (guix packages)
30 #:use-module (guix records)
31 #:use-module (guix gexp)
32 #:export (home-kodi-configuration
33 home-kodi-service-type
34
35 home-jellyfin-mpv-shim-configuration
36 home-jellyfin-mpv-shim-service-type))
37
38
39;;;
40;;; Kodi.
41;;;
42
43(define-record-type* <home-kodi-configuration>
44 home-kodi-configuration make-home-kodi-configuration
45 home-kodi-configuration?
46 (kodi home-kodi-kodi ;file-like
47 (default kodi))
48 (extra-options home-kodi-extra-options ;list of string
49 (default '())))
50
51(define (home-kodi-services config)
52 "Return a <shepherd-service> for kodi with CONFIG."
53 (match-record config <home-kodi-configuration>
54 (kodi extra-options)
55 (let* ((kodi (file-append kodi "/bin/kodi"))
56 (command #~'(#$kodi "-fs" #$@extra-options))
57 (log-file #~(string-append %user-log-dir "/kodi.log")))
58 (list (shepherd-service
59 (documentation "Run the kodi media center.")
60 (provision '(kodi))
61 (modules '((shepherd support))) ;for '%user-log-dir'
62 (start #~(make-forkexec-constructor #$command
63 #:log-file #$log-file))
64 (stop #~(make-kill-destructor)))))))
65
66(define home-kodi-service-type
67 (service-type
68 (name 'home-kodi)
69 (default-value (home-kodi-configuration))
70 (extensions
71 (list (service-extension home-shepherd-service-type
72 home-kodi-services)))
73 (description
74 "Install and configure the Kodi media center so that it runs as a Shepherd
75service.")))
76
77(define-configuration home-jellyfin-mpv-shim-configuration
78 (package
79 (file-like jellyfin-mpv-shim)
80 "The Jellyfin MPV Shim package to use"))
81
82(define (jellyfin-mpv-shim-shepherd-service config)
83 (list (shepherd-service
84 (documentation "Jellyfin MPV Shim.")
85 (provision '(jellyfin-mpv-shim jellyfin-client))
86
87 ;; Depend on 'x11-display', which sets 'DISPLAY' if an X11 server is
88 ;; available, and fails to start otherwise.
89 (requirement '(x11-display))
90
91 (modules '((srfi srfi-1)
92 (srfi srfi-26)
93 (srfi srfi-98)))
94 (start
95 #~(make-forkexec-constructor
96 (list
97 #$(file-append
98 (home-jellyfin-mpv-shim-configuration-package config)
99 "/bin/jellyfin-mpv-shim"))))
100 (stop #~(make-kill-destructor)))))
101
102(define-public home-jellyfin-mpv-shim-service-type
103 (service-type
104 (name 'home-jellyfin-mpv-shim)
105 (extensions (list (service-extension home-shepherd-service-type
106 jellyfin-mpv-shim-shepherd-service)
107 ;; Ensure 'home-x11-service-type' is instantiated so we
108 ;; can depend on the Shepherd 'x11-display' service.
109 (service-extension home-x11-service-type
110 (const #t))))
111 (default-value (home-jellyfin-mpv-shim-configuration))
112 (description "Run Jellyfin MPV Shim.")))