From a338234170db808b054bb4a12c668af44eeb7259 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Tue, 10 May 2022 08:06:48 +0000 Subject: host/initramfs: use module list from NixOS This means we don't have to include every kernel module in the initramfs (making it huge), while we still don't have to maintain our own list of which ones are required. The "all-hardware" NixOS profile is designed for the NixOS installer to be able to boot on as many systems as possible, which matches pretty well what we need for the generic Spectrum image. The makeModulesClosure function from Nixpkgs would also handle installing firmware in the initramfs, if any of the modules we were installing required firmware. An important reason to change this (apart from the 92% size reduction and the corresponding reduction in boot time) is that, by making every module available in the initramfs, without including any firmware, modules that required firmware would be loaded before the firmware they needed was available. When the root filesystem became available, even if it had the firmware on it, it would be too late. --- host/initramfs/default.nix | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'host/initramfs') diff --git a/host/initramfs/default.nix b/host/initramfs/default.nix index 5ce198a..f22f9c8 100644 --- a/host/initramfs/default.nix +++ b/host/initramfs/default.nix @@ -6,8 +6,8 @@ }: pkgs.callPackage ( -{ lib, stdenv, runCommand, writeReferencesToFile, pkgsStatic -, busybox, cpio, cryptsetup, lvm2 +{ lib, stdenv, makeModulesClosure, nixos, runCommand, writeReferencesToFile +, pkgsStatic, busybox, cpio, cryptsetup, linux-firmware, lvm2 }: let @@ -15,6 +15,17 @@ let linux = rootfs.kernel; + nixosAllHardware = nixos ({ modulesPath, ... }: { + imports = [ (modulesPath + "/profiles/all-hardware.nix") ]; + }); + + modules = makeModulesClosure { + inherit (rootfs) kernel; + firmware = linux-firmware; + rootModules = with nixosAllHardware.config.boot.initrd; + availableKernelModules ++ kernelModules ++ [ "dm-verity" "loop" ]; + }; + packages = [ pkgsStatic.execline pkgsStatic.kmod pkgsStatic.mdevd @@ -43,7 +54,7 @@ let packagesSysroot = runCommand "packages-sysroot" {} '' mkdir -p $out/bin ln -s ${concatMapStringsSep " " (p: "${p}/bin/*") packages} $out/bin - cp -R ${linux}/lib $out + cp -R ${modules}/lib $out ln -s /bin $out/sbin # TODO: this is a hack and we should just build the util-linux -- cgit 1.4.1