diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2023-09-15 22:09:02 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2023-10-01 22:58:19 +0200 |
| commit | 416933cde5b4e45a0e3214f2713cfe3974b07fb8 (patch) | |
| tree | 06b1fec1c7b0b2809a0332dc6e9cbdc65be031e6 /gnu/services/virtualization.scm | |
| parent | aa40b085dc36721c00eb7fcde69c70c5d9284c1c (diff) | |
services: childhurd: Authorize the childhurd’s key on the host.
This partly automates setting up a childhurd for offloading purposes.
* gnu/services/virtualization.scm (authorize-guest-substitutes-on-host):
New procedure.
(hurd-vm-activation): Use it.
Diffstat (limited to 'gnu/services/virtualization.scm')
| -rw-r--r-- | gnu/services/virtualization.scm | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/gnu/services/virtualization.scm b/gnu/services/virtualization.scm index fd153dd0518..ca000f5d28f 100644 --- a/gnu/services/virtualization.scm +++ b/gnu/services/virtualization.scm | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #:use-module (gnu image) | 28 | #:use-module (gnu image) |
| 29 | #:use-module (gnu packages admin) | 29 | #:use-module (gnu packages admin) |
| 30 | #:use-module (gnu packages gdb) | 30 | #:use-module (gnu packages gdb) |
| 31 | #:autoload (gnu packages gnupg) (guile-gcrypt) | ||
| 31 | #:use-module (gnu packages package-management) | 32 | #:use-module (gnu packages package-management) |
| 32 | #:use-module (gnu packages ssh) | 33 | #:use-module (gnu packages ssh) |
| 33 | #:use-module (gnu packages virtualization) | 34 | #:use-module (gnu packages virtualization) |
| @@ -50,6 +51,7 @@ | |||
| 50 | #:use-module (guix records) | 51 | #:use-module (guix records) |
| 51 | #:use-module (guix store) | 52 | #:use-module (guix store) |
| 52 | #:use-module (guix utils) | 53 | #:use-module (guix utils) |
| 54 | #:autoload (guix self) (make-config.scm) | ||
| 53 | 55 | ||
| 54 | #:use-module (srfi srfi-9) | 56 | #:use-module (srfi srfi-9) |
| 55 | #:use-module (srfi srfi-26) | 57 | #:use-module (srfi srfi-26) |
| @@ -1271,6 +1273,50 @@ is added to the OS specified in CONFIG." | |||
| 1271 | 1273 | ||
| 1272 | (program-file "initialize-hurd-vm-substitutes" run)) | 1274 | (program-file "initialize-hurd-vm-substitutes" run)) |
| 1273 | 1275 | ||
| 1276 | (define (authorize-guest-substitutes-on-host) | ||
| 1277 | "Return a program that authorizes the guest's archive signing key (passed as | ||
| 1278 | an argument) on the host." | ||
| 1279 | (define not-config? | ||
| 1280 | (match-lambda | ||
| 1281 | ('(guix config) #f) | ||
| 1282 | (('guix _ ...) #t) | ||
| 1283 | (('gnu _ ...) #t) | ||
| 1284 | (_ #f))) | ||
| 1285 | |||
| 1286 | (define run | ||
| 1287 | (with-extensions (list guile-gcrypt) | ||
| 1288 | (with-imported-modules `(((guix config) => ,(make-config.scm)) | ||
| 1289 | ,@(source-module-closure | ||
| 1290 | '((guix pki) | ||
| 1291 | (guix build utils)) | ||
| 1292 | #:select? not-config?)) | ||
| 1293 | #~(begin | ||
| 1294 | (use-modules (ice-9 match) | ||
| 1295 | (ice-9 textual-ports) | ||
| 1296 | (gcrypt pk-crypto) | ||
| 1297 | (guix pki) | ||
| 1298 | (guix build utils)) | ||
| 1299 | |||
| 1300 | (match (command-line) | ||
| 1301 | ((_ guest-config-directory) | ||
| 1302 | (let ((guest-key (string-append guest-config-directory | ||
| 1303 | "/signing-key.pub"))) | ||
| 1304 | (if (file-exists? guest-key) | ||
| 1305 | ;; Add guest key to the host's ACL. | ||
| 1306 | (let* ((key (string->canonical-sexp | ||
| 1307 | (call-with-input-file guest-key | ||
| 1308 | get-string-all))) | ||
| 1309 | (acl (public-keys->acl | ||
| 1310 | (cons key (acl->public-keys (current-acl)))))) | ||
| 1311 | (with-atomic-file-replacement %acl-file | ||
| 1312 | (lambda (_ port) | ||
| 1313 | (write-acl acl port)))) | ||
| 1314 | (format (current-error-port) | ||
| 1315 | "warning: guest key missing from '~a'~%" | ||
| 1316 | guest-key))))))))) | ||
| 1317 | |||
| 1318 | (program-file "authorize-guest-substitutes-on-host" run)) | ||
| 1319 | |||
| 1274 | (define (hurd-vm-activation config) | 1320 | (define (hurd-vm-activation config) |
| 1275 | "Return a gexp to activate the Hurd VM according to CONFIG." | 1321 | "Return a gexp to activate the Hurd VM according to CONFIG." |
| 1276 | (with-imported-modules '((guix build utils)) | 1322 | (with-imported-modules '((guix build utils)) |
| @@ -1294,7 +1340,10 @@ is added to the OS specified in CONFIG." | |||
| 1294 | 1340 | ||
| 1295 | (unless (file-exists? guix-directory) | 1341 | (unless (file-exists? guix-directory) |
| 1296 | (invoke #$(initialize-hurd-vm-substitutes) | 1342 | (invoke #$(initialize-hurd-vm-substitutes) |
| 1297 | guix-directory))))) | 1343 | guix-directory)) |
| 1344 | |||
| 1345 | ;; Authorize the archive signing key from GUIX-DIRECTORY in the host. | ||
| 1346 | (invoke #$(authorize-guest-substitutes-on-host) guix-directory)))) | ||
| 1298 | 1347 | ||
| 1299 | (define hurd-vm-service-type | 1348 | (define hurd-vm-service-type |
| 1300 | (service-type | 1349 | (service-type |
