···46 builtins.concatStringsSep "."
47 (lib.take 2 (splitVersion v));
4849+ /* Pad a version string with zeros to match the given number of components.
50+51+ Example:
52+ pad 3 "1.2"
53+ => "1.2.0"
54+ pad 3 "1.3-rc1"
55+ => "1.3.0-rc1"
56+ pad 3 "1.2.3.4"
57+ => "1.2.3"
58+ */
59+ pad = n: version: let
60+ numericVersion = lib.head (lib.splitString "-" version);
61+ versionSuffix = lib.removePrefix numericVersion version;
62+ in lib.concatStringsSep "." (lib.take n (lib.splitVersion numericVersion ++ lib.genList (_: "0") n)) + versionSuffix;
63+64}
···82sets the kernel's TCP keepalive time to 120 seconds. To see the
83available parameters, run `sysctl -a`.
8485-## Customize your kernel {#sec-linux-config-customizing}
8687-The first step before compiling the kernel is to generate an appropriate
88-`.config` configuration. Either you pass your own config via the
89-`configfile` setting of `linuxKernel.manualConfig`:
9091```nix
92-custom-kernel = let base_kernel = linuxKernel.kernels.linux_4_9;
93- in super.linuxKernel.manualConfig {
94- inherit (super) stdenv hostPlatform;
95- inherit (base_kernel) src;
96- version = "${base_kernel.version}-custom";
97-98- configfile = /home/me/my_kernel_config;
99- allowImportFromDerivation = true;
100-};
000101```
102103-You can edit the config with this snippet (by default `make
104- menuconfig` won\'t work out of the box on nixos):
000105106-```ShellSession
107-nix-shell -E 'with import <nixpkgs> {}; kernelToOverride.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkg-config ncurses ];})'
108```
109110-or you can let nixpkgs generate the configuration. Nixpkgs generates it
111-via answering the interactive kernel utility `make config`. The answers
112-depend on parameters passed to
113-`pkgs/os-specific/linux/kernel/generic.nix` (which you can influence by
114-overriding `extraConfig, autoModules,
115- modDirVersion, preferBuiltin, extraConfig`).
116117```nix
118-mptcp93.override ({
119- name="mptcp-local";
0000000120121- ignoreConfigErrors = true;
122- autoModules = false;
123- kernelPreferBuiltin = true;
0124125- enableParallelBuilding = true;
126127- extraConfig = ''
128- DEBUG_KERNEL y
129- FRAME_POINTER y
130- KGDB y
131- KGDB_SERIAL_CONSOLE y
132- DEBUG_INFO y
133- '';
134-});
135```
136137## Developing kernel modules {#sec-linux-config-developing-modules}
138139-When developing kernel modules it\'s often convenient to run
140edit-compile-run loop as quickly as possible. See below snippet as an
141example of developing `mellanox` drivers.
142
···82sets the kernel's TCP keepalive time to 120 seconds. To see the
83available parameters, run `sysctl -a`.
8485+## Building a custom kernel {#sec-linux-config-customizing}
8687+You can customize the default kernel configuration by overriding the arguments for your kernel package:
008889```nix
90+pkgs.linux_latest.override {
91+ ignoreConfigErrors = true;
92+ autoModules = false;
93+ kernelPreferBuiltin = true;
94+ extraStructuredConfig = with lib.kernel; {
95+ DEBUG_KERNEL = yes;
96+ FRAME_POINTER = yes;
97+ KGDB = yes;
98+ KGDB_SERIAL_CONSOLE = yes;
99+ DEBUG_INFO = yes;
100+ };
101+}
102```
103104+See `pkgs/os-specific/linux/kernel/generic.nix` for details on how these arguments
105+affect the generated configuration. You can also build a custom version of Linux by calling
106+`pkgs.buildLinux` directly, which requires the `src` and `version` arguments to be specified.
107+108+To use your custom kernel package in your NixOS configuration, set
109110+```nix
111+boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
112```
113114+Note that this method will use the common configuration defined in `pkgs/os-specific/linux/kernel/common-config.nix`,
115+which is suitable for a NixOS system.
116+117+If you already have a generated configuration file, you can build a kernel that uses it with `pkgs.linuxManualConfig`:
00118119```nix
120+let
121+ baseKernel = pkgs.linux_latest;
122+in pkgs.linuxManualConfig {
123+ inherit (baseKernel) src modDirVersion;
124+ version = "${baseKernel.version}-custom";
125+ configfile = ./my_kernel_config;
126+ allowImportFromDerivation = true;
127+}
128+```
129130+::: {.note}
131+The build will fail if `modDirVersion` does not match the source's `kernel.release` file,
132+so `modDirVersion` should remain tied to `src`.
133+:::
134135+To edit the `.config` file for Linux X.Y, proceed as follows:
136137+```ShellSession
138+$ nix-shell '<nixpkgs>' -A linuxKernel.kernels.linux_X_Y.configEnv
139+$ unpackPhase
140+$ cd linux-*
141+$ make nconfig
000142```
143144## Developing kernel modules {#sec-linux-config-developing-modules}
145146+When developing kernel modules it's often convenient to run
147edit-compile-run loop as quickly as possible. See below snippet as an
148example of developing `mellanox` drivers.
149
···96 available parameters, run <literal>sysctl -a</literal>.
97 </para>
98 <section xml:id="sec-linux-config-customizing">
99- <title>Customize your kernel</title>
100 <para>
101- The first step before compiling the kernel is to generate an
102- appropriate <literal>.config</literal> configuration. Either you
103- pass your own config via the <literal>configfile</literal> setting
104- of <literal>linuxKernel.manualConfig</literal>:
105 </para>
106 <programlisting language="bash">
107-custom-kernel = let base_kernel = linuxKernel.kernels.linux_4_9;
108- in super.linuxKernel.manualConfig {
109- inherit (super) stdenv hostPlatform;
110- inherit (base_kernel) src;
111- version = "${base_kernel.version}-custom";
112-113- configfile = /home/me/my_kernel_config;
114- allowImportFromDerivation = true;
115-};
000116</programlisting>
117 <para>
118- You can edit the config with this snippet (by default
119- <literal>make menuconfig</literal> won't work out of the box on
120- nixos):
000121 </para>
122- <programlisting>
123-nix-shell -E 'with import <nixpkgs> {}; kernelToOverride.overrideAttrs (o: {nativeBuildInputs=o.nativeBuildInputs ++ [ pkg-config ncurses ];})'
000124</programlisting>
125 <para>
126- or you can let nixpkgs generate the configuration. Nixpkgs
127- generates it via answering the interactive kernel utility
128- <literal>make config</literal>. The answers depend on parameters
129- passed to
130- <literal>pkgs/os-specific/linux/kernel/generic.nix</literal>
131- (which you can influence by overriding
132- <literal>extraConfig, autoModules, modDirVersion, preferBuiltin, extraConfig</literal>).
0133 </para>
134 <programlisting language="bash">
135-mptcp93.override ({
136- name="mptcp-local";
137-138- ignoreConfigErrors = true;
139- autoModules = false;
140- kernelPreferBuiltin = true;
141-142- enableParallelBuilding = true;
143-144- extraConfig = ''
145- DEBUG_KERNEL y
146- FRAME_POINTER y
147- KGDB y
148- KGDB_SERIAL_CONSOLE y
149- DEBUG_INFO y
150- '';
151-});
000000000152</programlisting>
153 </section>
154 <section xml:id="sec-linux-config-developing-modules">
155 <title>Developing kernel modules</title>
156 <para>
157- When developing kernel modules it's often convenient to run
158 edit-compile-run loop as quickly as possible. See below snippet as
159 an example of developing <literal>mellanox</literal> drivers.
160 </para>
···96 available parameters, run <literal>sysctl -a</literal>.
97 </para>
98 <section xml:id="sec-linux-config-customizing">
99+ <title>Building a custom kernel</title>
100 <para>
101+ You can customize the default kernel configuration by overriding
102+ the arguments for your kernel package:
00103 </para>
104 <programlisting language="bash">
105+pkgs.linux_latest.override {
106+ ignoreConfigErrors = true;
107+ autoModules = false;
108+ kernelPreferBuiltin = true;
109+ extraStructuredConfig = with lib.kernel; {
110+ DEBUG_KERNEL = yes;
111+ FRAME_POINTER = yes;
112+ KGDB = yes;
113+ KGDB_SERIAL_CONSOLE = yes;
114+ DEBUG_INFO = yes;
115+ };
116+}
117</programlisting>
118 <para>
119+ See <literal>pkgs/os-specific/linux/kernel/generic.nix</literal>
120+ for details on how these arguments affect the generated
121+ configuration. You can also build a custom version of Linux by
122+ calling <literal>pkgs.buildLinux</literal> directly, which
123+ requires the <literal>src</literal> and <literal>version</literal>
124+ arguments to be specified.
125 </para>
126+ <para>
127+ To use your custom kernel package in your NixOS configuration, set
128+ </para>
129+ <programlisting language="bash">
130+boot.kernelPackages = pkgs.linuxPackagesFor yourCustomKernel;
131</programlisting>
132 <para>
133+ Note that this method will use the common configuration defined in
134+ <literal>pkgs/os-specific/linux/kernel/common-config.nix</literal>,
135+ which is suitable for a NixOS system.
136+ </para>
137+ <para>
138+ If you already have a generated configuration file, you can build
139+ a kernel that uses it with
140+ <literal>pkgs.linuxManualConfig</literal>:
141 </para>
142 <programlisting language="bash">
143+let
144+ baseKernel = pkgs.linux_latest;
145+in pkgs.linuxManualConfig {
146+ inherit (baseKernel) src modDirVersion;
147+ version = "${baseKernel.version}-custom";
148+ configfile = ./my_kernel_config;
149+ allowImportFromDerivation = true;
150+}
151+</programlisting>
152+ <note>
153+ <para>
154+ The build will fail if <literal>modDirVersion</literal> does not
155+ match the source’s <literal>kernel.release</literal> file, so
156+ <literal>modDirVersion</literal> should remain tied to
157+ <literal>src</literal>.
158+ </para>
159+ </note>
160+ <para>
161+ To edit the <literal>.config</literal> file for Linux X.Y, proceed
162+ as follows:
163+ </para>
164+ <programlisting>
165+$ nix-shell '<nixpkgs>' -A linuxKernel.kernels.linux_X_Y.configEnv
166+$ unpackPhase
167+$ cd linux-*
168+$ make nconfig
169</programlisting>
170 </section>
171 <section xml:id="sec-linux-config-developing-modules">
172 <title>Developing kernel modules</title>
173 <para>
174+ When developing kernel modules it’s often convenient to run
175 edit-compile-run loop as quickly as possible. See below snippet as
176 an example of developing <literal>mellanox</literal> drivers.
177 </para>
+2-1
nixos/lib/testing/legacy.nix
···3 inherit (lib) mkIf mkOption types;
4in
5{
6- # This needs options.warnings, which we don't have (yet?).
7 # imports = [
8 # (lib.mkRenamedOptionModule [ "machine" ] [ "nodes" "machine" ])
09 # ];
1011 options = {
···3 inherit (lib) mkIf mkOption types;
4in
5{
6+ # This needs options.warnings and options.assertions, which we don't have (yet?).
7 # imports = [
8 # (lib.mkRenamedOptionModule [ "machine" ] [ "nodes" "machine" ])
9+ # (lib.mkRemovedOptionModule [ "minimal" ] "The minimal kernel module was removed as it was broken and not used any more in nixpkgs.")
10 # ];
1112 options = {
+1-9
nixos/lib/testing/nodes.nix
···23 nixpkgs.config.allowAliases = false;
24 })
25 testModuleArgs.config.extraBaseModules
26- ] ++ optional config.minimal ../../modules/testing/minimal-kernel.nix;
27 };
2829···75 An attribute set of arbitrary values that will be made available as module arguments during the resolution of module `imports`.
7677 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.
78- '';
79- };
80-81- minimal = mkOption {
82- type = types.bool;
83- default = false;
84- description = mdDoc ''
85- Enable to configure all [{option}`nodes`](#test-opt-nodes) to run with a minimal kernel.
86 '';
87 };
88
···23 nixpkgs.config.allowAliases = false;
24 })
25 testModuleArgs.config.extraBaseModules
26+ ];
27 };
2829···75 An attribute set of arbitrary values that will be made available as module arguments during the resolution of module `imports`.
7677 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.
0000000078 '';
79 };
80