diff options
| author | Ryan Schanzenbacher <ryan@rschanz.org> | 2025-01-21 11:37:34 -0500 |
|---|---|---|
| committer | Ryan Schanzenbacher <ryan@rschanz.org> | 2025-01-21 11:37:34 -0500 |
| commit | 012e58699d4183dc27e13d60bf9a85e974d45b07 (patch) | |
| tree | 4e465393d1237f41f5f7063732d213007aeeb387 /modules | |
| parent | de3f5434bd7a1a323663d88d3b0eca15aa8f46bf (diff) | |
Added service to periodically clean Downloads folder
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ryan-services/file-manager.scm | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/modules/ryan-services/file-manager.scm b/modules/ryan-services/file-manager.scm index 9f0bdc4..1f76d0e 100644 --- a/modules/ryan-services/file-manager.scm +++ b/modules/ryan-services/file-manager.scm | |||
| @@ -3,10 +3,21 @@ | |||
| 3 | #:use-module (gnu packages base) | 3 | #:use-module (gnu packages base) |
| 4 | #:use-module (gnu services) | 4 | #:use-module (gnu services) |
| 5 | #:use-module (gnu services configuration) | 5 | #:use-module (gnu services configuration) |
| 6 | #:use-module (gnu services shepherd) | ||
| 6 | #:use-module (gnu home services) | 7 | #:use-module (gnu home services) |
| 7 | #:use-module (gnu home services shepherd) | 8 | #:use-module (gnu home services shepherd) |
| 8 | #:use-module (srfi srfi-1) | 9 | #:use-module (srfi srfi-1) |
| 9 | #:use-module (guix gexp)) | 10 | #:use-module (guix gexp) |
| 11 | #:use-module (guix records) | ||
| 12 | #:export (downloads-garbage-collector-service-type | ||
| 13 | downloads-garbage-collector-configuration | ||
| 14 | downloads-garbage-collector-configuration?)) | ||
| 15 | |||
| 16 | (define-configuration downloads-garbage-collector-configuration | ||
| 17 | (user | ||
| 18 | (string "") | ||
| 19 | "User to run under") | ||
| 20 | (no-serialization)) | ||
| 10 | 21 | ||
| 11 | (define-public (home-symlinks files) | 22 | (define-public (home-symlinks files) |
| 12 | ;; Simple service to symlink two paths. Treats all paths with HOME prepended | 23 | ;; Simple service to symlink two paths. Treats all paths with HOME prepended |
| @@ -23,3 +34,33 @@ | |||
| 23 | #f) | 34 | #f) |
| 24 | (symlink full-path1 full-path2))))) | 35 | (symlink full-path1 full-path2))))) |
| 25 | files)) | 36 | files)) |
| 37 | |||
| 38 | (define downloads-garbage-collector-service | ||
| 39 | (match-record-lambda <downloads-garbage-collector-configuration> | ||
| 40 | (user) | ||
| 41 | (let ((cleanup-command #~(list "find" (string-append "/home/" #$user "/Downloads") "-mtime" "+7" "-exec" "rm" "-rf" "{}" "';'"))) | ||
| 42 | (shepherd-service | ||
| 43 | (documentation "Garbage collect downloaded files more than 1 week old for USER.") | ||
| 44 | (provision '(downloads-garbage-collector)) | ||
| 45 | ;(requirement '(root)) | ||
| 46 | (modules '((shepherd service timer))) | ||
| 47 | (start #~(make-timer-constructor | ||
| 48 | (calendar-event #:hours '(8) #:minutes '(20) | ||
| 49 | #:days-of-week '(tuesday)) | ||
| 50 | (command #$cleanup-command))) | ||
| 51 | (stop #~(make-timer-destructor)) | ||
| 52 | (actions (list (shepherd-action | ||
| 53 | (name 'trigger) | ||
| 54 | (documentation "Trigger GC in Downloads folder for USER") | ||
| 55 | (procedure #~(lambda _ | ||
| 56 | (system (string-join #$cleanup-command " "))))))))))) | ||
| 57 | |||
| 58 | (define-public downloads-garbage-collector-service-type | ||
| 59 | (service-type | ||
| 60 | (name 'downloads-garbage-collector) | ||
| 61 | (description "Given a USER, clear files older than 1 week from Downloads folder") | ||
| 62 | (extensions | ||
| 63 | (list | ||
| 64 | (service-extension home-shepherd-service-type | ||
| 65 | (compose list downloads-garbage-collector-service)))) | ||
| 66 | (default-value (downloads-garbage-collector-configuration)))) | ||
