···4646 builtins.concatStringsSep "."
4747 (lib.take 2 (splitVersion v));
48484949+ /* Pad a version string with zeros to match the given number of components.
5050+5151+ Example:
5252+ pad 3 "1.2"
5353+ => "1.2.0"
5454+ pad 3 "1.3-rc1"
5555+ => "1.3.0-rc1"
5656+ pad 3 "1.2.3.4"
5757+ => "1.2.3"
5858+ */
5959+ pad = n: version: let
6060+ numericVersion = lib.head (lib.splitString "-" version);
6161+ versionSuffix = lib.removePrefix numericVersion version;
6262+ in lib.concatStringsSep "." (lib.take n (lib.splitVersion numericVersion ++ lib.genList (_: "0") n)) + versionSuffix;
6363+4964}
···8282sets the kernel's TCP keepalive time to 120 seconds. To see the
8383available parameters, run `sysctl -a`.
84848585-## Customize your kernel {#sec-linux-config-customizing}
8585+## Building a custom kernel {#sec-linux-config-customizing}
86868787-The first step before compiling the kernel is to generate an appropriate
8888-`.config` configuration. Either you pass your own config via the
8989-`configfile` setting of `linuxKernel.manualConfig`:
8787+You can customize the default kernel configuration by overriding the arguments for your kernel package:
90889189```nix
9292-custom-kernel = let base_kernel = linuxKernel.kernels.linux_4_9;
9393- in super.linuxKernel.manualConfig {
9494- inherit (super) stdenv hostPlatform;
9595- inherit (base_kernel) src;
9696- version = "${base_kernel.version}-custom";
9797-9898- configfile = /home/me/my_kernel_config;
9999- allowImportFromDerivation = true;
100100-};
9090+pkgs.linux_latest.override {
9191+ ignoreConfigErrors = true;
9292+ autoModules = false;
9393+ kernelPreferBuiltin = true;
9494+ extraStructuredConfig = with lib.kernel; {
9595+ DEBUG_KERNEL = yes;
9696+ FRAME_POINTER = yes;
9797+ KGDB = yes;
9898+ KGDB_SERIAL_CONSOLE = yes;
9999+ DEBUG_INFO = yes;
100100+ };
101101+}
101102```
102103103103-You can edit the config with this snippet (by default `make
104104- menuconfig` won\'t work out of the box on nixos):
104104+See `pkgs/os-specific/linux/kernel/generic.nix` for details on how these arguments
105105+affect the generated configuration. You can also build a custom version of Linux by calling
106106+`pkgs.buildLinux` directly, which requires the `src` and `version` arguments to be specified.
107107+108108+To use your custom kernel package in your NixOS configuration, set
105109106106-```ShellSession
107107-nix-shell -E 'with import <nixpkgs> {}; kernelToOverride.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkg-config ncurses ];})'
110110+```nix
111111+boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
108112```
109113110110-or you can let nixpkgs generate the configuration. Nixpkgs generates it
111111-via answering the interactive kernel utility `make config`. The answers
112112-depend on parameters passed to
113113-`pkgs/os-specific/linux/kernel/generic.nix` (which you can influence by
114114-overriding `extraConfig, autoModules,
115115- modDirVersion, preferBuiltin, extraConfig`).
114114+Note that this method will use the common configuration defined in `pkgs/os-specific/linux/kernel/common-config.nix`,
115115+which is suitable for a NixOS system.
116116+117117+If you already have a generated configuration file, you can build a kernel that uses it with `pkgs.linuxManualConfig`:
116118117119```nix
118118-mptcp93.override ({
119119- name="mptcp-local";
120120+let
121121+ baseKernel = pkgs.linux_latest;
122122+in pkgs.linuxManualConfig {
123123+ inherit (baseKernel) src modDirVersion;
124124+ version = "${baseKernel.version}-custom";
125125+ configfile = ./my_kernel_config;
126126+ allowImportFromDerivation = true;
127127+}
128128+```
120129121121- ignoreConfigErrors = true;
122122- autoModules = false;
123123- kernelPreferBuiltin = true;
130130+::: {.note}
131131+The build will fail if `modDirVersion` does not match the source's `kernel.release` file,
132132+so `modDirVersion` should remain tied to `src`.
133133+:::
124134125125- enableParallelBuilding = true;
135135+To edit the `.config` file for Linux X.Y, proceed as follows:
126136127127- extraConfig = ''
128128- DEBUG_KERNEL y
129129- FRAME_POINTER y
130130- KGDB y
131131- KGDB_SERIAL_CONSOLE y
132132- DEBUG_INFO y
133133- '';
134134-});
137137+```ShellSession
138138+$ nix-shell '<nixpkgs>' -A linuxKernel.kernels.linux_X_Y.configEnv
139139+$ unpackPhase
140140+$ cd linux-*
141141+$ make nconfig
135142```
136143137144## Developing kernel modules {#sec-linux-config-developing-modules}
138145139139-When developing kernel modules it\'s often convenient to run
146146+When developing kernel modules it's often convenient to run
140147edit-compile-run loop as quickly as possible. See below snippet as an
141148example of developing `mellanox` drivers.
142149
···9696 available parameters, run <literal>sysctl -a</literal>.
9797 </para>
9898 <section xml:id="sec-linux-config-customizing">
9999- <title>Customize your kernel</title>
9999+ <title>Building a custom kernel</title>
100100 <para>
101101- The first step before compiling the kernel is to generate an
102102- appropriate <literal>.config</literal> configuration. Either you
103103- pass your own config via the <literal>configfile</literal> setting
104104- of <literal>linuxKernel.manualConfig</literal>:
101101+ You can customize the default kernel configuration by overriding
102102+ the arguments for your kernel package:
105103 </para>
106104 <programlisting language="bash">
107107-custom-kernel = let base_kernel = linuxKernel.kernels.linux_4_9;
108108- in super.linuxKernel.manualConfig {
109109- inherit (super) stdenv hostPlatform;
110110- inherit (base_kernel) src;
111111- version = "${base_kernel.version}-custom";
112112-113113- configfile = /home/me/my_kernel_config;
114114- allowImportFromDerivation = true;
115115-};
105105+pkgs.linux_latest.override {
106106+ ignoreConfigErrors = true;
107107+ autoModules = false;
108108+ kernelPreferBuiltin = true;
109109+ extraStructuredConfig = with lib.kernel; {
110110+ DEBUG_KERNEL = yes;
111111+ FRAME_POINTER = yes;
112112+ KGDB = yes;
113113+ KGDB_SERIAL_CONSOLE = yes;
114114+ DEBUG_INFO = yes;
115115+ };
116116+}
116117</programlisting>
117118 <para>
118118- You can edit the config with this snippet (by default
119119- <literal>make menuconfig</literal> won't work out of the box on
120120- nixos):
119119+ See <literal>pkgs/os-specific/linux/kernel/generic.nix</literal>
120120+ for details on how these arguments affect the generated
121121+ configuration. You can also build a custom version of Linux by
122122+ calling <literal>pkgs.buildLinux</literal> directly, which
123123+ requires the <literal>src</literal> and <literal>version</literal>
124124+ arguments to be specified.
121125 </para>
122122- <programlisting>
123123-nix-shell -E 'with import <nixpkgs> {}; kernelToOverride.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkg-config ncurses ];})'
126126+ <para>
127127+ To use your custom kernel package in your NixOS configuration, set
128128+ </para>
129129+ <programlisting language="bash">
130130+boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
124131</programlisting>
125132 <para>
126126- or you can let nixpkgs generate the configuration. Nixpkgs
127127- generates it via answering the interactive kernel utility
128128- <literal>make config</literal>. The answers depend on parameters
129129- passed to
130130- <literal>pkgs/os-specific/linux/kernel/generic.nix</literal>
131131- (which you can influence by overriding
132132- <literal>extraConfig, autoModules, modDirVersion, preferBuiltin, extraConfig</literal>).
133133+ Note that this method will use the common configuration defined in
134134+ <literal>pkgs/os-specific/linux/kernel/common-config.nix</literal>,
135135+ which is suitable for a NixOS system.
136136+ </para>
137137+ <para>
138138+ If you already have a generated configuration file, you can build
139139+ a kernel that uses it with
140140+ <literal>pkgs.linuxManualConfig</literal>:
133141 </para>
134142 <programlisting language="bash">
135135-mptcp93.override ({
136136- name="mptcp-local";
137137-138138- ignoreConfigErrors = true;
139139- autoModules = false;
140140- kernelPreferBuiltin = true;
141141-142142- enableParallelBuilding = true;
143143-144144- extraConfig = ''
145145- DEBUG_KERNEL y
146146- FRAME_POINTER y
147147- KGDB y
148148- KGDB_SERIAL_CONSOLE y
149149- DEBUG_INFO y
150150- '';
151151-});
143143+let
144144+ baseKernel = pkgs.linux_latest;
145145+in pkgs.linuxManualConfig {
146146+ inherit (baseKernel) src modDirVersion;
147147+ version = "${baseKernel.version}-custom";
148148+ configfile = ./my_kernel_config;
149149+ allowImportFromDerivation = true;
150150+}
151151+</programlisting>
152152+ <note>
153153+ <para>
154154+ The build will fail if <literal>modDirVersion</literal> does not
155155+ match the source’s <literal>kernel.release</literal> file, so
156156+ <literal>modDirVersion</literal> should remain tied to
157157+ <literal>src</literal>.
158158+ </para>
159159+ </note>
160160+ <para>
161161+ To edit the <literal>.config</literal> file for Linux X.Y, proceed
162162+ as follows:
163163+ </para>
164164+ <programlisting>
165165+$ nix-shell '<nixpkgs>' -A linuxKernel.kernels.linux_X_Y.configEnv
166166+$ unpackPhase
167167+$ cd linux-*
168168+$ make nconfig
152169</programlisting>
153170 </section>
154171 <section xml:id="sec-linux-config-developing-modules">
155172 <title>Developing kernel modules</title>
156173 <para>
157157- When developing kernel modules it's often convenient to run
174174+ When developing kernel modules it’s often convenient to run
158175 edit-compile-run loop as quickly as possible. See below snippet as
159176 an example of developing <literal>mellanox</literal> drivers.
160177 </para>
+2-1
nixos/lib/testing/legacy.nix
···33 inherit (lib) mkIf mkOption types;
44in
55{
66- # This needs options.warnings, which we don't have (yet?).
66+ # This needs options.warnings and options.assertions, which we don't have (yet?).
77 # imports = [
88 # (lib.mkRenamedOptionModule [ "machine" ] [ "nodes" "machine" ])
99+ # (lib.mkRemovedOptionModule [ "minimal" ] "The minimal kernel module was removed as it was broken and not used any more in nixpkgs.")
910 # ];
10111112 options = {
+1-9
nixos/lib/testing/nodes.nix
···2323 nixpkgs.config.allowAliases = false;
2424 })
2525 testModuleArgs.config.extraBaseModules
2626- ] ++ optional config.minimal ../../modules/testing/minimal-kernel.nix;
2626+ ];
2727 };
28282929···7575 An attribute set of arbitrary values that will be made available as module arguments during the resolution of module `imports`.
76767777 Note that it is not possible to override these from within the NixOS configurations. If you argument is not relevant to `imports`, consider setting {option}`defaults._module.args.<name>` instead.
7878- '';
7979- };
8080-8181- minimal = mkOption {
8282- type = types.bool;
8383- default = false;
8484- description = mdDoc ''
8585- Enable to configure all [{option}`nodes`](#test-opt-nodes) to run with a minimal kernel.
8678 '';
8779 };
8880