Linux kernel: Difference between revisions

From NixOS Wiki
imported>Samueldr
m Adds link to Choose your kernel on NixOS page
imported>Teto
added entry for make xconfig
Line 40: Line 40:
[nix-shell] $ make menuconfig
[nix-shell] $ make menuconfig
</syntaxHighlight> (thanks to sphalerite)
</syntaxHighlight> (thanks to sphalerite)
== make xconfig ==
Similarly to make menuconfig, you need to import qt in the environment:
<syntaxHighlight lang=console>
$ nix-shell -E 'with import <nixpkgs> {}; linux.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkgconfig qt5.qtbase ];})'
</syntaxHighlight>
If the source was unpacked and an initial config exists, you can run <code>make xconfig KCONFIG_CONFIG=build/.config</code>


== Adding <code>extraConfig</code> ==
== Adding <code>extraConfig</code> ==

Revision as of 05:02, 3 September 2018

Configuring the Linux Kernel

See:

Developing Kernel Modules

See also: NixOS Manual "Developing kernel modules"

If you work on an out-of-tree kernel module the workflow could look as follow:

#include <linux/module.h>
#define MODULE_NAME "hello"
static int __init hello_init(void)
{
    printk(KERN_INFO "hello world!");
    return 0;
}
static void __exit hello_cleanup(void) {}
module_init(hello_init);
module_exit(hello_cleanup);
$ nix-shell '<nixpkgs>' -A linux.dev
$ make -C $(nix-build -E '(import <nixpkgs> {}).linux.dev' --no-out-link)/lib/modules/*/build M=$(pwd) modules
$ insmod ./hello.ko
$ dmesg | grep hello
[   82.027229] hello world!

make menuconfig

It is (currently) not possible to run make menuconfig in the checked out linux kernel sources. This is because ncurses is not part of your working environment when you start it with nix-shell '<nixpkgs>' -A linuxPackages.kernel.

This nix-shell hack adds ncurses as a build dependency to the kernel:

$ nix-shell -E 'with import <nixpkgs> {}; linux.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkgconfig ncurses ];})'
[nix-shell] $ unpackPhase && cd linux-*
[nix-shell] $ make menuconfig

(thanks to sphalerite)

make xconfig

Similarly to make menuconfig, you need to import qt in the environment:

$ nix-shell -E 'with import <nixpkgs> {}; linux.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkgconfig qt5.qtbase ];})'

If the source was unpacked and an initial config exists, you can run make xconfig KCONFIG_CONFIG=build/.config

Adding extraConfig

It is sometimes desirable to change the configuration of your kernel, while keeping the kernel version itself managed through nixpkgs. To do so, you can add the configuration to a dummy boot.kernelPatches[1][2], which will then be merged and applied to the current kernel. As with kernel configuration with NixOS, drop the CONFIG_ from the kernel configuration names.

This example is from the boot.crashDump.enable option:

{
      boot.kernelPatches = [ {
        name = "crashdump-config";
        patch = null;
        extraConfig = ''
                CRASH_DUMP y
                DEBUG_INFO y
                PROC_VMCORE y
                LOCKUP_DETECTOR y
                HARDLOCKUP_DETECTOR y
              '';
        } ];
}