(define-module (ruther home services xdg-desktop-portals) #:use-module (srfi srfi-1) #:use-module (guix gexp) #:use-module (guix packages) #:use-module (guix build-system copy) #:use-module (rde serializers ini) #:use-module (gnu services) #:use-module (gnu home services) #:use-module (gnu packages freedesktop) #:use-module (gnu services configuration) #:export (xdg-desktop-portals-conf xdg-desktop-portal-configuration)) (define-configuration/no-serialization xdg-desktop-portals-conf (name string "Name of the portals configuration, like sway. Set your XDG_CURRENT_DESKTOP to this name to use this config") (config ini-config "Configuration for the given x-portals.conf.")) (define (list-of-xdg-portals-conf? lst) (every xdg-desktop-portals-conf? lst)) (define (list-of-file-like? lst) (every file-like? lst)) (define-configuration/no-serialization xdg-desktop-portal-configuration (xdg-desktop-portal (file-like xdg-desktop-portal) "The xdg-desktop-portal to add to the home profile.") (implementations list-of-file-like "The implementations of xdg-desktop-portal interfaces to add to the home profile.") (configs list-of-xdg-portals-conf "Configurations to provide for xdg portals.confs")) (define (xdg-desktop-portals-conf-files config) (computed-file "union-of-portals.conf" (with-imported-modules '((guix build utils)) #~(begin (use-modules (guix build utils)) (mkdir-p (string-append #$output "/share/xdg-desktop-portal")) (for-each (lambda (portals-conf) (call-with-output-file (string-append #$output "/share/xdg-desktop-portal/" (car portals-conf) "-portals.conf") (lambda (port) (display (apply string-append (cdr portals-conf)) port)))) '#$(map (lambda (x) (cons (xdg-desktop-portals-conf-name x) (serialize-ini-config (xdg-desktop-portals-conf-config x) #:equal-string "="))) (xdg-desktop-portal-configuration-configs config))))))) (define (add-xdg-desktop-portals-packages config) (cons* (xdg-desktop-portal-configuration-xdg-desktop-portal config) (package (name "union-of-portals.conf") (version "0.0.0") (source (xdg-desktop-portals-conf-files config)) (build-system copy-build-system) (synopsis "Union of portals.conf files") (description "Union of portals.conf files") (license #f) (home-page #f)) (xdg-desktop-portal-configuration-implementations config))) (define-public home-xdg-desktop-portal-service-type (service-type (name 'xdg-desktop-portal-service) (description "A service to provide xdg-desktop-portal config files, and add implementations to the home profile.") (extensions (list (service-extension home-profile-service-type add-xdg-desktop-portals-packages)))))