From 6e746443983827b2db895e8da9822288e7eb76e7 Mon Sep 17 00:00:00 2001 From: Jakub Czajka Date: Fri, 23 Dec 2022 20:30:29 +0100 Subject: [PATCH] [home] Set the wallpaper using a shepherd service. --- conf/home/wallpaper.scm | 91 +++++++++++++++++++++++++++++++++++++++++ scripts/wallpaper | 5 +++ 2 files changed, 96 insertions(+) create mode 100644 conf/home/wallpaper.scm create mode 100755 scripts/wallpaper diff --git a/conf/home/wallpaper.scm b/conf/home/wallpaper.scm new file mode 100644 index 0000000..d358472 --- /dev/null +++ b/conf/home/wallpaper.scm @@ -0,0 +1,91 @@ +;; Copyright (c) 2022 Jakub Czajka +;; 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 make-wallpaper-configuration + wallpaper-configuration? + (package wallpaper-configuration-package + (default wallpaper))) + +(define wallpaper-shepherd-service + (match-lambda + (($ 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 index 0000000..ce729f0 --- /dev/null +++ b/scripts/wallpaper @@ -0,0 +1,5 @@ +#!/bin/sh +# Copyright (c) 2022 Jakub Czajka +# License: GPL-3.0 or later. + +feh --no-fehbg --bg-scale "${XDG_DATA_HOME}/wallpapers/current" -- 2.39.5