guix_mirror_bot pushed a commit to branch master
in repository guix.
commit 7b017250d937e08137dcb33dd67c97d6332534b7
Author: Sergio Pastor Pérez <[email protected]>
AuthorDate: Mon Jul 20 10:21:51 2026 +0200
gnu: linux: Use package properties to modularize initrd build.
* doc/guix.texi (operating-system Reference): Document initrd-modules
change.
(Initial RAM Disk): Inform about deprecation of '%base-initrd-modules' and
document 'base-initrd-modules'.
* gnu/packages/linux.scm (make-linux*): New argument
'produced-modules'. Handle GEXP in 'defconfig' arguments.
(virtio-modules, default-linux-libre-initrd-modules): New variable.
(make-linux-libre*): Adjust to instruct 'make-linux*' which modules a Debian
configuration will produce.
* gnu/system.scm (<operating-system>): Compute default operating systems
initrd modules with 'base-initrd-modules'.
* gnu/system/linux-initrd.scm (default-initrd-modules): Remove in favor of
'base-initrd-modules' which takes a mandatory kernel argument from which to
extract the initrd-modules from the package properties.
(base-initrd-modules): New procedure.
(%base-initrd-modules): Deprecate in favor of 'base-initrd-modules'.
---
doc/guix.texi | 19 +++++---
gnu/packages/linux.scm | 103 ++++++++++++++++++++++++++++++++++++--------
gnu/system.scm | 3 +-
gnu/system/linux-initrd.scm | 47 +++++++-------------
4 files changed, 118 insertions(+), 54 deletions(-)
diff --git a/doc/guix.texi b/doc/guix.texi
index 49ae745d83..19be19c6d2 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -19080,7 +19080,7 @@ Window}, for information on how to specify the keyboard
layout used by the X
Window System.
@end quotation
-@item @code{initrd-modules} (default: @code{%base-initrd-modules})
+@item @code{initrd-modules} (default: @code{(base-initrd-modules
(operating-system-kernel this-operating-system))})
@cindex initrd
@cindex initial RAM disk
The list of Linux kernel modules that need to be available in the
@@ -49834,16 +49834,25 @@ file system, you would write:
@lisp
(operating-system
;; @dots{}
- (initrd-modules (cons "megaraid_sas" %base-initrd-modules)))
+ (initrd-modules (cons "megaraid_sas"
+ (base-initrd-modules (operating-system-kernel
+ this-operating-system)))))
@end lisp
Other useful kernel modules include those necessary for a
@code{raid-device-mapping}, e.g. @code{raid1}, @code{raid456} and
@code{raid10} (@pxref{Mapped Devices}).
-@defvar %base-initrd-modules
-This is the list of kernel modules included in the initrd by default.
-@end defvar
+@vindex %base-initrd-modules
+@deffn {Procedure} base-initrd-modules kernel [system]
+Return a list of modules tailored to @var{kernel} for @var{system} to
+include in the initrd by default.
+@end deffn
+
+@quotation Deprecation notice
+This was formerly known as @var{%base-initrd-modules}. It is recommended
+that you switch to using @code{(base-initrd-modules linux-libre)}.
+@end quotation
Furthermore, if you need lower-level customization, the @code{initrd}
field of an @code{operating-system} declaration allows
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 6965528ab7..252328f423 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -1047,7 +1047,7 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
(and (version>=? version "5.10")
(not (version>=? version "6.2")))) ;patch applied upstream
-(define* (make-linux* version source supported-systems
+(define* (make-linux* version source supported-systems produced-modules
#:key
(extra-version #f)
;; A function that takes an arch and a variant.
@@ -1055,6 +1055,30 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
(configuration-file #f)
(defconfig "defconfig")
(extra-options (default-extra-linux-options version)))
+ "Create a Linux package from VERSION using SOURCE for SUPPORTED-SYSTEMS.
+
+Produced modules will use package-properties to convey which modules the given
+configuration produced either by CONFIGURATION-FILE or DEFCONFIG will yield.
+This allows 'operating-system' records to infer their 'intrd-modules' value
+from their 'kernel' field package.
+
+EXTRA-VERSION will control the emitted package name as well as the
+EXTRAVERSION value of the kernel build.
+
+CONFIGURATION-FILE is a file-like object which will be used as the
+configuration file to use for building the kernel. If used the DEFCONFIG
+argument will be ignored.
+
+DEFCONFIG can either be a string, which will control the make target that
+generates the configuration file used for building the kernel, or a GEXP which
+should produce the '.config' file that will be used for building the kernel.
+
+EXTRA-OPTIONS will be appended to the configuration file provided by
+CONFIGURATION-FILE or generated by DEFCONFIG. It must be an alist where each
element has the form:
+(KERNEL-OPTION . VALUE)
+
+KERNEL-OPTION must be a string and VALUE can be '#t', '#f' or 'm' for
+instructing that the configuration option should build a kernel module."
(package
(name (if extra-version
(string-append "linux-" extra-version)
@@ -1133,7 +1157,13 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
(begin
(copy-file config ".config")
(chmod ".config" #o666))
- (invoke "make" #$defconfig))
+ #$(cond
+ ((string? defconfig)
+ #~(invoke "make" #$defconfig))
+ ((promise? defconfig)
+ (force defconfig))
+ (else
+ defconfig)))
;; Appending works even when the option wasn't in the file.
;; The last one prevails if duplicated.
(let ((port (open-file ".config" "a"))
@@ -1211,7 +1241,9 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
(home-page #f)
(synopsis #f)
(description #f)
- (license #f)))
+ (license #f)
+ (properties
+ `((base-initrd-modules . ,produced-modules)))))
(define* (make-linux-libre version gnu-revision hash-string supported-systems
#:key
@@ -1240,6 +1272,39 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
#:defconfig defconfig
#:extra-options extra-options))
+(define virtio-modules
+ ;; Modules for Linux para-virtualized devices, for use in QEMU guests.
+ '("virtio_pci" "virtio_balloon" "virtio_blk" "virtio_net"
+ "virtio_console" "virtio-rng" "virtio_mmio" "virtio_scsi"))
+
+(define default-linux-libre-initrd-modules
+ ;; Default set of modules that need to be available in the initrd when
+ ;; booting Linux-libre.
+ (let* ((generic `("ahci" ;for SATA
controllers
+ "nvme" ;for NVMe
controllers
+ "usb-storage" "uas" ;for the
installation image etc.
+ "usbhid" "hid-generic" ;keyboards
during early boot
+ "mmc_block" ;for MMC block
device driver
+ "dm-crypt" "xts" "serpent_generic" "wp512" ;for encrypted
root partitions
+ "nls_iso8859-1" ;for
`mkfs.fat`, et.al
+ ,@virtio-modules))
+ (_86 (cons*
+ "hid-apple"
+ "pata_acpi" "pata_atiixp" ;for ATA controllers
+ "isci"
+ generic))
+ (others (cons*
+ "hid-apple"
+ generic)))
+ `(("x86_64-linux" . ,_86)
+ ("i686-linux" . ,_86)
+ ("armhf-linux" . ,others)
+ ("aarch64-linux" . ,others)
+ ("mips64el-linux" . ,others)
+ ("powerpc-linux" . ,others)
+ ("powerpc64le-linux" . ,others)
+ ("riscv64-linux" . ,generic))))
+
(define* (make-linux-libre* version gnu-revision source supported-systems
#:key
(extra-version #f)
@@ -1248,21 +1313,25 @@ ARCH and optionally VARIANT, or #f if there is no such
configuration."
(configuration-file #f)
(defconfig "defconfig")
(extra-options (default-extra-linux-options
version)))
- (package
- (inherit (make-linux* version source supported-systems
- #:extra-version extra-version
- #:configuration-file configuration-file
- #:defconfig defconfig
- #:extra-options extra-options))
- (name (if extra-version
- (string-append "linux-libre-" extra-version)
- "linux-libre"))
- (home-page "https://www.gnu.org/software/linux-libre/")
- (synopsis "100% free redistribution of a cleaned Linux kernel")
- (description "GNU Linux-Libre is a free (as in freedom) variant of the
+ (let ((linux (make-linux* version source supported-systems
+ default-linux-libre-initrd-modules
+ #:extra-version extra-version
+ #:configuration-file configuration-file
+ #:defconfig defconfig
+ #:extra-options extra-options)))
+ (package
+ (inherit linux)
+ (name (if extra-version
+ (string-append "linux-libre-" extra-version)
+ "linux-libre"))
+ (home-page "https://www.gnu.org/software/linux-libre/")
+ (synopsis "100% free redistribution of a cleaned Linux kernel")
+ (description "GNU Linux-Libre is a free (as in freedom) variant of the
Linux kernel. It has been modified to remove all non-free binary blobs.")
- (license license:gpl2)
- (properties %linux-libre-timeout-properties)))
+ (license license:gpl2)
+ (properties (append %linux-libre-timeout-properties
+ (package-properties linux))))))
+
;;;
diff --git a/gnu/system.scm b/gnu/system.scm
index 14b4cab4b2..bfcb4025a7 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -261,7 +261,8 @@ VERSION is the target version of the boot-parameters
record."
(default base-initrd))
(initrd-modules operating-system-initrd-modules ; list of strings
(thunked) ; it's system-dependent
- (default %base-initrd-modules))
+ (default (base-initrd-modules (operating-system-kernel
+ this-operating-system))))
(firmware operating-system-firmware ; list of packages
(default %base-firmware))
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 2977031584..b56e6cf5d4 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -21,6 +21,7 @@
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu system linux-initrd)
+ #:use-module (guix deprecation)
#:use-module (guix gexp)
#:use-module (guix utils)
#:use-module ((guix store)
@@ -28,6 +29,7 @@
#:use-module ((guix derivations)
#:select (derivation->output-path))
#:use-module (guix modules)
+ #:use-module (guix packages)
#:use-module (gnu packages compression)
#:use-module (gnu packages disk)
#:use-module (gnu packages linux)
@@ -37,6 +39,7 @@
#:select (console-setup xkeyboard-config))
#:use-module ((gnu packages make-bootstrap)
#:select (%guile-static-initrd))
+ #:use-module (gnu system)
#:use-module (gnu system file-systems)
#:use-module (gnu system mapped-devices)
#:use-module (gnu system keyboard)
@@ -46,7 +49,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:export (expression->initrd
- %base-initrd-modules
+ base-initrd-modules
raw-initrd
file-system-packages
file-system-modules
@@ -362,36 +365,18 @@ FILE-SYSTEMS."
(append-map (compose file-system-type-modules file-system-type)
file-systems))
-(define* (default-initrd-modules
- #:optional
- (system (or (%current-target-system)
- (%current-system))))
- "Return the list of modules included in the initrd by default."
- (define virtio-modules
- ;; Modules for Linux para-virtualized devices, for use in QEMU guests.
- '("virtio_pci" "virtio_balloon" "virtio_blk" "virtio_net"
- "virtio_console" "virtio-rng" "virtio_mmio" "virtio_scsi"))
-
- `("ahci" ;for SATA controllers
- "nvme" ;for NVMe controllers
- "usb-storage" "uas" ;for the installation image etc.
- "usbhid" "hid-generic" ;keyboards during early boot
- ,@(if (target-riscv64? system)
- '()
- '("hid-apple"))
- "mmc_block" ;for MMC block device driver
- "dm-crypt" "xts" "serpent_generic" "wp512" ;for encrypted root partitions
- "nls_iso8859-1" ;for `mkfs.fat`, et.al
- ,@(if (string-match "^(x86_64|i[3-6]86)-" system)
- '("pata_acpi" "pata_atiixp" ;for ATA controllers
- "isci") ;for SAS controllers like Intel C602
- '())
-
- ,@virtio-modules))
-
-(define-syntax %base-initrd-modules
- ;; This more closely matches our naming convention.
- (identifier-syntax (default-initrd-modules)))
+(define-deprecated/public-alias %base-initrd-modules
+ (base-initrd-modules linux-libre))
+
+(define* (base-initrd-modules
+ kernel
+ #:optional
+ (system (or (%current-target-system)
+ (%current-system))))
+ "Return a list of modules tailored to KERNEL for SYSTEM to include in the
+initrd by default."
+ (assoc-ref (assoc-ref (package-properties kernel) 'base-initrd-modules)
+ system))
(define* (base-initrd file-systems
#:key