1# Linux Kernel {#sec-kernel-config} 2 3You can override the Linux kernel and associated packages using the 4option `boot.kernelPackages`. For instance, this selects the Linux 3.10 5kernel: 6 7```nix 8{ boot.kernelPackages = pkgs.linuxKernel.packages.linux_3_10; } 9``` 10 11Note that this not only replaces the kernel, but also packages that are 12specific to the kernel version, such as the NVIDIA video drivers. This 13ensures that driver packages are consistent with the kernel. 14 15While `pkgs.linuxKernel.packages` contains all available kernel packages, 16you may want to use one of the unversioned `pkgs.linuxPackages_*` aliases 17such as `pkgs.linuxPackages_latest`, that are kept up to date with new 18versions. 19 20Please note that the current convention in NixOS is to only keep actively 21maintained kernel versions on both unstable and the currently supported stable 22release(s) of NixOS. This means that a non-longterm kernel will be removed after it's 23abandoned by the kernel developers, even on stable NixOS versions. If you 24pin your kernel onto a non-longterm version, expect your evaluation to fail as 25soon as the version is out of maintenance. 26 27A kernel will be removed from nixpkgs when the first batch of stable kernels 28_after_ the final release is published. E.g. when 6.15.11 is the final release 29of the 6.15 series and is released together with 6.16.3 and 6.12.43, it will be 30removed on the release of 6.16.4 and 6.12.44. Custom kernel variants such 31as linux-hardened are also affected by this. 32 33Longterm versions of kernels will be removed before the next stable NixOS that will 34exceed the maintenance period of the kernel version. 35 36The default Linux kernel configuration should be fine for most users. 37You can see the configuration of your current kernel with the following 38command: 39 40```ShellSession 41zcat /proc/config.gz 42``` 43 44If you want to change the kernel configuration, you can use the 45`packageOverrides` feature (see [](#sec-customising-packages)). For 46instance, to enable support for the kernel debugger KGDB: 47 48```nix 49{ 50 nixpkgs.config.packageOverrides = 51 pkgs: 52 pkgs.lib.recursiveUpdate pkgs { 53 linuxKernel.kernels.linux_5_10 = pkgs.linuxKernel.kernels.linux_5_10.override { 54 extraConfig = '' 55 KGDB y 56 ''; 57 }; 58 }; 59} 60``` 61 62`extraConfig` takes a list of Linux kernel configuration options, one 63per line. The name of the option should not include the prefix 64`CONFIG_`. The option value is typically `y`, `n` or `m` (to build 65something as a kernel module). 66 67Kernel modules for hardware devices are generally loaded automatically 68by `udev`. You can force a module to be loaded via 69[](#opt-boot.kernelModules), e.g. 70 71```nix 72{ 73 boot.kernelModules = [ 74 "fuse" 75 "kvm-intel" 76 "coretemp" 77 ]; 78} 79``` 80 81If the module is required early during the boot (e.g. to mount the root 82file system), you can use [](#opt-boot.initrd.kernelModules): 83 84```nix 85{ boot.initrd.kernelModules = [ "cifs" ]; } 86``` 87 88This causes the specified modules and their dependencies to be added to 89the initial ramdisk. 90 91Kernel runtime parameters can be set through 92[](#opt-boot.kernel.sysctl), e.g. 93 94```nix 95{ boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 120; } 96``` 97 98sets the kernel's TCP keepalive time to 120 seconds. To see the 99available parameters, run `sysctl -a`. 100 101## Building a custom kernel {#sec-linux-config-customizing} 102 103Please refer to the Nixpkgs manual for the various ways of [building a custom kernel](https://nixos.org/nixpkgs/manual#sec-linux-kernel). 104 105To use your custom kernel package in your NixOS configuration, set 106 107```nix 108{ boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel; } 109``` 110 111## Rust {#sec-linux-rust} 112 113The Linux kernel does not have Rust language support enabled by 114default. For kernel versions 6.7 or newer, experimental Rust support 115can be enabled. In a NixOS configuration, set: 116 117```nix 118{ 119 boot.kernelPatches = [ 120 { 121 name = "Rust Support"; 122 patch = null; 123 features = { 124 rust = true; 125 }; 126 } 127 ]; 128} 129``` 130 131## Developing kernel modules {#sec-linux-config-developing-modules} 132 133This section was moved to the [Nixpkgs manual](https://nixos.org/nixpkgs/manual#sec-linux-kernel-developing-modules). 134 135## ZFS {#sec-linux-zfs} 136 137It's a common issue that the latest stable version of ZFS doesn't support the latest 138available Linux kernel. It is recommended to use the latest available LTS that's compatible 139with ZFS. Usually this is the default kernel provided by nixpkgs (i.e. `pkgs.linuxPackages`).