summaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorEdouard Klein <edk@beaver-labs.com>2025-07-25 11:01:50 +0200
committerMaxim Cournoyer <maxim@guixotic.coop>2025-07-25 23:36:10 +0900
commitb740fe801e072094c6262ed71a30a0d953b0886b (patch)
tree8c9ba85860d6c5db94c36a58e2ca2ed01aa2ceb4 /gnu/services
parentf05f8fb6b4e6982cd12db4c943deae95e5692924 (diff)
services: Add shared-cache-service-type.
* gnu/services/guix.scm (shared-cache-service-type) (shared-cache-configuration, user-cache): New variables. * doc/guix.texi (Shared Cache Service): New subsubsection under "Guix Services". Change-Id: I73a8db228d9a892c8bb93c6cdfef12d0d06e25a6 Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop> Modified-by: Maxim Cournoyer <maxim@guixotic.coop>
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/guix.scm87
1 files changed, 86 insertions, 1 deletions
diff --git a/gnu/services/guix.scm b/gnu/services/guix.scm
index 8f6b6652ef1..cb8f6ef4f7b 100644
--- a/gnu/services/guix.scm
+++ b/gnu/services/guix.scm
@@ -1,6 +1,8 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@cbaines.net> 2;;; Copyright © 2019, 2020, 2021, 2022 Christopher Baines <mail@cbaines.net>
3;;; Copyright © 2024 Andrew Tropin <andrew@trop.in> 3;;; Copyright © 2024 Andrew Tropin <andrew@trop.in>
4;;; Copyright © 2025 Edouard Klein <edk@beaver-labs.com>
5;;; Copyright © 2025 Rutherther <rutherther@digital.xyz>
4;;; 6;;;
5;;; This file is part of GNU Guix. 7;;; This file is part of GNU Guix.
6;;; 8;;;
@@ -31,11 +33,15 @@
31 #:use-module (gnu packages guile) 33 #:use-module (gnu packages guile)
32 #:use-module (gnu packages guile-xyz) 34 #:use-module (gnu packages guile-xyz)
33 #:use-module (gnu packages package-management) 35 #:use-module (gnu packages package-management)
36 #:use-module (gnu packages file-systems)
37 #:use-module (gnu packages linux)
34 #:use-module (gnu services) 38 #:use-module (gnu services)
35 #:use-module (gnu services base) 39 #:use-module (gnu services base)
36 #:use-module (gnu services admin) 40 #:use-module (gnu services admin)
41 #:use-module (gnu services configuration)
37 #:use-module (gnu services shepherd) 42 #:use-module (gnu services shepherd)
38 #:use-module (gnu services getmail) 43 #:use-module (gnu services getmail)
44 #:use-module (gnu services linux)
39 #:use-module (gnu system shadow) 45 #:use-module (gnu system shadow)
40 #:export (guix-build-coordinator-configuration 46 #:export (guix-build-coordinator-configuration
41 guix-build-coordinator-configuration? 47 guix-build-coordinator-configuration?
@@ -145,7 +151,11 @@
145 bffe-configuration-arguments 151 bffe-configuration-arguments
146 bffe-configuration-extra-environment-variables 152 bffe-configuration-extra-environment-variables
147 153
148 bffe-service-type)) 154 bffe-service-type
155
156 shared-cache-service-type
157 shared-cache-configuration
158 user-cache))
149 159
150;;;; Commentary: 160;;;; Commentary:
151;;; 161;;;
@@ -1181,3 +1191,78 @@ ca-certificates.crt file in the system profile."
1181 bffe-account))) 1191 bffe-account)))
1182 (description 1192 (description
1183 "Run the Build Farm Front-end."))) 1193 "Run the Build Farm Front-end.")))
1194
1195;;;
1196;;; Share .cache/ content between users
1197;;;
1198;;; On a system with multiple users, each $HOME/.cache/guix is
1199;;; ~700MB of data that is mostly the same between users. This service allows
1200;;; one to either:
1201;;
1202;;; - share this cache between users, with updates shared between users, which
1203;;; is suitable for a high trust environment, typically a single human user
1204;;; with multiple accounts on the same computer
1205;;;
1206;;; - or expose a single user's cache, read-only with a write overlay, to the
1207;;; other users, typically used in low-trust environments such as a public
1208;;; access guix system.
1209
1210(define-record-type* <user-cache>
1211 user-cache make-user-cache
1212 user-cache?
1213 (user user-cache-user)
1214 (location user-cache-location (default (string-append "/home/" (user-cache-user this-record) "/.cache")) (thunked))
1215 (group user-cache-group (default "users"))
1216 (directories user-cache-directories (default '("guix/checkouts"))))
1217
1218(define list-of-user-cache? (list-of user-cache?))
1219
1220(define (mount-type? x)
1221 (and (symbol? x)
1222 (or (eq? x 'share)
1223 (eq? x 'expose))))
1224
1225(define-configuration/no-serialization shared-cache-configuration
1226 (mode (mount-type 'expose) "Either 'share (read-write, dangerous) or 'expose (read-only, the default) the cache directory.")
1227 (shared-directory (string "/root/.cache") "The sharing user's cache directory (i.e. the source).")
1228 (users (list-of-user-cache '()) "The users that benefit from the shared directory. This is a list of user-cache records (i.e. the destinations)."))
1229
1230(define shared-cache-vfs-mappings
1231 (match-record-lambda <shared-cache-configuration>
1232 (mode shared-directory users)
1233 (apply
1234 append
1235 (map
1236 (match-record-lambda <user-cache>
1237 (location user group directories)
1238 (map
1239 (lambda (subdir)
1240 (vfs-mapping
1241 ;; Each subdir has its own service
1242 (name (string-append "shared-cache-" subdir "-" user))
1243 ;; Make sure the homes are already present
1244 (requirement '(file-systems user-homes))
1245 ;; Mount each shared dir over the target dir in the users' .cache/
1246 (source (string-append shared-directory "/" subdir))
1247 (destination (string-append location "/" subdir))
1248 (policy (match mode
1249 ('expose 'overlay)
1250 ('share 'translate)))
1251 (user user)
1252 (group group)))
1253 directories))
1254 users))))
1255
1256(define shared-cache-service-type
1257 (service-type
1258 (name 'shared-cache)
1259 (extensions (list
1260 (service-extension vfs-mapping-service-type
1261 shared-cache-vfs-mappings)))
1262 (compose concatenate)
1263 (extend (lambda (original extensions)
1264 (shared-cache-configuration
1265 (inherit original)
1266 (users (append (shared-cache-configuration-users original) extensions)))))
1267 (default-value (shared-cache-configuration))
1268 (description "Share or expose ~/.cache/ sub directories between multiple users.")))