Skip to content

Commit

Permalink
doc: show how to use manual linux kernel configs
Browse files Browse the repository at this point in the history
The documentation on the linux kernel focused on using and extending
kernels that were already packaged, but never mentioned that it's
possible to also build a kernel almost "from scratch".

This commit gives a starting point on how to do these specialised
kernel builds.
  • Loading branch information
DanielSidhion committed Oct 24, 2023
1 parent 200aa03 commit a8d3b9f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/builders/packages/linux.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ How to add a new (major) version of the Linux kernel to Nixpkgs:
4. Test building the kernel: `nix-build -A linuxKernel.kernels.kernel_2_6_22`. If it compiles, ship it! For extra credit, try booting NixOS with it.

5. It may be that the new kernel requires updating the external kernel modules and kernel-dependent packages listed in the `linuxPackagesFor` function in `linux-kernels.nix` (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.

## Manual kernel configs {#sec-manual-kernel-configs}

Sometimes it may not be desirable to use the kernels already packaged in Nixpkgs, especially if most of the default configuration has to be altered or disabled to achieve a kernel as expected by the target use case. An example of this is building a kernel for use in a VM or micro VM. Nixpkgs provides the `linuxManualConfig` function for these cases: it requires the caller to pass the kernel sources and a config file, allowing one to build their own kernel with specific tuning.

An example usage of `linuxManualConfig`:

```nix
{ pkgs, ... }: {
version = "X.Y.Z";
src = pkgs.fetchurl { ... };
configfile = ./path_to_config_file;
linux = pkgs.linuxManualConfig { inherit version src configfile; };
}
```

Additional properties can be used with `linuxManualConfig` for further customisation. Readers who need more than the barebones example above should read [`pkgs/os-specific/linux/kernel/manual-config.nix`](https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/kernel/manual-config.nix).

0 comments on commit a8d3b9f

Please sign in to comment.