Linux kernel: Difference between revisions
Add sysfs example |
m prefix shell comments with $ to get "comment" highlighting instead of "root shell" |
||
| (10 intermediate revisions by 9 users not shown) | |||
| Line 24: | Line 24: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
nix-repl> | nix-repl> pkgs = import <nixpkgs> {} | ||
Added 12607 variables. | Added 12607 variables. | ||
nix-repl> pkgs. | nix-repl> pkgs.linuxKernel.packages | ||
pkgs.linuxPackages pkgs.linuxPackages_custom | pkgs.linuxPackages pkgs.linuxPackages_custom | ||
pkgs.linuxPackages-libre pkgs.linuxPackages_custom_tinyconfig_kernel | pkgs.linuxPackages-libre pkgs.linuxPackages_custom_tinyconfig_kernel | ||
| Line 127: | Line 127: | ||
<syntaxhighlight lang=nix> | <syntaxhighlight lang=nix> | ||
{ | { | ||
boot.kernelPatches = [ { | |||
name = "crashdump-config"; | |||
patch = null; | |||
structuredExtraConfig = with lib.kernel; { | |||
CRASH_DUMP = yes; | |||
DEBUG_INFO = yes; | |||
PROC_VMCORE = yes; | |||
LOCKUP_DETECTOR = yes; | |||
HARDLOCKUP_DETECTOR = yes; | |||
}; | |||
} ]; | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Another way is to create an overlay to configure | Another way is to create an overlay to configure {{ic|structuredExtraConfig}}. This allows for more flexibility, since you can basically override any available kernel option<ref>[https://github.com/NixOS/nixpkgs/blob/e6db435973160591fe7348876a5567c729495175/pkgs/os-specific/linux/kernel/generic.nix#L11-L56<tt>pkgs/os-specific/linux/kernel/generic.nix#L11-L56</tt>]</ref>. | ||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
| Line 152: | Line 153: | ||
SCHED_MUQSS = yes; | SCHED_MUQSS = yes; | ||
}; | }; | ||
ignoreConfigErrors = true; | ignoreConfigErrors = true; # not necessarily a good idea | ||
}); | }); | ||
}) | }) | ||
| Line 159: | Line 160: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
If the kernel config fails to build with messages like <code>error: unused option: DRM_I915_GVT</code>, try setting e.g. <code>DRM_I915_GVT = lib.kernel.unset</code>. Setting {{ic|ignoreConfigErrors}} will also silence these errors, at the cost of ignoring potential problems. ([https://github.com/NixOS/nixpkgs/blob/3ab9a9d12ba76f6a544c207e1364da5b3087b77c/pkgs/os-specific/linux/kernel/generate-config.pl generate-config.pl] is responsible for these; they are often produced when [https://github.com/NixOS/nixpkgs/blob/3ab9a9d12ba76f6a544c207e1364da5b3087b77c/pkgs/os-specific/linux/kernel/common-config.nix the default config] doesn't use <code>lib.kernel.option</code> for an option that is implicitly disabled by whatever change you made.) | |||
=== Pinning a kernel version === | === Pinning a kernel version === | ||
| Line 176: | Line 179: | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
Note that pinning the kernel version will likely require manual recompilation, which may be slow on older hardware. See [https://discourse.nixos.org/t/pin-kernel-version/50630/3 this thread] for a related discussion. | |||
=== Debugging a failed configuration === | === Debugging a failed configuration === | ||
| Line 236: | Line 241: | ||
Please provide a comparison with other distributions' kernel: | Please provide a comparison with other distributions' kernel: | ||
* Arch: https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/blob/main/config | |||
* Debian: https://salsa.debian.org/kernel-team/linux/blob/master/debian/config/config and the ARCH specific ones | |||
== Booting a kernel from a custom source == | == Booting a kernel from a custom source == | ||
| Line 261: | Line 267: | ||
kernelPatches = []; | kernelPatches = []; | ||
structuredExtraConfig = with lib.kernel; { | |||
INTEL_SGX | INTEL_SGX = yes; | ||
}; | |||
extraMeta.branch = "5.4"; | extraMeta.branch = "5.4"; | ||
| Line 286: | Line 292: | ||
owner = "aramg"; | owner = "aramg"; | ||
repo = "droidcam"; | repo = "droidcam"; | ||
tag = "v${version}"; | |||
hash = "1d9qpnmqa3pfwsrpjnxdz76ipk4w37bbxyrazchh4vslnfc886fx"; | hash = "1d9qpnmqa3pfwsrpjnxdz76ipk4w37bbxyrazchh4vslnfc886fx"; | ||
}; | }; | ||
| Line 440: | Line 446: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ nix-shell | $ nix-shell | ||
# to configure | $ # to configure | ||
$ nix-shell> make $makeFlags defconfig -j $(nproc) | $ nix-shell> make $makeFlags defconfig -j $(nproc) | ||
# to build | $ # to build | ||
$ nix-shell> make $makeFlags -j $(nproc) | $ nix-shell> make $makeFlags -j $(nproc) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 461: | Line 467: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ nix-shell | $ nix-shell | ||
# to configure | $ # to configure | ||
$ nix-shell> make $makeFlags defconfig -j $(nproc) | $ nix-shell> make $makeFlags defconfig -j $(nproc) | ||
# to build | $ # to build | ||
$ nix-shell> make $makeFlags -j $(nproc) | $ nix-shell> make $makeFlags -j $(nproc) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 469: | Line 475: | ||
=== Overriding kernel packages === | === Overriding kernel packages === | ||
In order to override <code>linuxPackages</code>, use the <code>extend</code> attribute. Example: | In order to override <code>linuxPackages</code>, an alias of <code>linuxKernel.packages</code>, use the <code>extend</code> attribute. Example: | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
| Line 493: | Line 499: | ||
}) | }) | ||
]; | ]; | ||
</syntaxHighlight> | |||
You can also use <code>kernelPackagesExtensions</code> in a similar fashion to override <code>linuxKernel.packages</code>: | |||
<syntaxHighlight lang=nix> | |||
nixpkgs.overlays = [ | |||
(_: prev: { | |||
kernelPackagesExtensions = prev.kernelPackagesExtensions ++ [ | |||
(_: linuxPrev: { | |||
digimend = linuxPrev.digimend.overrideAttrs (prevAttrs: { | |||
postPatch = prevAttrs.postPatch or "" + '' | |||
substituteInPlace "hid-uclogic-core.c" \ | |||
--replace-fail "del_timer_sync" "timer_shutdown_sync" | |||
''; | |||
}); | |||
}) | |||
]; | |||
}) | |||
]; | |||
</syntaxHighlight> | </syntaxHighlight> | ||
| Line 589: | Line 614: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== See also == | == See also == | ||