summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergio Pastor Pérez <sergio.pastor-perez@inria.fr>2026-07-20 10:21:51 +0200
committerVagrant Cascadian <vagrant@debian.org>2026-08-27 00:05:04 -0700
commit7b017250d937e08137dcb33dd67c97d6332534b7 (patch)
treeda5164c56a7697f40219dba65b52d5f9346d54c7
parent38a7797012907bc8e0ec5f6d4e76aede9666e38a (diff)
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'.
-rw-r--r--doc/guix.texi19
-rw-r--r--gnu/packages/linux.scm103
-rw-r--r--gnu/system.scm3
-rw-r--r--gnu/system/linux-initrd.scm47
4 files changed, 118 insertions, 54 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index 49ae745d83e..19be19c6d20 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
19080Window System. 19080Window System.
19081@end quotation 19081@end quotation
19082 19082
19083@item @code{initrd-modules} (default: @code{%base-initrd-modules}) 19083@item @code{initrd-modules} (default: @code{(base-initrd-modules (operating-system-kernel this-operating-system))})
19084@cindex initrd 19084@cindex initrd
19085@cindex initial RAM disk 19085@cindex initial RAM disk
19086The list of Linux kernel modules that need to be available in the 19086The list of Linux kernel modules that need to be available in the
@@ -49834,16 +49834,25 @@ file system, you would write:
49834@lisp 49834@lisp
49835(operating-system 49835(operating-system
49836 ;; @dots{} 49836 ;; @dots{}
49837 (initrd-modules (cons "megaraid_sas" %base-initrd-modules))) 49837 (initrd-modules (cons "megaraid_sas"
49838 (base-initrd-modules (operating-system-kernel
49839 this-operating-system)))))
49838@end lisp 49840@end lisp
49839 49841
49840Other useful kernel modules include those necessary for a 49842Other useful kernel modules include those necessary for a
49841@code{raid-device-mapping}, e.g. @code{raid1}, @code{raid456} and 49843@code{raid-device-mapping}, e.g. @code{raid1}, @code{raid456} and
49842@code{raid10} (@pxref{Mapped Devices}). 49844@code{raid10} (@pxref{Mapped Devices}).
49843 49845
49844@defvar %base-initrd-modules 49846@vindex %base-initrd-modules
49845This is the list of kernel modules included in the initrd by default. 49847@deffn {Procedure} base-initrd-modules kernel [system]
49846@end defvar 49848Return a list of modules tailored to @var{kernel} for @var{system} to
49849include in the initrd by default.
49850@end deffn
49851
49852@quotation Deprecation notice
49853This was formerly known as @var{%base-initrd-modules}. It is recommended
49854that you switch to using @code{(base-initrd-modules linux-libre)}.
49855@end quotation
49847 49856
49848Furthermore, if you need lower-level customization, the @code{initrd} 49857Furthermore, if you need lower-level customization, the @code{initrd}
49849field of an @code{operating-system} declaration allows 49858field of an @code{operating-system} declaration allows
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index 6965528ab7a..252328f4230 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."
1047 (and (version>=? version "5.10") 1047 (and (version>=? version "5.10")
1048 (not (version>=? version "6.2")))) ;patch applied upstream 1048 (not (version>=? version "6.2")))) ;patch applied upstream
1049 1049
1050(define* (make-linux* version source supported-systems 1050(define* (make-linux* version source supported-systems produced-modules
1051 #:key 1051 #:key
1052 (extra-version #f) 1052 (extra-version #f)
1053 ;; A function that takes an arch and a variant. 1053 ;; 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."
1055 (configuration-file #f) 1055 (configuration-file #f)
1056 (defconfig "defconfig") 1056 (defconfig "defconfig")
1057 (extra-options (default-extra-linux-options version))) 1057 (extra-options (default-extra-linux-options version)))
1058 "Create a Linux package from VERSION using SOURCE for SUPPORTED-SYSTEMS.
1059
1060Produced modules will use package-properties to convey which modules the given
1061configuration produced either by CONFIGURATION-FILE or DEFCONFIG will yield.
1062This allows 'operating-system' records to infer their 'intrd-modules' value
1063from their 'kernel' field package.
1064
1065EXTRA-VERSION will control the emitted package name as well as the
1066EXTRAVERSION value of the kernel build.
1067
1068CONFIGURATION-FILE is a file-like object which will be used as the
1069configuration file to use for building the kernel. If used the DEFCONFIG
1070argument will be ignored.
1071
1072DEFCONFIG can either be a string, which will control the make target that
1073generates the configuration file used for building the kernel, or a GEXP which
1074should produce the '.config' file that will be used for building the kernel.
1075
1076EXTRA-OPTIONS will be appended to the configuration file provided by
1077CONFIGURATION-FILE or generated by DEFCONFIG. It must be an alist where each element has the form:
1078(KERNEL-OPTION . VALUE)
1079
1080KERNEL-OPTION must be a string and VALUE can be '#t', '#f' or 'm' for
1081instructing that the configuration option should build a kernel module."
1058 (package 1082 (package
1059 (name (if extra-version 1083 (name (if extra-version
1060 (string-append "linux-" extra-version) 1084 (string-append "linux-" extra-version)
@@ -1133,7 +1157,13 @@ ARCH and optionally VARIANT, or #f if there is no such configuration."
1133 (begin 1157 (begin
1134 (copy-file config ".config") 1158 (copy-file config ".config")
1135 (chmod ".config" #o666)) 1159 (chmod ".config" #o666))
1136 (invoke "make" #$defconfig)) 1160 #$(cond
1161 ((string? defconfig)
1162 #~(invoke "make" #$defconfig))
1163 ((promise? defconfig)
1164 (force defconfig))
1165 (else
1166 defconfig)))
1137 ;; Appending works even when the option wasn't in the file. 1167 ;; Appending works even when the option wasn't in the file.
1138 ;; The last one prevails if duplicated. 1168 ;; The last one prevails if duplicated.
1139 (let ((port (open-file ".config" "a")) 1169 (let ((port (open-file ".config" "a"))
@@ -1211,7 +1241,9 @@ ARCH and optionally VARIANT, or #f if there is no such configuration."
1211 (home-page #f) 1241 (home-page #f)
1212 (synopsis #f) 1242 (synopsis #f)
1213 (description #f) 1243 (description #f)
1214 (license #f))) 1244 (license #f)
1245 (properties
1246 `((base-initrd-modules . ,produced-modules)))))
1215 1247
1216(define* (make-linux-libre version gnu-revision hash-string supported-systems 1248(define* (make-linux-libre version gnu-revision hash-string supported-systems
1217 #:key 1249 #:key
@@ -1240,6 +1272,39 @@ ARCH and optionally VARIANT, or #f if there is no such configuration."
1240 #:defconfig defconfig 1272 #:defconfig defconfig
1241 #:extra-options extra-options)) 1273 #:extra-options extra-options))
1242 1274
1275(define virtio-modules
1276 ;; Modules for Linux para-virtualized devices, for use in QEMU guests.
1277 '("virtio_pci" "virtio_balloon" "virtio_blk" "virtio_net"
1278 "virtio_console" "virtio-rng" "virtio_mmio" "virtio_scsi"))
1279
1280(define default-linux-libre-initrd-modules
1281 ;; Default set of modules that need to be available in the initrd when
1282 ;; booting Linux-libre.
1283 (let* ((generic `("ahci" ;for SATA controllers
1284 "nvme" ;for NVMe controllers
1285 "usb-storage" "uas" ;for the installation image etc.
1286 "usbhid" "hid-generic" ;keyboards during early boot
1287 "mmc_block" ;for MMC block device driver
1288 "dm-crypt" "xts" "serpent_generic" "wp512" ;for encrypted root partitions
1289 "nls_iso8859-1" ;for `mkfs.fat`, et.al
1290 ,@virtio-modules))
1291 (_86 (cons*
1292 "hid-apple"
1293 "pata_acpi" "pata_atiixp" ;for ATA controllers
1294 "isci"
1295 generic))
1296 (others (cons*
1297 "hid-apple"
1298 generic)))
1299 `(("x86_64-linux" . ,_86)
1300 ("i686-linux" . ,_86)
1301 ("armhf-linux" . ,others)
1302 ("aarch64-linux" . ,others)
1303 ("mips64el-linux" . ,others)
1304 ("powerpc-linux" . ,others)
1305 ("powerpc64le-linux" . ,others)
1306 ("riscv64-linux" . ,generic))))
1307
1243(define* (make-linux-libre* version gnu-revision source supported-systems 1308(define* (make-linux-libre* version gnu-revision source supported-systems
1244 #:key 1309 #:key
1245 (extra-version #f) 1310 (extra-version #f)
@@ -1248,21 +1313,25 @@ ARCH and optionally VARIANT, or #f if there is no such configuration."
1248 (configuration-file #f) 1313 (configuration-file #f)
1249 (defconfig "defconfig") 1314 (defconfig "defconfig")
1250 (extra-options (default-extra-linux-options version))) 1315 (extra-options (default-extra-linux-options version)))
1251 (package 1316 (let ((linux (make-linux* version source supported-systems
1252 (inherit (make-linux* version source supported-systems 1317 default-linux-libre-initrd-modules
1253 #:extra-version extra-version 1318 #:extra-version extra-version
1254 #:configuration-file configuration-file 1319 #:configuration-file configuration-file
1255 #:defconfig defconfig 1320 #:defconfig defconfig
1256 #:extra-options extra-options)) 1321 #:extra-options extra-options)))
1257 (name (if extra-version 1322 (package
1258 (string-append "linux-libre-" extra-version) 1323 (inherit linux)
1259 "linux-libre")) 1324 (name (if extra-version
1260 (home-page "https://www.gnu.org/software/linux-libre/") 1325 (string-append "linux-libre-" extra-version)
1261 (synopsis "100% free redistribution of a cleaned Linux kernel") 1326 "linux-libre"))
1262 (description "GNU Linux-Libre is a free (as in freedom) variant of the 1327 (home-page "https://www.gnu.org/software/linux-libre/")
1328 (synopsis "100% free redistribution of a cleaned Linux kernel")
1329 (description "GNU Linux-Libre is a free (as in freedom) variant of the
1263Linux kernel. It has been modified to remove all non-free binary blobs.") 1330Linux kernel. It has been modified to remove all non-free binary blobs.")
1264 (license license:gpl2) 1331 (license license:gpl2)
1265 (properties %linux-libre-timeout-properties))) 1332 (properties (append %linux-libre-timeout-properties
1333 (package-properties linux))))))
1334
1266 1335
1267 1336
1268;;; 1337;;;
diff --git a/gnu/system.scm b/gnu/system.scm
index 14b4cab4b22..bfcb4025a75 100644
--- a/gnu/system.scm
+++ b/gnu/system.scm
@@ -261,7 +261,8 @@ VERSION is the target version of the boot-parameters record."
261 (default base-initrd)) 261 (default base-initrd))
262 (initrd-modules operating-system-initrd-modules ; list of strings 262 (initrd-modules operating-system-initrd-modules ; list of strings
263 (thunked) ; it's system-dependent 263 (thunked) ; it's system-dependent
264 (default %base-initrd-modules)) 264 (default (base-initrd-modules (operating-system-kernel
265 this-operating-system))))
265 266
266 (firmware operating-system-firmware ; list of packages 267 (firmware operating-system-firmware ; list of packages
267 (default %base-firmware)) 268 (default %base-firmware))
diff --git a/gnu/system/linux-initrd.scm b/gnu/system/linux-initrd.scm
index 29770315847..b56e6cf5d42 100644
--- a/gnu/system/linux-initrd.scm
+++ b/gnu/system/linux-initrd.scm
@@ -21,6 +21,7 @@
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. 21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22 22
23(define-module (gnu system linux-initrd) 23(define-module (gnu system linux-initrd)
24 #:use-module (guix deprecation)
24 #:use-module (guix gexp) 25 #:use-module (guix gexp)
25 #:use-module (guix utils) 26 #:use-module (guix utils)
26 #:use-module ((guix store) 27 #:use-module ((guix store)
@@ -28,6 +29,7 @@
28 #:use-module ((guix derivations) 29 #:use-module ((guix derivations)
29 #:select (derivation->output-path)) 30 #:select (derivation->output-path))
30 #:use-module (guix modules) 31 #:use-module (guix modules)
32 #:use-module (guix packages)
31 #:use-module (gnu packages compression) 33 #:use-module (gnu packages compression)
32 #:use-module (gnu packages disk) 34 #:use-module (gnu packages disk)
33 #:use-module (gnu packages linux) 35 #:use-module (gnu packages linux)
@@ -37,6 +39,7 @@
37 #:select (console-setup xkeyboard-config)) 39 #:select (console-setup xkeyboard-config))
38 #:use-module ((gnu packages make-bootstrap) 40 #:use-module ((gnu packages make-bootstrap)
39 #:select (%guile-static-initrd)) 41 #:select (%guile-static-initrd))
42 #:use-module (gnu system)
40 #:use-module (gnu system file-systems) 43 #:use-module (gnu system file-systems)
41 #:use-module (gnu system mapped-devices) 44 #:use-module (gnu system mapped-devices)
42 #:use-module (gnu system keyboard) 45 #:use-module (gnu system keyboard)
@@ -46,7 +49,7 @@
46 #:use-module (srfi srfi-1) 49 #:use-module (srfi srfi-1)
47 #:use-module (srfi srfi-26) 50 #:use-module (srfi srfi-26)
48 #:export (expression->initrd 51 #:export (expression->initrd
49 %base-initrd-modules 52 base-initrd-modules
50 raw-initrd 53 raw-initrd
51 file-system-packages 54 file-system-packages
52 file-system-modules 55 file-system-modules
@@ -362,36 +365,18 @@ FILE-SYSTEMS."
362 (append-map (compose file-system-type-modules file-system-type) 365 (append-map (compose file-system-type-modules file-system-type)
363 file-systems)) 366 file-systems))
364 367
365(define* (default-initrd-modules 368(define-deprecated/public-alias %base-initrd-modules
366 #:optional 369 (base-initrd-modules linux-libre))
367 (system (or (%current-target-system) 370
368 (%current-system)))) 371(define* (base-initrd-modules
369 "Return the list of modules included in the initrd by default." 372 kernel
370 (define virtio-modules 373 #:optional
371 ;; Modules for Linux para-virtualized devices, for use in QEMU guests. 374 (system (or (%current-target-system)
372 '("virtio_pci" "virtio_balloon" "virtio_blk" "virtio_net" 375 (%current-system))))
373 "virtio_console" "virtio-rng" "virtio_mmio" "virtio_scsi")) 376 "Return a list of modules tailored to KERNEL for SYSTEM to include in the
374 377initrd by default."
375 `("ahci" ;for SATA controllers 378 (assoc-ref (assoc-ref (package-properties kernel) 'base-initrd-modules)
376 "nvme" ;for NVMe controllers 379 system))
377 "usb-storage" "uas" ;for the installation image etc.
378 "usbhid" "hid-generic" ;keyboards during early boot
379 ,@(if (target-riscv64? system)
380 '()
381 '("hid-apple"))
382 "mmc_block" ;for MMC block device driver
383 "dm-crypt" "xts" "serpent_generic" "wp512" ;for encrypted root partitions
384 "nls_iso8859-1" ;for `mkfs.fat`, et.al
385 ,@(if (string-match "^(x86_64|i[3-6]86)-" system)
386 '("pata_acpi" "pata_atiixp" ;for ATA controllers
387 "isci") ;for SAS controllers like Intel C602
388 '())
389
390 ,@virtio-modules))
391
392(define-syntax %base-initrd-modules
393 ;; This more closely matches our naming convention.
394 (identifier-syntax (default-initrd-modules)))
395 380
396(define* (base-initrd file-systems 381(define* (base-initrd file-systems
397 #:key 382 #:key