Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 20.09 85 lines 4.3 kB view raw
1<section xmlns="http://docbook.org/ns/docbook" 2 xmlns:xlink="http://www.w3.org/1999/xlink" 3 xml:id="sec-linux-kernel"> 4 <title>Linux kernel</title> 5 6 <para> 7 The Nix expressions to build the Linux kernel are in <link 8xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/kernel"><filename>pkgs/os-specific/linux/kernel</filename></link>. 9 </para> 10 11 <para> 12 The function that builds the kernel has an argument <varname>kernelPatches</varname> which should be a list of <literal>{name, patch, extraConfig}</literal> attribute sets, where <varname>name</varname> is the name of the patch (which is included in the kernel’s <varname>meta.description</varname> attribute), <varname>patch</varname> is the patch itself (possibly compressed), and <varname>extraConfig</varname> (optional) is a string specifying extra options to be concatenated to the kernel configuration file (<filename>.config</filename>). 13 </para> 14 15 <para> 16 The kernel derivation exports an attribute <varname>features</varname> specifying whether optional functionality is or isn’t enabled. This is used in NixOS to implement kernel-specific behaviour. For instance, if the kernel has the <varname>iwlwifi</varname> feature (i.e. has built-in support for Intel wireless chipsets), then NixOS doesn’t have to build the external <varname>iwlwifi</varname> package: 17<programlisting> 18modulesTree = [kernel] 19 ++ pkgs.lib.optional (!kernel.features ? iwlwifi) kernelPackages.iwlwifi 20 ++ ...; 21</programlisting> 22 </para> 23 24 <para> 25 How to add a new (major) version of the Linux kernel to Nixpkgs: 26 <orderedlist> 27 <listitem> 28 <para> 29 Copy the old Nix expression (e.g. <filename>linux-2.6.21.nix</filename>) to the new one (e.g. <filename>linux-2.6.22.nix</filename>) and update it. 30 </para> 31 </listitem> 32 <listitem> 33 <para> 34 Add the new kernel to <filename>all-packages.nix</filename> (e.g., create an attribute <varname>kernel_2_6_22</varname>). 35 </para> 36 </listitem> 37 <listitem> 38 <para> 39 Now we’re going to update the kernel configuration. First unpack the kernel. Then for each supported platform (<literal>i686</literal>, <literal>x86_64</literal>, <literal>uml</literal>) do the following: 40 <orderedlist> 41 <listitem> 42 <para> 43 Make an copy from the old config (e.g. <filename>config-2.6.21-i686-smp</filename>) to the new one (e.g. <filename>config-2.6.22-i686-smp</filename>). 44 </para> 45 </listitem> 46 <listitem> 47 <para> 48 Copy the config file for this platform (e.g. <filename>config-2.6.22-i686-smp</filename>) to <filename>.config</filename> in the kernel source tree. 49 </para> 50 </listitem> 51 <listitem> 52 <para> 53 Run <literal>make oldconfig ARCH=<replaceable>{i386,x86_64,um}</replaceable></literal> and answer all questions. (For the uml configuration, also add <literal>SHELL=bash</literal>.) Make sure to keep the configuration consistent between platforms (i.e. don’t enable some feature on <literal>i686</literal> and disable it on <literal>x86_64</literal>). 54 </para> 55 </listitem> 56 <listitem> 57 <para> 58 If needed you can also run <literal>make menuconfig</literal>: 59<screen> 60<prompt>$ </prompt>nix-env -i ncurses 61<prompt>$ </prompt>export NIX_CFLAGS_LINK=-lncurses 62<prompt>$ </prompt>make menuconfig ARCH=<replaceable>arch</replaceable></screen> 63 </para> 64 </listitem> 65 <listitem> 66 <para> 67 Copy <filename>.config</filename> over the new config file (e.g. <filename>config-2.6.22-i686-smp</filename>). 68 </para> 69 </listitem> 70 </orderedlist> 71 </para> 72 </listitem> 73 <listitem> 74 <para> 75 Test building the kernel: <literal>nix-build -A kernel_2_6_22</literal>. If it compiles, ship it! For extra credit, try booting NixOS with it. 76 </para> 77 </listitem> 78 <listitem> 79 <para> 80 It may be that the new kernel requires updating the external kernel modules and kernel-dependent packages listed in the <varname>linuxPackagesFor</varname> function in <filename>all-packages.nix</filename> (such as the NVIDIA drivers, AUFS, etc.). If the updated packages aren’t backwards compatible with older kernels, you may need to keep the older versions around. 81 </para> 82 </listitem> 83 </orderedlist> 84 </para> 85</section>