at 17.09-beta 3.2 kB view raw
1<chapter xmlns="http://docbook.org/ns/docbook" 2 xmlns:xlink="http://www.w3.org/1999/xlink" 3 xmlns:xi="http://www.w3.org/2001/XInclude" 4 version="5.0" 5 xml:id="sec-kernel-config"> 6 7<title>Linux Kernel</title> 8 9<para>You can override the Linux kernel and associated packages using 10the option <option>boot.kernelPackages</option>. For instance, this 11selects the Linux 3.10 kernel: 12<programlisting> 13boot.kernelPackages = pkgs.linuxPackages_3_10; 14</programlisting> 15Note that this not only replaces the kernel, but also packages that 16are specific to the kernel version, such as the NVIDIA video drivers. 17This ensures that driver packages are consistent with the 18kernel.</para> 19 20<para>The default Linux kernel configuration should be fine for most users. You can see the configuration of your current kernel with the following command: 21<programlisting> 22zcat /proc/config.gz 23</programlisting> 24If you want to change the kernel configuration, you can use the 25<option>packageOverrides</option> feature (see <xref 26linkend="sec-customising-packages" />). For instance, to enable 27support for the kernel debugger KGDB: 28 29<programlisting> 30nixpkgs.config.packageOverrides = pkgs: 31 { linux_3_4 = pkgs.linux_3_4.override { 32 extraConfig = 33 '' 34 KGDB y 35 ''; 36 }; 37 }; 38</programlisting> 39 40<varname>extraConfig</varname> takes a list of Linux kernel 41configuration options, one per line. The name of the option should 42not include the prefix <literal>CONFIG_</literal>. The option value 43is typically <literal>y</literal>, <literal>n</literal> or 44<literal>m</literal> (to build something as a kernel module).</para> 45 46<para>Kernel modules for hardware devices are generally loaded 47automatically by <command>udev</command>. You can force a module to 48be loaded via <option>boot.kernelModules</option>, e.g. 49<programlisting> 50boot.kernelModules = [ "fuse" "kvm-intel" "coretemp" ]; 51</programlisting> 52If the module is required early during the boot (e.g. to mount the 53root file system), you can use 54<option>boot.initrd.extraKernelModules</option>: 55<programlisting> 56boot.initrd.extraKernelModules = [ "cifs" ]; 57</programlisting> 58This causes the specified modules and their dependencies to be added 59to the initial ramdisk.</para> 60 61<para>Kernel runtime parameters can be set through 62<option>boot.kernel.sysctl</option>, e.g. 63<programlisting> 64boot.kernel.sysctl."net.ipv4.tcp_keepalive_time" = 120; 65</programlisting> 66sets the kernel’s TCP keepalive time to 120 seconds. To see the 67available parameters, run <command>sysctl -a</command>.</para> 68 69<section> 70 <title>Developing kernel modules</title> 71 72 <para>When developing kernel modules it's often convenient to run 73 edit-compile-run loop as quickly as possible. 74 75 See below snippet as an example of developing <literal>mellanox</literal> 76 drivers. 77 </para> 78 79 <screen><![CDATA[ 80$ nix-build '<nixpkgs>' -A linuxPackages.kernel.dev 81$ nix-shell '<nixpkgs>' -A linuxPackages.kernel 82$ unpackPhase 83$ cd linux-* 84$ make -C $dev/lib/modules/*/build M=$(pwd)/drivers/net/ethernet/mellanox modules 85# insmod ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko 86]]></screen> 87 88</section> 89 90</chapter>