From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 31 10:49:51 2020 Received: (at 42634) by debbugs.gnu.org; 31 Jul 2020 14:49:51 +0000 Received: from localhost ([127.0.0.1]:38412 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k1WM3-0006Lg-1g for submit@debbugs.gnu.org; Fri, 31 Jul 2020 10:49:51 -0400 Received: from mail-wr1-f43.google.com ([209.85.221.43]:36111) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k1WLx-0006L8-To for 42634@debbugs.gnu.org; Fri, 31 Jul 2020 10:49:50 -0400 Received: by mail-wr1-f43.google.com with SMTP id 88so28227266wrh.3 for <42634@debbugs.gnu.org>; Fri, 31 Jul 2020 07:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ToTsMo410aZEmHCcvhvcJh6u7fw+3mCmL20awHZ5Bwo=; b=W0XNrlAR8thNsv84IKPhHXR/CvPKsNacR6EY7FZwyNnZ9Fxp9dZko8SINd2uRh7si6 XK0AOm+ZV3ghNQieB64vDY6AV+PXB72DgLCmPjYw0fDdqk0UQvKWLY+inOXNtJwyFTUf fiic4ruwxFy/zUrvns2tAkNGWZ6HOiOwciKP7sS6H1r/iYgFWO+0ssNR5KtA4uJZNyOi qW21uhku5hiobfOzb9R2IeEK7/VxeZTVIGeMtldaeQDnFvw3uSOTJHKYpD1Z1Kw6CP3m BsLv3IJr1wMU8r3CTS1NKvmHE+ozIhyLP7qVRXsndXnscusNWbKyQKEz2vGbhYszYzXO vexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ToTsMo410aZEmHCcvhvcJh6u7fw+3mCmL20awHZ5Bwo=; b=TW2Shhy0eNgjla2YrUIbdBEaYxXWPK2nN93sTDaxhnuh5CFUkwgWLqwjH+A3YTzb1M Z8RR5z6BXYaq0QvCIIHRXZYD46wxqpro+8PRoPZvCB8SGoyYWkmHhQ/HX2gPxRNifYSR uezMEJHaT3BiDHD4BSziChrOsImh2qYcQvg9RXfZ7E/05bfZnm7j0r39AkimgoH2lEGl OHrcWb8qIZkrSnrAKoGnZERWPi3a/s+gDMnpUvnC4/eAekLXGuAEqt0ttXfp8bt3ar0C MT30VTPi2eqiCdsfWVfXQeJBxPwcnuTGhT5gMwCfMJdEsqrvicyHiwe1WWVajzmv+zLu O2sA== X-Gm-Message-State: AOAM532YeMtY8CRde3BEmy8lF9JrpaMxj1ehHuD6pz4d9J+KeLrjwCtJ 3NE67Bot6KwsvV8xD5AeVdXmkzU4 X-Google-Smtp-Source: ABdhPJwe+SzP/4berr/x+akOk2qy5lukhYsFcQj4tYH17xxAQO6Ojrl4KVgSBcpb2gOCFRa6uNgAZQ== X-Received: by 2002:a05:6000:10cd:: with SMTP id b13mr3757021wrx.216.1596206979631; Fri, 31 Jul 2020 07:49:39 -0700 (PDT) Received: from cervin.home ([2a01:cb18:832e:5f00:c08f:7d21:ea98:a1c5]) by smtp.gmail.com with ESMTPSA id n189sm12648951wmn.40.2020.07.31.07.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 07:49:39 -0700 (PDT) From: Mathieu Othacehe X-Google-Original-From: Mathieu Othacehe To: 42634@debbugs.gnu.org Subject: [PATCH 2/3] system: image: Add image-type support. Date: Fri, 31 Jul 2020 16:49:28 +0200 Message-Id: <20200731144929.703345-2-othacehe@gnu.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200731144929.703345-1-othacehe@gnu.org> References: <20200731144929.703345-1-othacehe@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 42634 Cc: Mathieu Othacehe X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) * gnu/system/image.scm (image-with-os): New macro. Rename the old "image-with-os" procedure to ... (image-with-os*): ... this new procedure, (system-image): adapt according, (raw-image-type, iso-image-type, uncompressed-iso-image-type %image-types): new variables, (lookup-image-type-by-name): new procedure. (find-image): remove it. * gnu/system/images/hurd.scm (hurd-image-type): New variable, use it to define ... (hurd-disk-image): ... this variable, using "os->image" procedure. * gnu/tests/install.scm (run-install): Rename installation-disk-image-file-system-type parameter to installation-image-type, use os->config instead of find-image to compute the image passed to system-image, (%test-iso-image-installer) adapt accordingly, (guided-installation-test): ditto. --- gnu/system/image.scm | 88 ++++++++++++++++++++++++++++++-------- gnu/system/images/hurd.scm | 13 ++++-- gnu/tests/install.scm | 46 ++++++++++---------- 3 files changed, 103 insertions(+), 44 deletions(-) diff --git a/gnu/system/image.scm b/gnu/system/image.scm index 36f56e237d..deee8a6412 100644 --- a/gnu/system/image.scm +++ b/gnu/system/image.scm @@ -18,6 +18,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu system image) + #:use-module (guix discovery) #:use-module (guix gexp) #:use-module (guix modules) #:use-module (guix monads) @@ -62,8 +63,15 @@ efi-disk-image iso9660-image - find-image - system-image)) + image-with-os + raw-image-type + iso-image-type + uncompressed-iso-image-type + + system-image + + %image-types + lookup-image-type-by-name)) ;;; @@ -110,6 +118,37 @@ (label "GUIX_IMAGE") (flags '(boot))))))) + +;;; +;;; Images types. +;;; + +(define-syntax-rule (image-with-os base-image os) + "Return an image inheriting from BASE-IMAGE, with the operating-system field +set to the given OS." + (image + (inherit base-image) + (operating-system os))) + +(define raw-image-type + (image-type + (name "raw") + (constructor (cut image-with-os efi-disk-image <>)))) + +(define iso-image-type + (image-type + (name "iso9660") + (constructor (cut image-with-os iso9660-image <>)))) + +(define uncompressed-iso-image-type + (image-type + (name "uncompressed-iso9660") + (constructor (cut image-with-os + (image + (inherit iso9660-image) + (compression? #f)) + <>)))) + ;; ;; Helpers. @@ -426,7 +465,7 @@ used in the image. " image-size) (else root-size)))) -(define* (image-with-os base-image os) +(define* (image-with-os* base-image os) "Return an image based on BASE-IMAGE but with the operating-system field set to OS. Also set the UUID and the size of the root partition." (define root-file-system @@ -507,7 +546,7 @@ image, depending on IMAGE format." (with-parameters ((%current-target-system target)) (let* ((os (operating-system-for-image image)) - (image* (image-with-os image os)) + (image* (image-with-os* image os)) (register-closures? (has-guix-service-type? os)) (bootcfg (operating-system-bootcfg os)) (bootloader (bootloader-configuration-bootloader @@ -539,18 +578,33 @@ image, depending on IMAGE format." #:grub-mkrescue-environment '(("MKRESCUE_SED_MODE" . "mbr_only")))))))) -(define (find-image file-system-type target) - "Find and return an image built that could match the given FILE-SYSTEM-TYPE, -built for TARGET. This is useful to adapt to interfaces written before the -addition of the record." - (match file-system-type - ("iso9660" iso9660-image) - (_ (cond - ((and target - (hurd-triplet? target)) - (module-ref (resolve-interface '(gnu system images hurd)) - 'hurd-disk-image)) - (else - efi-disk-image))))) + +;; +;; Image detection. +;; + +(define (image-modules) + "Return the list of image modules." + (cons (resolve-interface '(gnu system image)) + (all-modules (map (lambda (entry) + `(,entry . "gnu/system/images/")) + %load-path) + #:warn warn-about-load-error))) + +(define %image-types + ;; The list of publically-known image types. + (delay (fold-module-public-variables (lambda (obj result) + (if (image-type? obj) + (cons obj result) + result)) + '() + (image-modules)))) + +(define (lookup-image-type-by-name name) + "Return the image type called NAME." + (or (srfi-1:find (lambda (image-type) + (string=? name (image-type-name image-type))) + (force %image-types)) + (leave (G_ "~a: no such image type.~%") name))) ;;; image.scm ends here diff --git a/gnu/system/images/hurd.scm b/gnu/system/images/hurd.scm index d87640e8e3..67f657d289 100644 --- a/gnu/system/images/hurd.scm +++ b/gnu/system/images/hurd.scm @@ -29,8 +29,10 @@ #:use-module (gnu system file-systems) #:use-module (gnu system hurd) #:use-module (gnu system image) + #:use-module (srfi srfi-26) #:export (hurd-barebones-os hurd-disk-image + hurd-image-type hurd-barebones-disk-image)) (define hurd-barebones-os @@ -82,8 +84,13 @@ (flags '(boot)) (initializer hurd-initialize-root-partition)))))) +(define hurd-image-type + (image-type + (name "hurd-raw") + (constructor (cut image-with-os hurd-disk-image <>)))) + (define hurd-barebones-disk-image (image - (inherit hurd-disk-image) - (name 'hurd-barebones-disk-image) - (operating-system hurd-barebones-os))) + (inherit + (os->image hurd-barebones-os #:type hurd-image-type)) + (name 'hurd-barebones-disk-image))) diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index 9656e5f41f..0be9ee2892 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm @@ -218,7 +218,7 @@ reboot\n") #:imported-modules '((gnu services herd) (gnu installer tests) (guix combinators)))) - (installation-disk-image-file-system-type "ext4") + (installation-image-type "raw") (install-size 'guess) (target-size (* 2200 MiB))) "Run SCRIPT (a shell script following the system installation procedure) in @@ -228,10 +228,6 @@ packages defined in installation-os." (mlet* %store-monad ((_ (set-grafting #f)) (system (current-system)) - (target (current-target-system)) - (base-image -> (find-image - installation-disk-image-file-system-type - target)) ;; Since the installation system has no network access, ;; we cheat a little bit by adding TARGET to its GC @@ -239,18 +235,20 @@ packages defined in installation-os." ;; succeed. Also add guile-final, which is pulled in ;; through provenance.drv and may not always be present. (target (operating-system-derivation target-os)) + (base-image -> + (os->image + (operating-system-with-gc-roots + os (list target guile-final)) + #:type (lookup-image-type-by-name + installation-image-type))) (image -> - (system-image - (image - (inherit base-image) - (size install-size) - (operating-system - (operating-system-with-gc-roots - os (list target guile-final))) - ;; Do not compress to speed-up the tests. - (compression? #f) - ;; Don't provide substitutes; too big. - (substitutable? #f))))) + (system-image + (image + (inherit base-image) + (size install-size) + + ;; Don't provide substitutes; too big. + (substitutable? #f))))) (define install (with-imported-modules '((guix build utils) (gnu build marionette)) @@ -270,16 +268,16 @@ packages defined in installation-os." "-no-reboot" "-m" "1200" #$@(cond - ((string=? "ext4" installation-disk-image-file-system-type) + ((string=? "raw" installation-image-type) #~("-drive" ,(string-append "file=" #$image ",if=virtio,readonly"))) - ((string=? "iso9660" installation-disk-image-file-system-type) + ((string-contains installation-image-type "iso9660") #~("-cdrom" #$image)) (else (error - "unsupported installation-disk-image-file-system-type:" - installation-disk-image-file-system-type))) + "unsupported installation-image-type:" + installation-image-type))) "-drive" ,(string-append "file=" #$output ",if=virtio") ,@(if (file-exists? "/dev/kvm") @@ -443,8 +441,8 @@ reboot\n") %minimal-os-on-vda-source #:script %simple-installation-script-for-/dev/vda - #:installation-disk-image-file-system-type - "iso9660")) + #:installation-image-type + "uncompressed-iso9660")) (command (qemu-command/writable-image image))) (run-basic-test %minimal-os-on-vda command name))))) @@ -1309,8 +1307,8 @@ build (current-guix) and then store a couple of full system images.") #:os installation-os-for-gui-tests #:install-size install-size #:target-size target-size - #:installation-disk-image-file-system-type - "iso9660" + #:installation-image-type + "uncompressed-iso9660" #:gui-test (lambda (marionette) (gui-test-program -- 2.26.2