A guixrus/home/services/toys.scm => guixrus/home/services/toys.scm +62 -0
@@ 0,0 1,62 @@
+(define-module (guixrus home services toys)
+ #:use-module (guix gexp)
+ #:use-module (gnu home services)
+ #:use-module (gnu home services mcron)
+ #:use-module (gnu home services shepherd)
+ #:use-module (gnu services configuration)
+ #:use-module ((guixrus packages toys) #:prefix rus:)
+
+ #:export (home-toys-service-type
+ home-toys-configuration))
+
+(define (mcron-spec? a-thing)
+ (or (procedure? a-thing)
+ (list? a-thing)
+ (string? a-thing)))
+
+(define-configuration/no-serialization home-toys-configuration
+ (toys
+ (file-like rus:toys)
+ "The toys package to use.")
+ (channels-file
+ (file-like #f)
+ "The channels file with the list of toys boxes.")
+ (pull-interval
+ (mcron-spec "* */2 * * *")
+ "The mcron specification (see @command{info mcron 'Guile Syntax'} for more
+details) for the toys pull interval. Defines how often the toys database
+will be updated. The default interval is every 2 hours."))
+
+(define (home-toys-shepherd-services config)
+ (list (shepherd-service
+ (provision '(toys))
+ (documentation "Run toys, a Guix channel webring.")
+ (start #~(make-forkexec-constructor
+ (list (string-append
+ (getenv "HOME")
+ "/.config/guix/current/bin/guix")
+ "toys" "serve")))
+ (stop #~(make-kill-destructor)))))
+
+(define (home-toys-mcron-services config)
+ (list #~(job #$(home-toys-configuration-pull-interval config)
+ (string-append
+ (getenv "HOME")
+ "/.config/guix/current/bin/guix toys pull "
+ #$(home-toys-configuration-channels-file config)))))
+
+(define (home-toys-profile-packages config)
+ (list (home-toys-configuration-toys config)))
+
+(define home-toys-service-type
+ (service-type
+ (name 'home-toys)
+ (default-value '())
+ (extensions
+ (list (service-extension home-shepherd-service-type
+ home-toys-shepherd-services)
+ (service-extension home-mcron-service-type
+ home-toys-mcron-services)
+ (service-extension home-profile-service-type
+ home-toys-profile-packages)))
+ (description "Run toys, a Guix channel webring.")))