system: Improve warning when using LUKS mapped devices without UUIDs.

This corrects two problems with the previous mapped devices warning:

1. It wasn't clear how to correct the situation.
2. The output would be repeated multiple times, as many times as the procedure
is called during a system reconfigure.

* gnu/system.scm (operating-system-bootloader-crypto-devices): Memoize
procedure.  Include the mapped devices source location information in the
warnings.  Add a hint to help users fix the warning.
This commit is contained in:
Maxim Cournoyer 2022-05-14 01:30:44 -04:00
parent cb38c7c169
commit 39a9404c99
No known key found for this signature in database
GPG Key ID: 1260E46482E63562
1 changed files with 24 additions and 19 deletions

View File

@ -33,6 +33,7 @@
(define-module (gnu system) (define-module (gnu system)
#:use-module (guix inferior) #:use-module (guix inferior)
#:use-module (guix store) #:use-module (guix store)
#:use-module (guix memoization)
#:use-module (guix monads) #:use-module (guix monads)
#:use-module (guix gexp) #:use-module (guix gexp)
#:use-module (guix records) #:use-module (guix records)
@ -42,6 +43,7 @@
#:use-module ((guix utils) #:select (substitute-keyword-arguments)) #:use-module ((guix utils) #:select (substitute-keyword-arguments))
#:use-module (guix i18n) #:use-module (guix i18n)
#:use-module (guix diagnostics) #:use-module (guix diagnostics)
#:use-module (guix ui)
#:use-module (gnu packages admin) #:use-module (gnu packages admin)
#:use-module (gnu packages base) #:use-module (gnu packages base)
#:use-module (gnu packages bash) #:use-module (gnu packages bash)
@ -78,11 +80,13 @@
#:use-module (gnu system uuid) #:use-module (gnu system uuid)
#:use-module (gnu system file-systems) #:use-module (gnu system file-systems)
#:use-module (gnu system mapped-devices) #:use-module (gnu system mapped-devices)
#:use-module (ice-9 format)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26) #:use-module (srfi srfi-26)
#:use-module (srfi srfi-34) #:use-module (srfi srfi-34)
#:use-module (srfi srfi-35) #:use-module (srfi srfi-35)
#:use-module (srfi srfi-71)
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:export (operating-system #:export (operating-system
operating-system? operating-system?
@ -600,25 +604,26 @@ from the initrd."
(any file-system-needed-for-boot? users))) (any file-system-needed-for-boot? users)))
devices))) devices)))
(define (operating-system-bootloader-crypto-devices os) (define operating-system-bootloader-crypto-devices
"Return the subset of mapped devices that the bootloader must open. (mlambdaq (os) ;to avoid duplicated output
Only devices specified by uuid are supported." "Return the sources of the LUKS mapped devices specified by UUID."
(define (valid-crypto-device? dev) ;; XXX: Device ordering is important, we trust the returned one.
(or (uuid? dev) (let* ((luks-devices (filter (lambda (m)
(begin (eq? luks-device-mapping
(warning (G_ "\ (mapped-device-type m)))
mapped-device '~a' may not be mounted by the bootloader.~%") (operating-system-boot-mapped-devices os)))
dev) (uuid-crypto-devices non-uuid-crypto-devices
#f))) (partition (compose uuid? mapped-device-source)
(filter-map (match-lambda luks-devices)))
((and (= mapped-device-type type) (when (not (null? non-uuid-crypto-devices))
(= mapped-device-source source)) (for-each (lambda (dev)
(and (eq? luks-device-mapping type) (warning
(valid-crypto-device? source) (source-properties->location (mapped-device-location dev))
source)) (G_ "mapped device '~a' may be ignored by bootloader~%")
(_ #f)) (mapped-device-source dev)))
;; XXX: Ordering is important, we trust the returned one. non-uuid-crypto-devices)
(operating-system-boot-mapped-devices os))) (display-hint "Specify mapped device sources via their LUKS UUID."))
(map mapped-device-source uuid-crypto-devices))))
(define (device-mapping-services os) (define (device-mapping-services os)
"Return the list of device-mapping services for OS as a list." "Return the list of device-mapping services for OS as a list."