From 1bb96ebf8b93b856de64d7bb02c8fb47254932cb Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sat, 3 Jun 2023 23:59:17 +0200 Subject: Indent *-file functions more conveniently Files with potentially long or complex contents shouldn't be indented quite as far. --- .dir-locals.el | 5 +++ tw/channels.scm | 2 +- tw/home.scm | 66 +++++++++++++++++++-------------------- tw/services/media.scm | 34 ++++++++++---------- tw/services/nextcloud.scm | 21 ++++++------- tw/services/restic.scm | 79 +++++++++++++++++++++++------------------------ tw/system/cern.scm | 31 +++++++++---------- tw/system/lap.scm | 33 ++++++++++---------- 8 files changed, 135 insertions(+), 136 deletions(-) diff --git a/.dir-locals.el b/.dir-locals.el index f2f5ef8a..2317c777 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -117,7 +117,12 @@ (eval . (put 'with-http-server 'scheme-indent-function 1)) + (eval . (put 'extra-special-file 'scheme-indent-function 1)) (eval . (put 'computed-file 'scheme-indent-function 1)) + (eval . (put 'program-file 'scheme-indent-function 1)) + (eval . (put 'scheme-file 'scheme-indent-function 1)) + (eval . (put 'plain-file 'scheme-indent-function 1)) + (eval . (put 'mixed-text-file 'scheme-indent-function 1)) ;; My own functions. (eval . (put 'combined-text-file 'scheme-indent-function 1)) diff --git a/tw/channels.scm b/tw/channels.scm index b9d243b8..ff9cdfac 100644 --- a/tw/channels.scm +++ b/tw/channels.scm @@ -38,4 +38,4 @@ (substitute-urls '("https://substitutes.nonguix.org")))) (extra-special-file "/etc/guix/channels.scm" - (scheme-file "channels.scm" %system-channels)))) + (scheme-file "channels.scm" %system-channels)))) diff --git a/tw/home.scm b/tw/home.scm index 9bc9384a..ebd76aa3 100644 --- a/tw/home.scm +++ b/tw/home.scm @@ -298,24 +298,23 @@ auto-expand-secmem "$_JAVA_OPTIONS${_JAVA_OPTIONS:+ }-Djava.util.prefs.userRoot=$XDG_CONFIG_HOME/java"))))) (define polybar-wrapper - (program-file - "polybar-wrapper" - #~(begin - ;; This wrapper program checks that the monitor we want to start - ;; polybar on is actually connected. - (use-modules (ice-9 popen) - (ice-9 rdelim)) - (let* ((connected-str (string-append (getenv "POLYBAR_MONITOR") " connected")) - (xrandr (open-pipe* OPEN_READ #$(file-append xrandr "/bin/xrandr") "-q")) - (monitor-connected? - (let loop ((line (read-line xrandr))) - (cond - ((eof-object? line) #f) ; we didn't find our monitor connected - ((string-prefix? connected-str line) #t) ; the monitor we want is connected - (else (loop (read-line xrandr))))))) ; keep looking - (close-pipe xrandr) - (when monitor-connected? - (execl #$(file-append polybar "/bin/polybar"))))))) + (program-file "polybar-wrapper" + #~(begin + ;; This wrapper program checks that the monitor we want to start + ;; polybar on is actually connected. + (use-modules (ice-9 popen) + (ice-9 rdelim)) + (let* ((connected-str (string-append (getenv "POLYBAR_MONITOR") " connected")) + (xrandr (open-pipe* OPEN_READ #$(file-append xrandr "/bin/xrandr") "-q")) + (monitor-connected? + (let loop ((line (read-line xrandr))) + (cond + ((eof-object? line) #f) ; we didn't find our monitor connected + ((string-prefix? connected-str line) #t) ; the monitor we want is connected + (else (loop (read-line xrandr))))))) ; keep looking + (close-pipe xrandr) + (when monitor-connected? + (execl #$(file-append polybar "/bin/polybar"))))))) (define-public (polybar-service monitor) (shepherd-service @@ -529,7 +528,7 @@ auto-expand-secmem ("kitty/diff.conf" ,(combined-text-file "kitty-diff.conf" (plain-file "kitty-diff-custom.conf" - "pygments_style bw\n") + "pygments_style bw\n") catppuccin-kitty-diff)) ("kitty/kitty.conf" ,(combined-text-file "kitty.conf" @@ -560,22 +559,23 @@ auto-expand-secmem (simple-service 'gui-scripts home-files-service-type `(;; https://sw.kovidgoyal.net/kitty/kittens/diff/ (".local/bin/kdiff" ; show a diff - ,(program-file "kdiff" #~(apply execl #$(file-append kitty "/bin/kitty") "kitty" - "+kitten" "diff" (cdr (command-line))))) + ,(program-file "kdiff" + #~(apply execl #$(file-append kitty "/bin/kitty") "kitty" + "+kitten" "diff" (cdr (command-line))))) (".local/bin/icat" ; kitty's "catimg" equivalent - ,(program-file "icat" #~(apply execl #$(file-append kitty "/bin/kitty") "kitty" - "+kitten" "icat" (cdr (command-line))))) + ,(program-file "icat" + #~(apply execl #$(file-append kitty "/bin/kitty") "kitty" + "+kitten" "icat" (cdr (command-line))))) (".local/bin/screenlock" - ,(program-file - "screenlock" - #~(begin ; Wrapper around i3lock to turn off the screen and pause notifications. - (system* #$(file-append dunst "/bin/dunstctl") "set-paused" "true") - (system* #$(file-append xset "/bin/xset") "dpms" "0" "0" "5") - ;; We mustn't use `file-append' here, as we have to pick up the - ;; setuid binary for i3lock installed by the system config. - (system* "i3lock" "-nc" #$catppuccin-background-color) - (system* #$(file-append xset "/bin/xset") "dpms" "600" "600" "600") - (system* #$(file-append dunst "/bin/dunstctl") "set-paused" "false")))) + ,(program-file "screenlock" + #~(begin ; Wrapper around i3lock to turn off the screen and pause notifications. + (system* #$(file-append dunst "/bin/dunstctl") "set-paused" "true") + (system* #$(file-append xset "/bin/xset") "dpms" "0" "0" "5") + ;; We mustn't use `file-append' here, as we have to pick up the + ;; setuid binary for i3lock installed by the system config. + (system* "i3lock" "-nc" #$catppuccin-background-color) + (system* #$(file-append xset "/bin/xset") "dpms" "600" "600" "600") + (system* #$(file-append dunst "/bin/dunstctl") "set-paused" "false")))) ;; With #:recursive? #t, Guix keeps the files' permission bits, i.e. makes them executable. (".local/bin/sessionmenu" ,(local-file "home/files/sessionmenu" #:recursive? #t)) (".local/bin/passmenu" ,(local-file "home/files/passmenu" #:recursive? #t)) diff --git a/tw/services/media.scm b/tw/services/media.scm index ec4d0afc..36637093 100644 --- a/tw/services/media.scm +++ b/tw/services/media.scm @@ -44,16 +44,15 @@ run the download script. By default, picks a random time between 04:00 and (string-append (yt-dlp-configuration-media-directory config) "/.yt-dlp/yt-dlp")))) #~(job #$(yt-dlp-configuration-schedule config) - #$(program-file - "yt-dlp-command" - #~(begin - (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) - (chdir #$(yt-dlp-configuration-media-directory config)) - ;; Auto-update if we're using yt-dlp from the media directory. - #$@(if yt-dlp-package '() - (list #~(system* #$yt-dlp-executable "--ignore-config" "--update"))) - (execl #$yt-dlp-executable - "yt-dlp" "--ignore-config" "--config-location" ".yt-dlp"))) + #$(program-file "yt-dlp-command" + #~(begin + (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) + (chdir #$(yt-dlp-configuration-media-directory config)) + ;; Auto-update if we're using yt-dlp from the media directory. + #$@(if yt-dlp-package '() + (list #~(system* #$yt-dlp-executable "--ignore-config" "--update"))) + (execl #$yt-dlp-executable + "yt-dlp" "--ignore-config" "--config-location" ".yt-dlp"))) #:user #$(yt-dlp-configuration-user config))))) (define yt-dlp-service-type @@ -77,14 +76,13 @@ run the download script. By default, picks a random time between 01:00 and (define (get-iplayer-cronjob config) (list #~(job #$(get-iplayer-configuration-schedule config) - #$(program-file - "get-iplayer-command" - #~(begin - (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) - (execl #$(file-append (get-iplayer-configuration-get-iplayer config) - "/bin/get_iplayer") - "get_iplayer" "--pvr" "--profile-dir" - #$(get-iplayer-configuration-config-directory config)))) + #$(program-file "get-iplayer-command" + #~(begin + (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) + (execl #$(file-append (get-iplayer-configuration-get-iplayer config) + "/bin/get_iplayer") + "get_iplayer" "--pvr" "--profile-dir" + #$(get-iplayer-configuration-config-directory config)))) #:user #$(get-iplayer-configuration-user config)))) (define get-iplayer-service-type diff --git a/tw/services/nextcloud.scm b/tw/services/nextcloud.scm index 7545474d..6ede7005 100644 --- a/tw/services/nextcloud.scm +++ b/tw/services/nextcloud.scm @@ -104,17 +104,16 @@ Header always set Strict-Transport-Security \"max-age=15552000\" ;; Nextcloud cron (simple-service 'nextcloud-cron mcron-service-type (list #~(job "*/5 * * * *" - #$(program-file - "nextcloud-cron-command" - #~(begin - ;; `setgid' first while we're still root - (setgid (group:gid (getgr "httpd"))) - (setuid (passwd:uid (getpw "httpd"))) - (chdir "/var/www/nextcloud") - ;; Nextcloud News needs this to fetch HTTPS feeds. - (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) - (execl #$(file-append php "/bin/php") "php" - "-c" #$%nextcloud-php.ini "cron.php")))) + #$(program-file "nextcloud-cron-command" + #~(begin + ;; `setgid' first while we're still root + (setgid (group:gid (getgr "httpd"))) + (setuid (passwd:uid (getpw "httpd"))) + (chdir "/var/www/nextcloud") + ;; Nextcloud News needs this to fetch HTTPS feeds. + (setenv "SSL_CERT_DIR" #$(file-append nss-certs "/etc/ssl/certs")) + (execl #$(file-append php "/bin/php") "php" + "-c" #$%nextcloud-php.ini "cron.php")))) ;; Nextcloud backups ;; Requires: sudo, php, btrfs, mysqldump, rsync diff --git a/tw/services/restic.scm b/tw/services/restic.scm index 62764750..f3ad6f82 100644 --- a/tw/services/restic.scm +++ b/tw/services/restic.scm @@ -151,26 +151,26 @@ true." (define (cronjob repo) #~(job #$(restic-cleanup-repository-schedule repo) #$(program-file - ;; Make cron commands for different repos easier to distinguish. - (format #f "restic-cleanup-~a-command" - (string-trim-right (basename (restic-cleanup-repository-url repo)) #\/)) - #~(begin - ;; `setgid' first, while we're still root. - (setgid (group:gid (getgr #$%restic-group))) - (setuid (passwd:uid (getpw #$%restic-user))) - (setenv "RESTIC_REPOSITORY" '#$(restic-cleanup-repository-url repo)) - (setenv "RESTIC_PASSWORD_FILE" '#$(restic-cleanup-repository-password-file repo)) - (execl #$(file-append (restic-cleanup-repository-restic repo) "/bin/restic") - "restic" "forget" "--no-cache" - #$@(arg-with-value "--prune" (restic-cleanup-repository-prune? repo)) - #$@(arg-with-value "--path" (restic-cleanup-repository-snapshot-paths repo)) - #$@(arg-with-value "--keep-within" (restic-cleanup-repository-keep-within repo)) - #$@(arg-with-value "--keep-last" (restic-cleanup-repository-keep-last repo)) - #$@(arg-with-value "--keep-hourly" (restic-cleanup-repository-keep-hourly repo)) - #$@(arg-with-value "--keep-daily" (restic-cleanup-repository-keep-daily repo)) - #$@(arg-with-value "--keep-weekly" (restic-cleanup-repository-keep-weekly repo)) - #$@(arg-with-value "--keep-monthly" (restic-cleanup-repository-keep-monthly repo)) - #$@(arg-with-value "--keep-yearly" (restic-cleanup-repository-keep-yearly repo))))))) + ;; Make cron commands for different repos easier to distinguish. + (format #f "restic-cleanup-~a-command" + (string-trim-right (basename (restic-cleanup-repository-url repo)) #\/)) + #~(begin + ;; `setgid' first, while we're still root. + (setgid (group:gid (getgr #$%restic-group))) + (setuid (passwd:uid (getpw #$%restic-user))) + (setenv "RESTIC_REPOSITORY" '#$(restic-cleanup-repository-url repo)) + (setenv "RESTIC_PASSWORD_FILE" '#$(restic-cleanup-repository-password-file repo)) + (execl #$(file-append (restic-cleanup-repository-restic repo) "/bin/restic") + "restic" "forget" "--no-cache" + #$@(arg-with-value "--prune" (restic-cleanup-repository-prune? repo)) + #$@(arg-with-value "--path" (restic-cleanup-repository-snapshot-paths repo)) + #$@(arg-with-value "--keep-within" (restic-cleanup-repository-keep-within repo)) + #$@(arg-with-value "--keep-last" (restic-cleanup-repository-keep-last repo)) + #$@(arg-with-value "--keep-hourly" (restic-cleanup-repository-keep-hourly repo)) + #$@(arg-with-value "--keep-daily" (restic-cleanup-repository-keep-daily repo)) + #$@(arg-with-value "--keep-weekly" (restic-cleanup-repository-keep-weekly repo)) + #$@(arg-with-value "--keep-monthly" (restic-cleanup-repository-keep-monthly repo)) + #$@(arg-with-value "--keep-yearly" (restic-cleanup-repository-keep-yearly repo))))))) (map cronjob repositories)) @@ -207,26 +207,25 @@ passwords in @code{rest:} URLs.") (define (restic-backup-cronjobs repositories) (define (cronjob repo) #~(job #$(restic-backup-repository-schedule repo) - #$(program-file - "restic-backup-command" - #~(begin - (use-modules (ice-9 popen) - (ice-9 textual-ports) - (srfi srfi-1)) - (define (replace-home path) - (if (string-prefix? "~/" path) - (string-replace path (getenv "HOME") 0 1) - path)) - (setenv "RESTIC_PASSWORD_COMMAND" - '#$(restic-backup-repository-password-command repo)) - (let ((pipe (open-pipe '#$(restic-backup-repository-url-command repo) OPEN_READ))) - (setenv "RESTIC_REPOSITORY" (string-trim-right (get-string-all pipe) #\newline)) - (close-pipe pipe)) - (apply execl #$(file-append (restic-backup-repository-restic repo) "/bin/restic") - "restic" "backup" "--cleanup-cache" - #$@(append-map (lambda (tag) (list "--tag" tag)) - (restic-backup-repository-tags repo)) - (map replace-home '#$(restic-backup-repository-paths repo))))))) + #$(program-file "restic-backup-command" + #~(begin + (use-modules (ice-9 popen) + (ice-9 textual-ports) + (srfi srfi-1)) + (define (replace-home path) + (if (string-prefix? "~/" path) + (string-replace path (getenv "HOME") 0 1) + path)) + (setenv "RESTIC_PASSWORD_COMMAND" + '#$(restic-backup-repository-password-command repo)) + (let ((pipe (open-pipe '#$(restic-backup-repository-url-command repo) OPEN_READ))) + (setenv "RESTIC_REPOSITORY" (string-trim-right (get-string-all pipe) #\newline)) + (close-pipe pipe)) + (apply execl #$(file-append (restic-backup-repository-restic repo) "/bin/restic") + "restic" "backup" "--cleanup-cache" + #$@(append-map (lambda (tag) (list "--tag" tag)) + (restic-backup-repository-tags repo)) + (map replace-home '#$(restic-backup-repository-paths repo))))))) (map cronjob repositories)) (define home-restic-backup-service-type diff --git a/tw/system/cern.scm b/tw/system/cern.scm index 508a7691..7ca6eab2 100644 --- a/tw/system/cern.scm +++ b/tw/system/cern.scm @@ -95,22 +95,21 @@ %base-user-accounts)) (sudoers-file - (plain-file - "sudoers" - (string-append - ;; We need to preserve $TERMINFO so that programs under sudo can - ;; find kitty's terminfo files. This is possibly unsafe; sudo - ;; explicitly deletes this variable by default. - "Defaults env_keep += \"TERMINFO\"\n" - (plain-file-content %sudoers-specification) - ;; In addition to the default rules, allow admins to power off - ;; the computer. They'll have to use the system binaries, not - ;; those from their user profile, as /etc/sudoers requires - ;; absolute paths to commands. - "%wheel ALL=(ALL) NOPASSWD: " - "/run/current-system/profile/sbin/halt, " - "/run/current-system/profile/sbin/reboot, " - "/run/current-system/profile/sbin/shutdown\n"))) + (plain-file "sudoers" + (string-append + ;; We need to preserve $TERMINFO so that programs under sudo can + ;; find kitty's terminfo files. This is possibly unsafe; sudo + ;; explicitly deletes this variable by default. + "Defaults env_keep += \"TERMINFO\"\n" + (plain-file-content %sudoers-specification) + ;; In addition to the default rules, allow admins to power off + ;; the computer. They'll have to use the system binaries, not + ;; those from their user profile, as /etc/sudoers requires + ;; absolute paths to commands. + "%wheel ALL=(ALL) NOPASSWD: " + "/run/current-system/profile/sbin/halt, " + "/run/current-system/profile/sbin/reboot, " + "/run/current-system/profile/sbin/shutdown\n"))) ;; This is where we specify system-wide packages. (packages diff --git a/tw/system/lap.scm b/tw/system/lap.scm index e9df3abf..1bcc0d78 100644 --- a/tw/system/lap.scm +++ b/tw/system/lap.scm @@ -222,22 +222,21 @@ support extra features (acr, pmu, gr).") %base-user-accounts)) (sudoers-file - (plain-file - "sudoers" - (string-append - ;; We need to preserve $TERMINFO so that programs under sudo can - ;; find kitty's terminfo files. This is possibly unsafe; sudo - ;; explicitly deletes this variable by default. - "Defaults env_keep += \"TERMINFO\"\n" - (plain-file-content %sudoers-specification) - ;; In addition to the default rules, allow admins to power off - ;; the computer. They'll have to use the system binaries, not - ;; those from their user profile, as /etc/sudoers requires - ;; absolute paths to commands. - "%wheel ALL=(ALL) NOPASSWD: " - "/run/current-system/profile/sbin/halt, " - "/run/current-system/profile/sbin/reboot, " - "/run/current-system/profile/sbin/shutdown\n"))) + (plain-file "sudoers" + (string-append + ;; We need to preserve $TERMINFO so that programs under sudo can + ;; find kitty's terminfo files. This is possibly unsafe; sudo + ;; explicitly deletes this variable by default. + "Defaults env_keep += \"TERMINFO\"\n" + (plain-file-content %sudoers-specification) + ;; In addition to the default rules, allow admins to power off + ;; the computer. They'll have to use the system binaries, not + ;; those from their user profile, as /etc/sudoers requires + ;; absolute paths to commands. + "%wheel ALL=(ALL) NOPASSWD: " + "/run/current-system/profile/sbin/halt, " + "/run/current-system/profile/sbin/reboot, " + "/run/current-system/profile/sbin/shutdown\n"))) ;; This is where we specify system-wide packages. (packages @@ -366,7 +365,7 @@ support extra features (acr, pmu, gr).") " --fstab --verbose")))) (extra-special-file "/etc/NetworkManager/dispatcher.d/09-set-timezone" - (program-file "set-timezone" set-timezone-script)) + (program-file "set-timezone" set-timezone-script)) (modify-services (append %system-channel-services %desktop-services) (gdm-service-type -- cgit v1.2.3