2014-04-14 14:26:48 +00:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
2009-11-08 09:01:53 +00:00
|
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
|
with lib;
|
2009-01-25 15:48:48 +00:00
|
|
|
|
|
2012-10-11 21:58:46 +00:00
|
|
|
|
let
|
|
|
|
|
|
2016-04-30 04:19:57 +00:00
|
|
|
|
inherit (config.boot) kernelPatches;
|
2019-01-12 00:35:18 +00:00
|
|
|
|
inherit (config.boot.kernel) features randstructSeed;
|
2016-04-30 04:19:57 +00:00
|
|
|
|
inherit (config.boot.kernelPackages) kernel;
|
2012-10-11 21:58:46 +00:00
|
|
|
|
|
|
|
|
|
kernelModulesConf = pkgs.writeText "nixos.conf"
|
|
|
|
|
''
|
|
|
|
|
${concatStringsSep "\n" config.boot.kernelModules}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in
|
2009-12-15 14:10:06 +00:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
###### interface
|
2009-01-25 15:48:48 +00:00
|
|
|
|
|
|
|
|
|
options = {
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2018-02-09 22:07:06 +00:00
|
|
|
|
boot.kernel.features = mkOption {
|
|
|
|
|
default = {};
|
|
|
|
|
example = literalExample "{ debug = true; }";
|
2018-02-14 01:16:36 +00:00
|
|
|
|
internal = true;
|
2018-02-09 22:07:06 +00:00
|
|
|
|
description = ''
|
|
|
|
|
This option allows to enable or disable certain kernel features.
|
2018-02-14 01:16:36 +00:00
|
|
|
|
It's not API, because it's about kernel feature sets, that
|
|
|
|
|
make sense for specific use cases. Mostly along with programs,
|
|
|
|
|
which would have separate nixos options.
|
|
|
|
|
`grep features pkgs/os-specific/linux/kernel/common-config.nix`
|
2018-02-09 22:07:06 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
boot.kernelPackages = mkOption {
|
2010-03-16 12:10:06 +00:00
|
|
|
|
default = pkgs.linuxPackages;
|
2019-03-24 13:04:15 +00:00
|
|
|
|
type = types.unspecified // { merge = mergeEqualOption; };
|
2016-04-30 04:19:57 +00:00
|
|
|
|
apply = kernelPackages: kernelPackages.extend (self: super: {
|
|
|
|
|
kernel = super.kernel.override {
|
2019-01-12 00:35:18 +00:00
|
|
|
|
inherit randstructSeed;
|
2016-04-30 04:19:57 +00:00
|
|
|
|
kernelPatches = super.kernel.kernelPatches ++ kernelPatches;
|
2018-02-09 22:07:06 +00:00
|
|
|
|
features = lib.recursiveUpdate super.kernel.features features;
|
2016-04-30 04:19:57 +00:00
|
|
|
|
};
|
|
|
|
|
});
|
2010-05-28 11:21:40 +00:00
|
|
|
|
# We don't want to evaluate all of linuxPackages for the manual
|
|
|
|
|
# - some of it might not even evaluate correctly.
|
|
|
|
|
defaultText = "pkgs.linuxPackages";
|
2013-10-30 16:37:45 +00:00
|
|
|
|
example = literalExample "pkgs.linuxPackages_2_6_25";
|
2009-12-15 14:10:06 +00:00
|
|
|
|
description = ''
|
|
|
|
|
This option allows you to override the Linux kernel used by
|
|
|
|
|
NixOS. Since things like external kernel module packages are
|
|
|
|
|
tied to the kernel you're using, it also overrides those.
|
|
|
|
|
This option is a function that takes Nixpkgs as an argument
|
|
|
|
|
(as a convenience), and returns an attribute set containing at
|
|
|
|
|
the very least an attribute <varname>kernel</varname>.
|
|
|
|
|
Additional attributes may be needed depending on your
|
|
|
|
|
configuration. For instance, if you use the NVIDIA X driver,
|
|
|
|
|
then it also needs to contain an attribute
|
|
|
|
|
<varname>nvidia_x11</varname>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2016-04-30 04:19:57 +00:00
|
|
|
|
boot.kernelPatches = mkOption {
|
|
|
|
|
type = types.listOf types.attrs;
|
|
|
|
|
default = [];
|
|
|
|
|
example = literalExample "[ pkgs.kernelPatches.ubuntu_fan_4_4 ]";
|
|
|
|
|
description = "A list of additional patches to apply to the kernel.";
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-12 00:35:18 +00:00
|
|
|
|
boot.kernel.randstructSeed = mkOption {
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = "";
|
|
|
|
|
example = "my secret seed";
|
|
|
|
|
description = ''
|
|
|
|
|
Provides a custom seed for the <varname>RANDSTRUCT</varname> security
|
|
|
|
|
option of the Linux kernel. Note that <varname>RANDSTRUCT</varname> is
|
|
|
|
|
only enabled in NixOS hardened kernels. Using a custom seed requires
|
|
|
|
|
building the kernel and dependent packages locally, since this
|
|
|
|
|
customization happens at build time.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
boot.kernelParams = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.listOf types.str;
|
2010-01-05 13:11:12 +00:00
|
|
|
|
default = [ ];
|
2013-10-30 16:37:45 +00:00
|
|
|
|
description = "Parameters added to the kernel command line.";
|
2009-12-15 14:10:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-07-23 18:43:11 +00:00
|
|
|
|
boot.consoleLogLevel = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 4;
|
|
|
|
|
description = ''
|
2018-04-17 01:30:31 +00:00
|
|
|
|
The kernel console <literal>loglevel</literal>. All Kernel Messages with a log level smaller
|
|
|
|
|
than this setting will be printed to the console.
|
2013-07-23 18:43:11 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-15 21:55:51 +00:00
|
|
|
|
boot.vesa = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.bool;
|
2013-09-26 15:33:52 +00:00
|
|
|
|
default = false;
|
2010-01-15 21:55:51 +00:00
|
|
|
|
description = ''
|
2011-09-02 13:19:45 +00:00
|
|
|
|
Whether to activate VESA video mode on boot.
|
2010-01-15 21:55:51 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
boot.extraModulePackages = mkOption {
|
2016-01-17 18:34:55 +00:00
|
|
|
|
type = types.listOf types.package;
|
2009-12-15 14:10:06 +00:00
|
|
|
|
default = [];
|
2019-09-17 06:37:56 +00:00
|
|
|
|
example = literalExample "[ config.boot.kernelPackages.nvidia_x11 ]";
|
2009-12-15 14:10:06 +00:00
|
|
|
|
description = "A list of additional packages supplying kernel modules.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
boot.kernelModules = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.listOf types.str;
|
2009-12-15 14:10:06 +00:00
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
The set of kernel modules to be loaded in the second stage of
|
|
|
|
|
the boot process. Note that modules that are needed to
|
|
|
|
|
mount the root file system should be added to
|
2009-12-15 16:38:20 +00:00
|
|
|
|
<option>boot.initrd.availableKernelModules</option> or
|
2009-12-15 14:10:06 +00:00
|
|
|
|
<option>boot.initrd.kernelModules</option>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 16:38:20 +00:00
|
|
|
|
boot.initrd.availableKernelModules = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.listOf types.str;
|
2009-12-15 16:38:20 +00:00
|
|
|
|
default = [];
|
|
|
|
|
example = [ "sata_nv" "ext3" ];
|
|
|
|
|
description = ''
|
|
|
|
|
The set of kernel modules in the initial ramdisk used during the
|
|
|
|
|
boot process. This set must include all modules necessary for
|
|
|
|
|
mounting the root device. That is, it should include modules
|
|
|
|
|
for the physical device (e.g., SCSI drivers) and for the file
|
|
|
|
|
system (e.g., ext3). The set specified here is automatically
|
|
|
|
|
closed under the module dependency relation, i.e., all
|
|
|
|
|
dependencies of the modules list here are included
|
|
|
|
|
automatically. The modules listed here are available in the
|
|
|
|
|
initrd, but are only loaded on demand (e.g., the ext3 module is
|
|
|
|
|
loaded automatically when an ext3 filesystem is mounted, and
|
|
|
|
|
modules for PCI devices are loaded when they match the PCI ID
|
|
|
|
|
of a device in your system). To force a module to be loaded,
|
|
|
|
|
include it in <option>boot.initrd.kernelModules</option>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
boot.initrd.kernelModules = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
|
type = types.listOf types.str;
|
2011-09-02 13:19:45 +00:00
|
|
|
|
default = [];
|
2009-12-15 16:38:20 +00:00
|
|
|
|
description = "List of modules that are always loaded by the initrd.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
system.modulesTree = mkOption {
|
2013-10-28 15:14:15 +00:00
|
|
|
|
type = types.listOf types.path;
|
2009-12-15 16:38:20 +00:00
|
|
|
|
internal = true;
|
|
|
|
|
default = [];
|
|
|
|
|
description = ''
|
|
|
|
|
Tree of kernel modules. This includes the kernel, plus modules
|
|
|
|
|
built outside of the kernel. Combine these into a single tree of
|
|
|
|
|
symlinks because modprobe only supports one directory.
|
|
|
|
|
'';
|
|
|
|
|
# Convert the list of path to only one path.
|
|
|
|
|
apply = pkgs.aggregateModules;
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-02 01:50:43 +00:00
|
|
|
|
system.requiredKernelConfig = mkOption {
|
|
|
|
|
default = [];
|
|
|
|
|
example = literalExample ''
|
|
|
|
|
with config.lib.kernelConfig; [
|
|
|
|
|
(isYes "MODULES")
|
|
|
|
|
(isEnabled "FB_CON_DECOR")
|
|
|
|
|
(isEnabled "BLK_DEV_INITRD")
|
|
|
|
|
]
|
|
|
|
|
'';
|
|
|
|
|
internal = true;
|
|
|
|
|
type = types.listOf types.attrs;
|
|
|
|
|
description = ''
|
|
|
|
|
This option allows modules to specify the kernel config options that
|
|
|
|
|
must be set (or unset) for the module to work. Please use the
|
|
|
|
|
lib.kernelConfig functions to build list elements.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 16:38:20 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
2013-11-27 15:54:20 +00:00
|
|
|
|
config = mkIf (!config.boot.isContainer) {
|
2009-12-15 16:38:20 +00:00
|
|
|
|
|
|
|
|
|
system.build = { inherit kernel; };
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2009-12-15 16:38:20 +00:00
|
|
|
|
system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
|
|
|
|
|
|
2013-07-23 18:43:11 +00:00
|
|
|
|
# Implement consoleLogLevel both in early boot and using sysctl
|
|
|
|
|
# (so you don't need to reboot to have changes take effect).
|
2010-01-05 13:11:12 +00:00
|
|
|
|
boot.kernelParams =
|
2013-07-23 18:43:11 +00:00
|
|
|
|
[ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
|
2019-06-13 15:58:08 +00:00
|
|
|
|
optionals config.boot.vesa [ "vga=0x317" "nomodeset" ];
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
nixos/boot: allow kernel.printk override (#34958)
At one point in my configuration I had:
boot.kernel.sysctl = {
# https://unix.stackexchange.com/questions/13019/description-of-kernel-printk-values
"kernel.printk" = "4 4 1 7";
};
which triggered:
error: The unique option `boot.kernel.sysctl.kernel.printk' is defined multiple times, in `/home/teto/dotfiles/nixpkgs/mptcp-unstable.nix' and `/home/teto/nixpkgs/nixos/modules/system/boot/kernel.nix'.
(use ‘--show-trace’ to show detailed location information)
Traceback (most recent call last):
File "/home/teto/nixops/scripts/nixops", line 984, in <module>
args.op()
File "/home/teto/nixops/scripts/nixops", line 406, in op_deploy
max_concurrent_activate=args.max_concurrent_activate)
File "/home/teto/nixops/nixops/deployment.py", line 1045, in deploy
self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
File "/home/teto/nixops/nixops/deployment.py", line 1034, in run_with_notify
f()
File "/home/teto/nixops/nixops/deployment.py", line 1045, in <lambda>
self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
File "/home/teto/nixops/nixops/deployment.py", line 985, in _deploy
self.configs_path = self.build_configs(dry_run=dry_run, repair=repair, include=include, exclude=exclude)
File "/home/teto/nixops/nixops/deployment.py", line 653, in build_configs
raise Exception("unable to build all machine configurations")
Exception: unable to build all machine configurations
This simple addition allows to override it.
2018-02-17 06:47:33 +00:00
|
|
|
|
boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
|
2013-07-23 18:43:11 +00:00
|
|
|
|
|
2016-01-04 12:59:53 +00:00
|
|
|
|
boot.kernelModules = [ "loop" "atkbd" ];
|
2009-12-15 16:38:20 +00:00
|
|
|
|
|
|
|
|
|
boot.initrd.availableKernelModules =
|
|
|
|
|
[ # Note: most of these (especially the SATA/PATA modules)
|
2017-02-17 23:40:54 +00:00
|
|
|
|
# shouldn't be included by default since nixos-generate-config
|
2009-12-15 14:10:06 +00:00
|
|
|
|
# detects them, but I'm keeping them for now for backwards
|
|
|
|
|
# compatibility.
|
|
|
|
|
|
2011-09-07 20:36:13 +00:00
|
|
|
|
# Some SATA/PATA stuff.
|
2009-12-15 14:10:06 +00:00
|
|
|
|
"ahci"
|
|
|
|
|
"sata_nv"
|
|
|
|
|
"sata_via"
|
|
|
|
|
"sata_sis"
|
|
|
|
|
"sata_uli"
|
|
|
|
|
"ata_piix"
|
|
|
|
|
"pata_marvell"
|
|
|
|
|
|
|
|
|
|
# Standard SCSI stuff.
|
|
|
|
|
"sd_mod"
|
|
|
|
|
"sr_mod"
|
|
|
|
|
|
2015-10-16 11:20:30 +00:00
|
|
|
|
# SD cards and internal eMMC drives.
|
|
|
|
|
"mmc_block"
|
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
# Support USB keyboards, in case the boot fails and we only have
|
2018-01-06 16:57:06 +00:00
|
|
|
|
# a USB keyboard, or for LUKS passphrase prompt.
|
2009-12-15 14:10:06 +00:00
|
|
|
|
"uhci_hcd"
|
|
|
|
|
"ehci_hcd"
|
2013-05-14 12:23:53 +00:00
|
|
|
|
"ehci_pci"
|
2009-12-15 14:10:06 +00:00
|
|
|
|
"ohci_hcd"
|
2014-04-13 06:58:08 +00:00
|
|
|
|
"ohci_pci"
|
2013-05-04 15:35:01 +00:00
|
|
|
|
"xhci_hcd"
|
2015-02-09 21:09:05 +00:00
|
|
|
|
"xhci_pci"
|
2009-12-15 14:10:06 +00:00
|
|
|
|
"usbhid"
|
2018-02-03 09:45:09 +00:00
|
|
|
|
"hid_generic" "hid_lenovo" "hid_apple" "hid_roccat"
|
|
|
|
|
"hid_logitech_hidpp" "hid_logitech_dj"
|
2009-12-15 14:10:06 +00:00
|
|
|
|
|
2017-12-06 18:25:06 +00:00
|
|
|
|
] ++ optionals (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
|
|
|
|
|
# Misc. x86 keyboard stuff.
|
2016-10-21 12:27:11 +00:00
|
|
|
|
"pcips2" "atkbd" "i8042"
|
2012-04-06 14:20:43 +00:00
|
|
|
|
|
2017-12-06 18:25:06 +00:00
|
|
|
|
# x86 RTC needed by the stage 2 init script.
|
2014-03-18 22:14:34 +00:00
|
|
|
|
"rtc_cmos"
|
2009-12-15 14:10:06 +00:00
|
|
|
|
];
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2009-12-15 16:38:20 +00:00
|
|
|
|
boot.initrd.kernelModules =
|
|
|
|
|
[ # For LVM.
|
|
|
|
|
"dm_mod"
|
|
|
|
|
];
|
2009-01-25 15:48:48 +00:00
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
# The Linux kernel >= 2.6.27 provides firmware.
|
2015-08-24 22:27:06 +00:00
|
|
|
|
hardware.firmware = [ kernel ];
|
2009-12-15 13:09:06 +00:00
|
|
|
|
|
2012-08-06 20:52:08 +00:00
|
|
|
|
# Create /etc/modules-load.d/nixos.conf, which is read by
|
|
|
|
|
# systemd-modules-load.service to load required kernel modules.
|
2019-09-14 17:51:29 +00:00
|
|
|
|
environment.etc =
|
|
|
|
|
{ "modules-load.d/nixos.conf".source = kernelModulesConf;
|
2012-10-11 21:58:46 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-08-13 21:52:01 +00:00
|
|
|
|
systemd.services.systemd-modules-load =
|
2014-04-17 16:52:31 +00:00
|
|
|
|
{ wantedBy = [ "multi-user.target" ];
|
|
|
|
|
restartTriggers = [ kernelModulesConf ];
|
2012-10-11 21:58:46 +00:00
|
|
|
|
serviceConfig =
|
2014-04-17 16:52:31 +00:00
|
|
|
|
{ # Ignore failed module loads. Typically some of the
|
2012-10-12 21:39:06 +00:00
|
|
|
|
# modules in ‘boot.kernelModules’ are "nice to have but
|
|
|
|
|
# not required" (e.g. acpi-cpufreq), so we don't want to
|
|
|
|
|
# barf on those.
|
|
|
|
|
SuccessExitStatus = "0 1";
|
2012-10-11 21:58:46 +00:00
|
|
|
|
};
|
2014-04-17 16:52:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-02 01:50:43 +00:00
|
|
|
|
lib.kernelConfig = {
|
|
|
|
|
isYes = option: {
|
|
|
|
|
assertion = config: config.isYes option;
|
|
|
|
|
message = "CONFIG_${option} is not yes!";
|
2012-08-02 02:32:16 +00:00
|
|
|
|
configLine = "CONFIG_${option}=y";
|
2012-08-02 01:50:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isNo = option: {
|
|
|
|
|
assertion = config: config.isNo option;
|
|
|
|
|
message = "CONFIG_${option} is not no!";
|
2012-08-02 02:32:16 +00:00
|
|
|
|
configLine = "CONFIG_${option}=n";
|
2012-08-02 01:50:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isModule = option: {
|
|
|
|
|
assertion = config: config.isModule option;
|
|
|
|
|
message = "CONFIG_${option} is not built as a module!";
|
2012-08-02 02:32:16 +00:00
|
|
|
|
configLine = "CONFIG_${option}=m";
|
2012-08-02 01:50:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
### Usually you will just want to use these two
|
|
|
|
|
# True if yes or module
|
|
|
|
|
isEnabled = option: {
|
|
|
|
|
assertion = config: config.isEnabled option;
|
|
|
|
|
message = "CONFIG_${option} is not enabled!";
|
2012-08-02 02:32:16 +00:00
|
|
|
|
configLine = "CONFIG_${option}=y";
|
2012-08-02 01:50:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# True if no or omitted
|
|
|
|
|
isDisabled = option: {
|
|
|
|
|
assertion = config: config.isDisabled option;
|
|
|
|
|
message = "CONFIG_${option} is not disabled!";
|
2012-08-02 02:32:16 +00:00
|
|
|
|
configLine = "CONFIG_${option}=n";
|
2012-08-02 01:50:43 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2012-08-02 01:50:43 +00:00
|
|
|
|
# The config options that all modules can depend upon
|
|
|
|
|
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
2012-08-07 22:09:08 +00:00
|
|
|
|
# !!! Should this really be needed?
|
2012-08-02 01:50:43 +00:00
|
|
|
|
(isYes "MODULES")
|
2012-08-02 04:47:36 +00:00
|
|
|
|
(isYes "BINFMT_ELF")
|
2019-01-12 00:35:18 +00:00
|
|
|
|
] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
|
2012-08-02 01:50:43 +00:00
|
|
|
|
|
|
|
|
|
# nixpkgs kernels are assumed to have all required features
|
|
|
|
|
assertions = if config.boot.kernelPackages.kernel ? features then [] else
|
|
|
|
|
let cfg = config.boot.kernelPackages.kernel.config; in map (attrs:
|
|
|
|
|
{ assertion = attrs.assertion cfg; inherit (attrs) message; }
|
|
|
|
|
) config.system.requiredKernelConfig;
|
|
|
|
|
|
2009-12-15 14:10:06 +00:00
|
|
|
|
};
|
2011-09-07 20:36:13 +00:00
|
|
|
|
|
2009-01-25 15:48:48 +00:00
|
|
|
|
}
|