dotfiles/guix-config/home/services/flatpak.scm

79 lines
2.6 KiB
Scheme

(define-module (guix-config home services flatpak)
#:use-module (gnu home services)
#:use-module (gnu home services utils)
#:use-module (gnu services)
#:use-module (gnu packages package-management)
#:use-module (guix gexp)
#:use-module (guix records)
#:export (home-flatpak-configuration
home-flatpak-service-type))
;; Configuration record
(define-record-type* <home-flatpak-configuration>
home-flatpak-configuration make-home-flatpak-configuration
home-flatpak-configuration?
(flatpak-package home-flatpak-configuration-flatpak-package
(default flatpak))
(remotes home-flatpak-configuration-remotes
(default '(("flathub" . "https://flathub.org/repo/flathub.flatpakrepo"))))
(apps home-flatpak-configuration-apps (default '())))
;; Service type
(define (home-flatpak-activation config)
#~(begin
(use-modules (ice-9 popen) (ice-9 rdelim) (srfi srfi-1))
(define (run cmd)
(format #t "Running: ~a~%" cmd)
(system* "bash" "-c" cmd))
;; Add remotes if missing
(for-each
(lambda (pair)
(let ((name (car pair))
(url (cdr pair)))
(run (string-append
"flatpak remote-add --user --if-not-exists "
name " " url))))
'#$(home-flatpak-configuration-remotes config))
;; Install apps
(for-each
(lambda (app)
(run (string-append "flatpak install -y --user " app)))
'#$(home-flatpak-configuration-apps config))))
(define (home-flatpak-service config)
(list
;; 1. Ensure flatpak installed
(simple-service
'flatpak-packages
home-profile-service-type
(list (home-flatpak-configuration-flatpak-package config)))
;; 2. Add flatpak apps to XDG_DATA_DIRS
;; https://forum.systemcrafters.net/t/gnome-software-center-flatpak-support/1702/3
(simple-service
'flatpak-env
home-shell-profile-service-type
(list (local-file
(string-append (getenv "HOME") "/.guix-profile/etc/profile.d/flatpak.sh")
"flatpak.sh")))
;; 3. Activation phase
(simple-service
'flatpak-activation
home-activation-service-type
(home-flatpak-activation config))))
(define home-flatpak-service-type
(service-type
(name 'home-flatpak)
(extensions
(list (service-extension home-profile-service-type
(compose list home-flatpak-configuration-flatpak-package))
(service-extension home-activation-service-type
home-flatpak-activation)))
(default-value (home-flatpak-configuration))
(description "Set up Flatpak with user remotes and apps.")))