summary refs log tree commit diff
path: root/host/initramfs
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-05-10 08:06:48 +0000
committerAlyssa Ross <hi@alyssa.is>2022-05-10 08:06:48 +0000
commita338234170db808b054bb4a12c668af44eeb7259 (patch)
tree25f79c3b7b698957d8a6c3695abe87b457ac96b7 /host/initramfs
parent194c2b5ffbaccb571a06710b415c71523c095bb8 (diff)
downloadspectrum-a338234170db808b054bb4a12c668af44eeb7259.tar
spectrum-a338234170db808b054bb4a12c668af44eeb7259.tar.gz
spectrum-a338234170db808b054bb4a12c668af44eeb7259.tar.bz2
spectrum-a338234170db808b054bb4a12c668af44eeb7259.tar.lz
spectrum-a338234170db808b054bb4a12c668af44eeb7259.tar.xz
spectrum-a338234170db808b054bb4a12c668af44eeb7259.tar.zst
spectrum-a338234170db808b054bb4a12c668af44eeb7259.zip
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.
Diffstat (limited to 'host/initramfs')
-rw-r--r--host/initramfs/default.nix17
1 files changed, 14 insertions, 3 deletions
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