You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

139 lines
5.1 KiB

  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. <title>Linux Kernel</title>
  7. <para>
  8. You can override the Linux kernel and associated packages using the option
  9. <option>boot.kernelPackages</option>. For instance, this selects the Linux
  10. 3.10 kernel:
  11. <programlisting>
  12. <xref linkend="opt-boot.kernelPackages"/> = pkgs.linuxPackages_3_10;
  13. </programlisting>
  14. Note that this not only replaces the kernel, but also packages that are
  15. specific to the kernel version, such as the NVIDIA video drivers. This
  16. ensures that driver packages are consistent with the kernel.
  17. </para>
  18. <para>
  19. The default Linux kernel configuration should be fine for most users. You can
  20. see the configuration of your current kernel with the following command:
  21. <programlisting>
  22. zcat /proc/config.gz
  23. </programlisting>
  24. If you want to change the kernel configuration, you can use the
  25. <option>packageOverrides</option> feature (see
  26. <xref
  27. linkend="sec-customising-packages" />). For instance, to enable support
  28. for the kernel debugger KGDB:
  29. <programlisting>
  30. nixpkgs.config.packageOverrides = pkgs:
  31. { linux_3_4 = pkgs.linux_3_4.override {
  32. extraConfig =
  33. ''
  34. KGDB y
  35. '';
  36. };
  37. };
  38. </programlisting>
  39. <varname>extraConfig</varname> takes a list of Linux kernel configuration
  40. options, one per line. The name of the option should not include the prefix
  41. <literal>CONFIG_</literal>. The option value is typically
  42. <literal>y</literal>, <literal>n</literal> or <literal>m</literal> (to build
  43. something as a kernel module).
  44. </para>
  45. <para>
  46. Kernel modules for hardware devices are generally loaded automatically by
  47. <command>udev</command>. You can force a module to be loaded via
  48. <xref linkend="opt-boot.kernelModules"/>, e.g.
  49. <programlisting>
  50. <xref linkend="opt-boot.kernelModules"/> = [ "fuse" "kvm-intel" "coretemp" ];
  51. </programlisting>
  52. If the module is required early during the boot (e.g. to mount the root file
  53. system), you can use <xref linkend="opt-boot.initrd.kernelModules"/>:
  54. <programlisting>
  55. <xref linkend="opt-boot.initrd.kernelModules"/> = [ "cifs" ];
  56. </programlisting>
  57. This causes the specified modules and their dependencies to be added to the
  58. initial ramdisk.
  59. </para>
  60. <para>
  61. Kernel runtime parameters can be set through
  62. <xref linkend="opt-boot.kernel.sysctl"/>, e.g.
  63. <programlisting>
  64. <xref linkend="opt-boot.kernel.sysctl"/>."net.ipv4.tcp_keepalive_time" = 120;
  65. </programlisting>
  66. sets the kernel’s TCP keepalive time to 120 seconds. To see the available
  67. parameters, run <command>sysctl -a</command>.
  68. </para>
  69. <section xml:id="sec-linux-config-customizing">
  70. <title>Customize your kernel</title>
  71. <para>
  72. The first step before compiling the kernel is to generate an appropriate
  73. <literal>.config</literal> configuration. Either you pass your own config
  74. via the <literal>configfile</literal> setting of
  75. <literal>linuxManualConfig</literal>:
  76. <screen><![CDATA[
  77. custom-kernel = super.linuxManualConfig {
  78. inherit (super) stdenv hostPlatform;
  79. inherit (linux_4_9) src;
  80. version = "${linux_4_9.version}-custom";
  81. configfile = /home/me/my_kernel_config;
  82. allowImportFromDerivation = true;
  83. };
  84. ]]></screen>
  85. You can edit the config with this snippet (by default <command>make
  86. menuconfig</command> won't work out of the box on nixos):
  87. <screen><![CDATA[
  88. nix-shell -E 'with import <nixpkgs> {}; kernelToOverride.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkgconfig ncurses ];})'
  89. ]]></screen>
  90. or you can let nixpkgs generate the configuration. Nixpkgs generates it via
  91. answering the interactive kernel utility <command>make config</command>. The
  92. answers depend on parameters passed to
  93. <filename>pkgs/os-specific/linux/kernel/generic.nix</filename> (which you
  94. can influence by overriding <literal>extraConfig, autoModules,
  95. modDirVersion, preferBuiltin, extraConfig</literal>).
  96. <screen><![CDATA[
  97. mptcp93.override ({
  98. name="mptcp-local";
  99. ignoreConfigErrors = true;
  100. autoModules = false;
  101. kernelPreferBuiltin = true;
  102. enableParallelBuilding = true;
  103. extraConfig = ''
  104. DEBUG_KERNEL y
  105. FRAME_POINTER y
  106. KGDB y
  107. KGDB_SERIAL_CONSOLE y
  108. DEBUG_INFO y
  109. '';
  110. });
  111. ]]></screen>
  112. </para>
  113. </section>
  114. <section xml:id="sec-linux-config-developing-modules">
  115. <title>Developing kernel modules</title>
  116. <para>
  117. When developing kernel modules it's often convenient to run edit-compile-run
  118. loop as quickly as possible. See below snippet as an example of developing
  119. <literal>mellanox</literal> drivers.
  120. </para>
  121. <screen>
  122. <prompt>$ </prompt>nix-build '&lt;nixpkgs>' -A linuxPackages.kernel.dev
  123. <prompt>$ </prompt>nix-shell '&lt;nixpkgs>' -A linuxPackages.kernel
  124. <prompt>$ </prompt>unpackPhase
  125. <prompt>$ </prompt>cd linux-*
  126. <prompt>$ </prompt>make -C $dev/lib/modules/*/build M=$(pwd)/drivers/net/ethernet/mellanox modules
  127. <prompt># </prompt>insmod ./drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.ko
  128. </screen>
  129. </section>
  130. </chapter>