diff options
author | Alyssa Ross <hi@alyssa.is> | 2022-05-10 08:06:48 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2022-05-10 08:06:48 +0000 |
commit | a338234170db808b054bb4a12c668af44eeb7259 (patch) | |
tree | 25f79c3b7b698957d8a6c3695abe87b457ac96b7 | |
parent | 194c2b5ffbaccb571a06710b415c71523c095bb8 (diff) | |
download | spectrum-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.
-rw-r--r-- | host/initramfs/default.nix | 17 |
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 |