Linux kernel
Configuring the Linux Kernel
Developing Kernel Modules
see 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!
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)