From 99675cf4fd61809fd674cb87c6d69c26279d56c5 Mon Sep 17 00:00:00 2001 From: Luis Guilherme Coelho Date: Sun, 24 Nov 2024 22:06:13 -0300 Subject: [PATCH] operating-systems: buer: Setup timer-related shepherd-services --- operating-systems/buer.scm | 16 ++++--- operating-systems/buer/shepherd-services.scm | 44 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 operating-systems/buer/shepherd-services.scm diff --git a/operating-systems/buer.scm b/operating-systems/buer.scm index 37ecc8d..3d47609 100644 --- a/operating-systems/buer.scm +++ b/operating-systems/buer.scm @@ -26,7 +26,6 @@ #|D|# #:use-module (gnu services dbus) #:use-module (gnu services desktop) #|G|# #:use-module (gnu services guix) - #|M|# #:use-module (gnu services mcron) #|L|# #:use-module (gnu services linux) #|N|# #:use-module (gnu services networking) #|P|# #:use-module (gnu services pm) @@ -81,7 +80,9 @@ #:prefix privileged-programs:) #|R|# #:use-module ((buer rules) #:prefix rules:) - #|S|# #:use-module ((buer substitute-keys) + #|S|# #:use-module ((buer shepherd-services) + #:prefix shepherd-service:) + #:use-module ((buer substitute-keys) #:prefix substitute-key:) #|U|# #:use-module ((buer users) #:prefix user:) @@ -175,7 +176,10 @@ (operating-system-default-essential-services this-operating-system) (shepherd-root-service-type _ => (shepherd-configuration - (shepherd (@ (shepherd-package) shepherd)))))) + (shepherd (@ (shepherd-package) shepherd)) + (services (list shepherd-service:guix-gc + shepherd-service:snapshot-@home + shepherd-service:timer)))))) #|System services|# (services @@ -233,12 +237,6 @@ "--gc-keep-derivations=yes" "--gc-keep-outputs=yes")))) - #|Mcron service|# - (service mcron-service-type - (mcron-configuration - (jobs (list #~(job "* * * * Sun" - "guix gc --optimize --free-space=10G"))))) - #|Device management services|# (service udev-service-type (udev-configuration diff --git a/operating-systems/buer/shepherd-services.scm b/operating-systems/buer/shepherd-services.scm new file mode 100644 index 0000000..08570e9 --- /dev/null +++ b/operating-systems/buer/shepherd-services.scm @@ -0,0 +1,44 @@ +(define-module (buer shepherd-services) + #:use-module (guix gexp) + #:use-module (gnu services shepherd) + #:use-module (shepherd service timer) + + #:export (guix-gc snapshot-@home timer)) + +(define timer-trigger-action + (shepherd-action + (name 'trigger) + (procedure #~trigger-timer) + (documentation + "Trigger the action associated with @var{timer} as if it had reached its +next calendar event."))) + +(define guix-gc + (shepherd-service + (provision '(guix-gc)) + (modules '((shepherd service timer))) + (start #~(make-timer-constructor + (calendar-event #:days-of-month '(1 15)) + (command '("guix" "gc" "--optimize" "--free-space=10G")))) + (stop #~(make-timer-destructor)) + (actions (list timer-trigger-action)))) + +(define snapshot-@home + (shepherd-service + (provision '(snapshot-@home)) + (modules '((shepherd service timer))) + (start #~(make-timer-constructor + (calendar-event #:days-of-month '(1 15)) + (lambda () + (let* ((btrfs "/run/current-system/profile/bin/btrfs") + (date (strftime "%Y-%m-%d" (localtime (current-time))))) + (system* btrfs "subvolume" "snapshot" "/home" + (string-append "/snapshots/home/" date)))))) + (stop #~(make-timer-destructor)) + (actions (list timer-trigger-action)))) + +(define timer + (shepherd-service + (provision '(timer)) + (modules '((shepherd service timer))) + (free-form #~(timer-service))))