operating-systems: buer: Setup timer-related shepherd-services

Luis Guilherme Coelho 2024-11-24 22:06:13 -03:00
parent 101f5404eb
commit 77d40da76f
No known key found for this signature in database
GPG Key ID: 1F2E76ACE3F531C8
2 changed files with 51 additions and 9 deletions

View File

@ -26,7 +26,6 @@
#|D|# #:use-module (gnu services dbus) #|D|# #:use-module (gnu services dbus)
#:use-module (gnu services desktop) #:use-module (gnu services desktop)
#|G|# #:use-module (gnu services guix) #|G|# #:use-module (gnu services guix)
#|M|# #:use-module (gnu services mcron)
#|L|# #:use-module (gnu services linux) #|L|# #:use-module (gnu services linux)
#|N|# #:use-module (gnu services networking) #|N|# #:use-module (gnu services networking)
#|P|# #:use-module (gnu services pm) #|P|# #:use-module (gnu services pm)
@ -81,7 +80,9 @@
#:prefix privileged-programs:) #:prefix privileged-programs:)
#|R|# #:use-module ((buer rules) #|R|# #:use-module ((buer rules)
#:prefix 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:) #:prefix substitute-key:)
#|U|# #:use-module ((buer users) #|U|# #:use-module ((buer users)
#:prefix user:) #:prefix user:)
@ -175,7 +176,10 @@
(operating-system-default-essential-services this-operating-system) (operating-system-default-essential-services this-operating-system)
(shepherd-root-service-type (shepherd-root-service-type
_ => (shepherd-configuration _ => (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|# #|System services|#
(services (services
@ -233,12 +237,6 @@
"--gc-keep-derivations=yes" "--gc-keep-derivations=yes"
"--gc-keep-outputs=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|# #|Device management services|#
(service udev-service-type (service udev-service-type
(udev-configuration (udev-configuration

View File

@ -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))))