mirror of
https://git.in.rschanz.org/ryan77627/guix-config.git
synced 2025-02-11 14:51:16 -05:00
Added service to periodically clean Downloads folder
This commit is contained in:
parent
de3f5434bd
commit
012e58699d
2 changed files with 45 additions and 1 deletions
|
@ -195,6 +195,9 @@
|
||||||
(prefer
|
(prefer
|
||||||
(family "DejaVu Sans Mono")))))
|
(family "DejaVu Sans Mono")))))
|
||||||
(service home-dbus-service-type)
|
(service home-dbus-service-type)
|
||||||
|
(service downloads-garbage-collector-service-type
|
||||||
|
(downloads-garbage-collector-configuration
|
||||||
|
(user "ryan")))
|
||||||
;;; trying some changes
|
;;; trying some changes
|
||||||
;(template-files "."
|
;(template-files "."
|
||||||
;'("spotify-player/app.toml"
|
;'("spotify-player/app.toml"
|
||||||
|
|
|
@ -3,10 +3,21 @@
|
||||||
#:use-module (gnu packages base)
|
#:use-module (gnu packages base)
|
||||||
#:use-module (gnu services)
|
#:use-module (gnu services)
|
||||||
#:use-module (gnu services configuration)
|
#:use-module (gnu services configuration)
|
||||||
|
#:use-module (gnu services shepherd)
|
||||||
#:use-module (gnu home services)
|
#:use-module (gnu home services)
|
||||||
#:use-module (gnu home services shepherd)
|
#:use-module (gnu home services shepherd)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (guix gexp))
|
#:use-module (guix gexp)
|
||||||
|
#:use-module (guix records)
|
||||||
|
#:export (downloads-garbage-collector-service-type
|
||||||
|
downloads-garbage-collector-configuration
|
||||||
|
downloads-garbage-collector-configuration?))
|
||||||
|
|
||||||
|
(define-configuration downloads-garbage-collector-configuration
|
||||||
|
(user
|
||||||
|
(string "")
|
||||||
|
"User to run under")
|
||||||
|
(no-serialization))
|
||||||
|
|
||||||
(define-public (home-symlinks files)
|
(define-public (home-symlinks files)
|
||||||
;; Simple service to symlink two paths. Treats all paths with HOME prepended
|
;; Simple service to symlink two paths. Treats all paths with HOME prepended
|
||||||
|
@ -23,3 +34,33 @@
|
||||||
#f)
|
#f)
|
||||||
(symlink full-path1 full-path2)))))
|
(symlink full-path1 full-path2)))))
|
||||||
files))
|
files))
|
||||||
|
|
||||||
|
(define downloads-garbage-collector-service
|
||||||
|
(match-record-lambda <downloads-garbage-collector-configuration>
|
||||||
|
(user)
|
||||||
|
(let ((cleanup-command #~(list "find" (string-append "/home/" #$user "/Downloads") "-mtime" "+7" "-exec" "rm" "-rf" "{}" "';'")))
|
||||||
|
(shepherd-service
|
||||||
|
(documentation "Garbage collect downloaded files more than 1 week old for USER.")
|
||||||
|
(provision '(downloads-garbage-collector))
|
||||||
|
;(requirement '(root))
|
||||||
|
(modules '((shepherd service timer)))
|
||||||
|
(start #~(make-timer-constructor
|
||||||
|
(calendar-event #:hours '(8) #:minutes '(20)
|
||||||
|
#:days-of-week '(tuesday))
|
||||||
|
(command #$cleanup-command)))
|
||||||
|
(stop #~(make-timer-destructor))
|
||||||
|
(actions (list (shepherd-action
|
||||||
|
(name 'trigger)
|
||||||
|
(documentation "Trigger GC in Downloads folder for USER")
|
||||||
|
(procedure #~(lambda _
|
||||||
|
(system (string-join #$cleanup-command " ")))))))))))
|
||||||
|
|
||||||
|
(define-public downloads-garbage-collector-service-type
|
||||||
|
(service-type
|
||||||
|
(name 'downloads-garbage-collector)
|
||||||
|
(description "Given a USER, clear files older than 1 week from Downloads folder")
|
||||||
|
(extensions
|
||||||
|
(list
|
||||||
|
(service-extension home-shepherd-service-type
|
||||||
|
(compose list downloads-garbage-collector-service))))
|
||||||
|
(default-value (downloads-garbage-collector-configuration))))
|
||||||
|
|
Loading…
Reference in a new issue