From 1a3e63250edef398f95bbd16c6e412a85e83e36c Mon Sep 17 00:00:00 2001 From: Rutherther Date: Wed, 14 May 2025 21:44:20 +0200 Subject: [PATCH] Improve shared guix cache - Add -o nonempty option to make sure the service can run even with users that already have a cache - Rename the config with -config suffix --- modules/ruther/services/bind.scm | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/modules/ruther/services/bind.scm b/modules/ruther/services/bind.scm index 1bad1fc32245ff17ae205cc85c0918bc564c69d7..ca3cac5190df96410e069570f82fe777cb526223 100644 --- a/modules/ruther/services/bind.scm +++ b/modules/ruther/services/bind.scm @@ -13,11 +13,11 @@ user-info-user user-info-home - guix-shared-cache - guix-shared-cache-bindfs - guix-shared-cache-main-user - guix-shared-cache-shared-directory - guix-shared-cache-users + guix-shared-cache-config + guix-shared-cache-config-bindfs + guix-shared-cache-config-main-user + guix-shared-cache-config-shared-directory + guix-shared-cache-config-users guix-shared-cache-service-type)) @@ -39,7 +39,7 @@ (group "root") (home "/root")))) -(define-configuration/no-serialization guix-shared-cache +(define-configuration/no-serialization guix-shared-cache-config (bindfs (file-like bindfs) "The bindfs package to use.") (fuse (file-like fuse-2) "The fuse package to use") @@ -51,21 +51,24 @@ (define (shared-guix-cache-shepherd-services config) (map (lambda (user) - (let* ((fuse (guix-shared-cache-fuse config)) - (bindfs (guix-shared-cache-bindfs config)) + (let* ((fuse (guix-shared-cache-config-fuse config)) + (bindfs (guix-shared-cache-config-bindfs config)) (user-name (user-info-user user)) (user-home (user-info-home user)) (user-group (user-info-group user)) (user-files (user-info-files user)) - (main-group (guix-shared-cache-main-group config)) - (main-user (guix-shared-cache-main-user config)) - (shared-dir-base (guix-shared-cache-shared-directory config)) + (main-group (guix-shared-cache-config-main-group config)) + (main-user (guix-shared-cache-config-main-user config)) + (shared-dir-base (guix-shared-cache-config-shared-directory config)) (mount-dir-base (string-append user-home "/.cache/guix"))) (shepherd-service + ;; Each user has their own service (provision (list (symbol-append 'shared-guix-cache- (string->symbol user-name)))) + ;; Make sure the homes are already present (requirement '(file-systems user-homes)) (stop #~(lambda args + ;; For each mounted directory, unmount it (for-each (lambda (dir) (let ((mount-dir (string-append #$mount-dir-base "/" dir) )) @@ -76,6 +79,8 @@ '#$user-files) #f)) (start #~(lambda args + ;; Like mkdir-p, but chown all created directories + ;; by the user specified. (define (mkdir-recursively dir user group) (unless (eq? dir "/") (when (not (file-exists? dir)) @@ -87,7 +92,7 @@ (gid (passwd:gid pw))) (chown dir uid gid))))) - + ;; For each mount directory, mount it to the shared directory (for-each (lambda (dir) (let ((mount-dir (string-append #$mount-dir-base "/" dir)) @@ -100,6 +105,7 @@ (string-append "--create-for-user=" #$main-user) (string-append "--force-user=" #$user-name) (string-append "--force-group=" #$user-group) + "-o" "nonempty" shared-dir mount-dir))) '#$user-files) #t))))) @@ -116,7 +122,7 @@ (guix-shared-cache (inherit original) (users (append (guix-shared-cache-users original)))))) - (default-value (guix-shared-cache)) + (default-value (guix-shared-cache-config)) (description "Share ~/.cache/guix between multiple users. The root user is going to own the shared checkout, and will be part of the users who can use the shared checkout.