I am trying to build a lz4-compressed kernel for faster boot, at very first I did it by
boot.kernelPatches = [ {
name = "lz4 compressed";
patch = null;
extraConfig = ''
KERNEL_LZ4 y
'';
} ];
But this won’t work, as lz4
is not a default build input of the kernel. So next I tried adding:
boot.kernelPackages = with pkgs; linuxPackages_5_6 // {
kernel = linux_5_6.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [ lz4 ];
});
};
This was inspired by the make menuconfig
trick on the wiki. However the kernel still ended up failing to build because of missing lz4
(and I haven’t figured out why yet). Next, I tried replacing the above with:
boot.kernelPackages = with pkgs; recurseIntoAttrs (linuxPackagesFor (
linux_5_6.overrideAttrs (...)
));
This time, I got the error that some kernel configs essential to NixOS
, like CONFIG_DEVTMPFS
and CONFIG_CGROUPS
, are not set. I tried removing the kernel patch for extra config, and the problem remains. So it is caused by overriding the kernel’s build inputs. My explanation is that overriding build inputs changes the kernel’s derivation and somewhat makes it failed to find the correct config file in /nix/store
.
Finally, I tried overriding linux_5_6
directly in nixpkgs
, but no luck. The same “essential config not set” error remains.
Of course, manually supply a config file the same as NixOS’s defalut can solve the problem. But kernel config varies from version to version, and I favor Nix’s approach of extraConfig
a lot, as I can alter kernel config freely, without the need to scan-through all config changes on kernel update.
So my question is: how can one add build inputs to the linux kernel in NixOS, while keeps using the config generated by NixOS (perhaps with patches later), not having to manually supply a config file?
Thanks for any suggestions in advance ; )