Linux kernel: Difference between revisions
fix: example |
Copy edit |
||
Line 3: | Line 3: | ||
== Configuration == | == Configuration == | ||
You can | You can change the installed kernel using {{nixos:option|boot.kernelPackages}}. To use the latest release: | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
{ | |||
boot.kernelPackages = pkgs.linuxPackages_latest; | boot.kernelPackages = pkgs.linuxPackages_latest; | ||
</ | } | ||
</nowiki>}} | |||
Then rebuild your system and reboot to use your new kernel: | |||
<syntaxHighlight lang="console"> | <syntaxHighlight lang="console"> | ||
$ sudo nixos-rebuild boot | $ sudo nixos-rebuild boot | ||
Line 17: | Line 19: | ||
=== List available kernels === | === List available kernels === | ||
You can list available kernels using <code>nix repl</code> (previously <code>nix-repl</code>) by typing the package name and using the tab completion: | You can list available kernels using <code>nix repl</code> (previously <code>nix-repl</code>) by typing the package name and using the tab completion: | ||
<syntaxHighlight lang="console"> | <syntaxHighlight lang="console"> | ||
$ nix repl | $ nix repl | ||
Line 51: | Line 53: | ||
Note that if you deviate from the default kernel version, you should also take extra care that extra kernel modules must match the same version. The safest way to do this is to use <code>config.boot.kernelPackages</code> to select the correct module set: | Note that if you deviate from the default kernel version, you should also take extra care that extra kernel modules must match the same version. The safest way to do this is to use <code>config.boot.kernelPackages</code> to select the correct module set: | ||
< | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ config, ... }: | { config, ... }: | ||
{ | { | ||
boot.extraModulePackages = with config.boot.kernelPackages; [ bbswitch ]; | boot.extraModulePackages = with config.boot.kernelPackages; [ bbswitch ]; | ||
} | } | ||
</ | </nowiki>}} | ||
=== Customizing kernel module parameters === | === Customizing kernel module parameters === | ||
You can use | You can use {{nixos:option|boot.extraModprobeConfig}}, which is analogous to creating modprobe.conf files in /etc/modprobe.d/ in regular Linux distributions. This can be used for both built-in and loadable kernel modules. | ||
< | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | |||
boot.extraModprobeConfig = '' | { | ||
boot.extraModprobeConfig = '' | |||
# example settings | |||
options yourmodulename optionA=valueA optionB=valueB # syntax | |||
options thinkpad_acpi fan_control=1 # example #1 kernel module parameter | |||
''; | options usbcore blinkenlights=1 # example #2 kernel module parameter | ||
</ | ''; | ||
} | |||
</nowiki>}} | |||
{{nixos:option|boot.kernelParams}} can be used to set additional kernel command line arguments at boot time. It can only be used for built-in modules. For example: | |||
< | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { | ||
boot.kernelParams = [ | boot.kernelParams = [ | ||
"quiet" | "quiet" | ||
"splash" | "splash" | ||
"usbcore.blinkenlights=1" | "usbcore.blinkenlights=1" | ||
]; | ]; | ||
} | } | ||
</ | </nowiki>}} | ||
=== Custom configuration === | === Custom configuration === | ||
It is sometimes desirable to change the configuration of your kernel, while keeping the kernel version itself managed through Nixpkgs | It is sometimes desirable to change the configuration of your kernel, while keeping the kernel version itself managed through Nixpkgs. | ||
One way is to use {{nixos:option|boot.kernelPatches}}<ref>[https://logs.nix.samueldr.com/nixos/2018-05-09#1525898458-1525898534; #nixos 2018-05-09]</ref><ref>[https://github.com/NixOS/nixpkgs/blob/03d4694e6110fa9c16e88ee74085ea2068c27494/nixos/modules/misc/crashdump.nix#L63-L73 <tt>nixos/modules/misc/crashdump.nix#L63-L73</tt>]</ref>. For example, {{nixos:option|boot.crashDump.enable}} is configured as shown below. Note that the {{ic|CONFIG_}} prefix is not used in the configuration names. | |||
<syntaxhighlight lang=nix> | <syntaxhighlight lang=nix> | ||
Line 107: | Line 109: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Another way | Another way is to create a overlay to configure either {{ic|extraConfig}} or {{ic|structuredExtraConfig}}. This allows for more flexibility, since you can basically override any available kernel option<ref>[https://github.com/NixOS/nixpkgs/blob/e6db435973160591fe7348876a5567c729495175/pkgs/os-specific/linux/kernel/generic.nix#L11-L56<tt>pkgs/os-specific/linux/kernel/generic.nix#L11-L56</tt>]</ref>. Using {{ic|structuredExtraConfig}} is recommended as it checks if the configured option are correct. You may also want to set {{ic|ignoreConfigErrors}} to avoid {{ic|error: unused option}} during builds. | ||
< | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { | ||
nixpkgs = { | nixpkgs = { | ||
Line 124: | Line 126: | ||
}; | }; | ||
} | } | ||
</ | </nowiki>}} | ||
=== Pinning a kernel version === | === Pinning a kernel version === | ||
< | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_4_19.override { | { | ||
boot.kernelPackages = pkgs.linuxPackagesFor (pkgs.linux_4_19.override { | |||
argsOverride = rec { | argsOverride = rec { | ||
src = pkgs.fetchurl { | src = pkgs.fetchurl { | ||
Line 139: | Line 142: | ||
}; | }; | ||
}); | }); | ||
</ | } | ||
</nowiki>}} | |||
=== Debugging a failed configuration === | === Debugging a failed configuration === | ||
As dependencies between kernel configurations | As dependencies between kernel configurations need to be addressed manually, use [https://nixos.org/manual/nix/stable/command-ref/nix-build#opt-keep-failed --keep-failed] to inspect the intermediate nix config file after any build failures: | ||
{{bc|note: keeping build directory '/tmp/nix-build-linux-config-4.19.0-mptcp_v0.94.1.drv-0'}} | {{bc|note: keeping build directory '/tmp/nix-build-linux-config-4.19.0-mptcp_v0.94.1.drv-0'}} | ||
== Embedded Linux Cross-compile xconfig and menuconfig == | == Embedded Linux Cross-compile xconfig and menuconfig == | ||
This section details the on how to get an environment that can be used to configure and cross-compile the kernel for embedded Linux development. The kernel source won't come from nix unpack phase but rather gotten externally(such as from the chip vendor github). So first clone the kernel source, then use the shell.nix below to set up the dev environment(example below is for aarch64): | This section details the on how to get an environment that can be used to configure and cross-compile the kernel for embedded Linux development. The kernel source won't come from nix unpack phase but rather gotten externally(such as from the chip vendor github). So first clone the kernel source, then use the shell.nix below to set up the dev environment(example below is for aarch64): | ||