Package: guix-patches;
Reported by: Sughosha <sughosha <at> disroot.org>
Date: Sat, 15 Mar 2025 02:03:01 UTC
Severity: normal
Tags: moreinfo, patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
View this message in rfc822 format
From: Sughosha <sughosha <at> disroot.org> To: 77023 <at> debbugs.gnu.org Cc: Ludovic Courtès <ludo <at> gnu.org>, Sughosha <sughosha <at> disroot.org>, Andrew Tropin <andrew <at> trop.in>, Janneke Nieuwenhuizen <janneke <at> gnu.org>, Ludovic Courtès <ludo <at> gnu.org>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, Tanguy Le Carrour <tanguy <at> bioneland.org> Subject: [bug#77023] [PATCH 3/3] home: services: Add readymedia. Date: Sat, 15 Mar 2025 07:33:45 +0530
* gnu/home/services/upnp.scm: New file. * gnu/local.mk: Register it. * gnu/services/upnp.scm: Export readymedia-activation and readymedia-shepherd-service. (<readymedia-configuration>)[home-service?]: New field. [cache-directory]: Adjust value depending on 'for-home?'. [log-directory]: Ditto. (readymedia-shepherd-service): Adjust 'requirement' and 'start' according to 'home-service?'. (readymedia-activation): Adjust creating directories with permissions according to 'home-service?'. * doc/guix.texi (Miscellaneous Home Services): Document Readymedia Service. (Miscellaneous Services): Add cross-reference. Change-Id: I57ec25726e716ca6600ef23b636523c48fd5041f --- doc/guix.texi | 45 +++++++++++++++++++++++++++++++ gnu/home/services/upnp.scm | 55 ++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + gnu/services/upnp.scm | 45 ++++++++++++++++++++++--------- 4 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 gnu/home/services/upnp.scm diff --git a/doc/guix.texi b/doc/guix.texi index 02da0a2ee98..0cb4573e4db 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43965,6 +43965,12 @@ Miscellaneous Services field is mandatory. All other fields (such as network ports and the server name) come with a predefined default and can be omitted. +@quotation Note +This service is also available for Guix Home, where it runs directly +with your user privileges (@pxref{Miscellaneous Home Services, +@code{home-readymedia-service-type}}). +@end quotation + @c %start of fragment @deftp {Data Type} readymedia-configuration @@ -50159,6 +50165,8 @@ Networking Home Services This section lists services somewhat networking-related that you may use with Guix Home. +@subheading Syncthing Service + @cindex Syncthing, file synchronization service @cindex backup service, Syncthing The @code{(gnu home services syncthing)} module provides a service to @@ -50261,6 +50269,43 @@ Miscellaneous Home Services (dicod-configuration @dots{}))) @end lisp +@subheading ReadyMedia Service + +@cindex ReadyMedia, DLNA/UPnP Service +The @code{(gnu home services upnp)} module provides a service to set up +the @uref{https://minidlna.sourceforge.net/, ReadyMedia} @acronym{DLNA, +Digital Living Network Alliance} @acronym{UPnP, Universal Plug and Play} +media server. + +@defvar home-readymedia-service-type +This is the service type for the @command{minidlnad} daemon; it is the +Home counterpart of the @code{readymedia-service-type} system service +(@pxref{Miscellaneous Services, @code{readymedia-service-type}}). The value +for this service type is a @code{readymedia-configuration}. +@end defvar + +The service can be used with a @code{readymedia-configuration} wrapped in +@code{for-home} like this: + +@lisp +(service home-readymedia-service-type + (for-home + (readymedia-configuration + (media-directories + (list (readymedia-directory + (path "/path/to/media/audio") + (types '(A))) + (readymedia-directory + (path "/path/to/media/video") + (types '(V))) + (readymedia-directory + (path "/path/to/media/misc"))))))) +@end lisp + +For details about @code{readymedia-configuration}, check out the +documentation of the system service (@pxref{Miscellaneous Services, +@code{readymedia-service-type}}). + @node Invoking guix home @section Invoking @command{guix home} diff --git a/gnu/home/services/upnp.scm b/gnu/home/services/upnp.scm new file mode 100644 index 00000000000..869c8e0c4a7 --- /dev/null +++ b/gnu/home/services/upnp.scm @@ -0,0 +1,55 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright �� 2025 Sughosha <sughosha <at> disroot.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 home services upnp) + #:use-module ((gnu build linux-container) #:select (%namespaces)) + #:use-module (gnu services) + #:use-module (gnu home services) + ;; For the 'home-shepherd-service-type' mapping. + #:use-module (gnu home services shepherd) + #:use-module (gnu services upnp) + #:use-module (guix records) + #:export (home-readymedia-service-type) + #:re-export (readymedia-configuration + readymedia-configuration? + readymedia-configuration-readymedia + readymedia-configuration-port + readymedia-configuration-cache-directory + readymedia-configuration-extra-config + readymedia-configuration-friendly-name + readymedia-configuration-log-directory + readymedia-configuration-media-directories + readymedia-media-directory + readymedia-media-directory? + readymedia-media-directory-path + readymedia-media-directory-types)) + +(define home-readymedia-service-type + (service-type + (inherit (system->home-service-type readymedia-service-type)) + ;; system->home-service-type does not convert special-files-service-type to + ;; home-files-service-type, so redefine extensios + (extensions + (list (service-extension home-shepherd-service-type + (compose list readymedia-shepherd-service)) + (service-extension home-activation-service-type + readymedia-activation))) + (default-value + (for-home + (readymedia-configuration + (media-directories '())))))) diff --git a/gnu/local.mk b/gnu/local.mk index 149ef8dff9a..6f7929bee8b 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -122,6 +122,7 @@ GNU_SYSTEM_MODULES = \ %D%/home/services/sway.scm \ %D%/home/services/syncthing.scm \ %D%/home/services/mcron.scm \ + %D%/home/services/upnp.scm \ %D%/home/services/utils.scm \ %D%/home/services/xdg.scm \ %D%/image.scm \ diff --git a/gnu/services/upnp.scm b/gnu/services/upnp.scm index c125c07af24..e4bafced53d 100644 --- a/gnu/services/upnp.scm +++ b/gnu/services/upnp.scm @@ -50,7 +50,9 @@ (define-module (gnu services upnp) readymedia-media-directory-path readymedia-media-directory-types readymedia-media-directory? - readymedia-service-type)) + readymedia-service-type + readymedia-activation + readymedia-shepherd-service)) ;;; Commentary: ;;; @@ -72,14 +74,27 @@ (define-record-type* <readymedia-configuration> (port readymedia-configuration-port (default #f)) (cache-directory readymedia-configuration-cache-directory - (default %readymedia-default-cache-directory)) + (default (if for-home? + (string-append (or (getenv "XDG_CACHE_HOME") + (string-append + (getenv "HOME") "/.cache")) + "/readymedia") + %readymedia-default-cache-directory))) (log-directory readymedia-configuration-log-directory - (default %readymedia-default-log-directory)) + (default (if for-home? + (string-append (or (getenv "XDG_STATE_HOME") + (string-append + (getenv "HOME") + "/.local/state")) + "/readymedia") + %readymedia-default-log-directory))) (friendly-name readymedia-configuration-friendly-name (default #f)) (media-directories readymedia-configuration-media-directories) (extra-config readymedia-configuration-extra-config - (default '()))) + (default '())) + (home-service? syncthing-configuration-home-service? + (default for-home?) (innate))) ;; READYMEDIA-MEDIA-DIR is a record that indicates the path of a media folder ;; and the types of media included within it. Allowed individual types are the @@ -96,9 +111,13 @@ (define-record-type* <readymedia-media-directory> (define (readymedia-configuration->config-file config) "Return the ReadyMedia/MiniDLNA configuration file corresponding to CONFIG." (match-record config <readymedia-configuration> - (port friendly-name cache-directory log-directory media-directories extra-config) + (port friendly-name cache-directory log-directory media-directories + extra-config home-service?) (apply mixed-text-file "minidlna.conf" + (if home-service? + (string-append "user=" (number->string (getuid)) "\n") + "") "db_dir=" cache-directory "\n" "log_dir=" log-directory "\n" (if friendly-name @@ -125,12 +144,12 @@ (define (readymedia-configuration->config-file config) (define (readymedia-shepherd-service config) "Return a least-authority ReadyMedia/MiniDLNA Shepherd service." (match-record config <readymedia-configuration> - (cache-directory log-directory media-directories) + (cache-directory log-directory media-directories home-service?) (let ((minidlna-conf (readymedia-configuration->config-file config))) (shepherd-service (documentation "Run the ReadyMedia/MiniDLNA daemon.") (provision '(readymedia)) - (requirement '(networking user-processes)) + (requirement (if home-service? '() '(networking user-processes))) (start #~(make-forkexec-constructor (list #$(least-authority-wrapper @@ -159,8 +178,8 @@ (define (readymedia-shepherd-service config) #$minidlna-conf "-S") #:log-file #$(string-append log-directory "/" %readymedia-log-file) - #:user #$%readymedia-user-account - #:group #$%readymedia-user-group)) + #:user #$(if home-service? #f %readymedia-user-account) + #:group #$(if home-service? #f %readymedia-user-group))) (stop #~(make-kill-destructor)))))) (define readymedia-accounts @@ -178,7 +197,7 @@ (define readymedia-accounts (define (readymedia-activation config) "Set up directories for ReadyMedia/MiniDLNA." (match-record config <readymedia-configuration> - (cache-directory log-directory media-directories) + (cache-directory log-directory media-directories home-service?) (with-imported-modules (source-module-closure '((gnu build activation))) #~(begin (use-modules (gnu build activation)) @@ -186,8 +205,10 @@ (define (readymedia-activation config) (for-each (lambda (directory) (unless (file-exists? directory) (mkdir-p/perms directory - (getpw #$%readymedia-user-account) - #o775))) + (getpw #$(if home-service? + (getuid) + %readymedia-user-account)) + (if home-service? #o755 #o775)))) (list #$cache-directory #$log-directory #$@(map readymedia-media-directory-path -- 2.48.1
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.