]> git.ekhem.eu.org Git - guix.git/commitdiff
[home] Set the wallpaper using a shepherd service.
authorJakub Czajka <jakub@ekhem.eu.org>
Fri, 23 Dec 2022 19:30:29 +0000 (20:30 +0100)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:53:07 +0000 (19:53 +0100)
conf/home/wallpaper.scm [new file with mode: 0644]
scripts/wallpaper [new file with mode: 0755]

diff --git a/conf/home/wallpaper.scm b/conf/home/wallpaper.scm
new file mode 100644 (file)
index 0000000..d358472
--- /dev/null
@@ -0,0 +1,91 @@
+;; 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))
diff --git a/scripts/wallpaper b/scripts/wallpaper
new file mode 100755 (executable)
index 0000000..ce729f0
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/sh
+# Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+# License: GPL-3.0 or later.
+
+feh --no-fehbg --bg-scale "${XDG_DATA_HOME}/wallpapers/current"