Linux kernel: Difference between revisions

imported>Lillecarl
Wireguard is no longer a great example since it's been mainlined, note this to readers.
imported>Binary-Eater
Added instructions for developing kernel modules for different kernel packages provided by NixOS
Line 266: Line 266:
$ nix-shell '<nixpkgs>' -A linux.dev
$ nix-shell '<nixpkgs>' -A linux.dev
$ make -C $(nix-build -E '(import <nixpkgs> {}).linux.dev' --no-out-link)/lib/modules/*/build M=$(pwd) modules
$ 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!
</syntaxHighlight>
If wishing to develop out-of-tree kernel modules for kernels aside from the default variant shipped under <code>pkgs.linuxPackages</code>, a flow similar to the example below will be used.
The example below illustrates a flow for building kernel modules for <code>pkgs.linuxPackages_latest</code>.
<syntaxHighlight lang="console>
$ nix-shell '<nixpkgs>' -A linuxPackages_latest.kernel.dev
$ make -C $(nix-build -E '(import <nixpkgs> {}).linuxPackages_latest.kernel.dev' --no-out-link)/lib/modules/*/build M=$(pwd) modules
$ insmod ./hello.ko
$ insmod ./hello.ko
$ dmesg | grep hello
$ dmesg | grep hello