--- /dev/null
+;; Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+;; License: GPL-3.0 or later.
+;;
+;; wallpaper.scm - program for installing wallpapers.
+
+(define-module (conf home wallpaper)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services shepherd)
+ #:use-module (gnu packages image-viewers)
+ #:use-module (guix build-system trivial)
+ #:use-module (guix gexp)
+ #:use-module (guix licenses)
+ #:use-module (guix packages)
+ #:use-module (guix records)
+ #:use-module (ice-9 match)
+ #:export (wallpaper
+ wallpaper-configuration
+ wallpaper-configuration?
+ wallpaper-configuration-package
+ wallpaper-service
+ wallpaper-service-type))
+
+(define wallpaper
+ (package
+ (name "wallpaper")
+ (version "1.0")
+ (source
+ (local-file
+ (string-concatenate
+ (list (getenv "GUIX_PACKAGE_PATH")
+ "/scripts/wallpaper"))))
+ (build-system trivial-build-system)
+ (arguments
+ '(#:modules ((guix build utils))
+ #:builder
+ (begin
+ (use-modules (guix build utils))
+
+ (let* ((ins (assoc-ref %build-inputs "source"))
+ (out (assoc-ref %outputs "out"))
+ (dir (string-concatenate (list out "/bin")))
+ (file (string-append dir "/wallpaper")))
+ (mkdir-p dir)
+ (copy-file ins file)
+ (chmod file #o555)))))
+ (synopsis "Set an image as wallpaper.")
+ (description "`wallpaper` gets a path to an image as an arguments and sets
+this image as the system's wallpaper.")
+ (home-page "https://git.ekhem.eu.org")
+ (license gpl3+)))
+
+(define-record-type* <wallpaper-configuration>
+ wallpaper-configuration make-wallpaper-configuration
+ wallpaper-configuration?
+ (package wallpaper-configuration-package
+ (default wallpaper)))
+
+(define wallpaper-shepherd-service
+ (match-lambda
+ (($ <wallpaper-configuration> package)
+ (shepherd-service
+ (provision '(wallpaper))
+ (respawn? #f)
+ (start #~(make-forkexec-constructor
+ (list #$(file-append package "/bin/wallpaper"))
+ #:directory
+ (getenv "HOME")
+ #:log-file
+ (string-append (getenv "XDG_LOG_HOME")
+ "/wallpaper.log")))
+ (stop #~(make-kill-destructor))
+ (documentation "")))))
+
+(define (install-wallpaper config)
+ (list (wallpaper-configuration-package config)
+ feh))
+
+(define wallpaper-service-type
+ (service-type
+ (name 'wallpaper-service)
+ (extensions
+ (list (service-extension home-profile-service-type
+ install-wallpaper)
+ (service-extension home-shepherd-service-type
+ (compose list
+ wallpaper-shepherd-service))))
+ (default-value (wallpaper-configuration))
+ (description "Shepherd service to run `wallpaper` once.")))
+
+(define wallpaper-service
+ (service wallpaper-service-type))