2009-11-08 10:01:53 +01:00
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-01-25 16:48:48 +01:00
|
|
|
|
|
2012-10-11 23:58:46 +02:00
|
|
|
|
let
|
|
|
|
|
|
|
|
|
|
kernel = config.boot.kernelPackages.kernel;
|
|
|
|
|
|
|
|
|
|
kernelModulesConf = pkgs.writeText "nixos.conf"
|
|
|
|
|
''
|
|
|
|
|
${concatStringsSep "\n" config.boot.kernelModules}
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
in
|
2009-12-15 15:10:06 +01:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
###### interface
|
2009-01-25 16:48:48 +01:00
|
|
|
|
|
|
|
|
|
options = {
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2009-12-15 15:10:06 +01:00
|
|
|
|
boot.kernelPackages = mkOption {
|
2010-03-16 13:10:06 +01:00
|
|
|
|
default = pkgs.linuxPackages;
|
2010-05-28 13:21:40 +02: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 17:37:45 +01:00
|
|
|
|
example = literalExample "pkgs.linuxPackages_2_6_25";
|
2009-12-15 15:10:06 +01: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>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
boot.kernelParams = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.str;
|
2010-01-05 14:11:12 +01:00
|
|
|
|
default = [ ];
|
2013-10-30 17:37:45 +01:00
|
|
|
|
description = "Parameters added to the kernel command line.";
|
2009-12-15 15:10:06 +01:00
|
|
|
|
};
|
|
|
|
|
|
2013-07-23 20:43:11 +02:00
|
|
|
|
boot.consoleLogLevel = mkOption {
|
|
|
|
|
type = types.int;
|
|
|
|
|
default = 4;
|
|
|
|
|
description = ''
|
|
|
|
|
The kernel console log level. Only log messages with a
|
|
|
|
|
priority numerically less than this will appear on the
|
|
|
|
|
console.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-15 22:55:51 +01:00
|
|
|
|
boot.vesa = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.bool;
|
2013-09-26 17:33:52 +02:00
|
|
|
|
default = false;
|
2010-01-15 22:55:51 +01:00
|
|
|
|
description = ''
|
2011-09-02 15:19:45 +02:00
|
|
|
|
Whether to activate VESA video mode on boot.
|
2010-01-15 22:55:51 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 15:10:06 +01:00
|
|
|
|
boot.extraModulePackages = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.path;
|
2009-12-15 15:10:06 +01:00
|
|
|
|
default = [];
|
2013-10-30 17:37:45 +01:00
|
|
|
|
example = literalExample "[ pkgs.linuxPackages.nvidia_x11 ]";
|
2009-12-15 15:10:06 +01:00
|
|
|
|
description = "A list of additional packages supplying kernel modules.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
boot.kernelModules = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.str;
|
2009-12-15 15:10:06 +01: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 17:38:20 +01:00
|
|
|
|
<option>boot.initrd.availableKernelModules</option> or
|
2009-12-15 15:10:06 +01:00
|
|
|
|
<option>boot.initrd.kernelModules</option>.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
boot.initrd.availableKernelModules = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.str;
|
2009-12-15 17:38:20 +01: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 22:36:13 +02:00
|
|
|
|
|
2009-12-15 15:10:06 +01:00
|
|
|
|
boot.initrd.kernelModules = mkOption {
|
2013-10-30 17:37:45 +01:00
|
|
|
|
type = types.listOf types.str;
|
2011-09-02 15:19:45 +02:00
|
|
|
|
default = [];
|
2009-12-15 17:38:20 +01:00
|
|
|
|
description = "List of modules that are always loaded by the initrd.";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
system.modulesTree = mkOption {
|
2013-10-28 16:14:15 +01:00
|
|
|
|
type = types.listOf types.path;
|
2009-12-15 17:38:20 +01: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 03:50:43 +02: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 17:38:20 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
|
|
system.build = { inherit kernel; };
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
|
|
|
|
|
|
2013-07-23 20:43:11 +02: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 14:11:12 +01:00
|
|
|
|
boot.kernelParams =
|
2013-07-23 20:43:11 +02:00
|
|
|
|
[ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
|
2013-09-26 17:33:52 +02:00
|
|
|
|
optionals config.boot.vesa [ "vga=0x317" ];
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2013-07-23 20:43:11 +02:00
|
|
|
|
boot.kernel.sysctl."kernel.printk" = config.boot.consoleLogLevel;
|
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
boot.kernelModules = [ "loop" ];
|
|
|
|
|
|
|
|
|
|
boot.initrd.availableKernelModules =
|
|
|
|
|
[ # Note: most of these (especially the SATA/PATA modules)
|
2009-12-15 15:10:06 +01:00
|
|
|
|
# shouldn't be included by default since nixos-hardware-scan
|
|
|
|
|
# detects them, but I'm keeping them for now for backwards
|
|
|
|
|
# compatibility.
|
|
|
|
|
|
2011-09-07 22:36:13 +02:00
|
|
|
|
# Some SATA/PATA stuff.
|
2009-12-15 15:10:06 +01:00
|
|
|
|
"ahci"
|
|
|
|
|
"sata_nv"
|
|
|
|
|
"sata_via"
|
|
|
|
|
"sata_sis"
|
|
|
|
|
"sata_uli"
|
|
|
|
|
"ata_piix"
|
|
|
|
|
"pata_marvell"
|
|
|
|
|
|
|
|
|
|
# Standard SCSI stuff.
|
|
|
|
|
"sd_mod"
|
|
|
|
|
"sr_mod"
|
|
|
|
|
|
|
|
|
|
# Standard IDE stuff.
|
|
|
|
|
"ide_cd"
|
|
|
|
|
"ide_disk"
|
|
|
|
|
"ide_generic"
|
|
|
|
|
|
|
|
|
|
# Support USB keyboards, in case the boot fails and we only have
|
|
|
|
|
# a USB keyboard.
|
|
|
|
|
"uhci_hcd"
|
|
|
|
|
"ehci_hcd"
|
2013-05-14 14:23:53 +02:00
|
|
|
|
"ehci_pci"
|
2009-12-15 15:10:06 +01:00
|
|
|
|
"ohci_hcd"
|
2013-05-04 17:35:01 +02:00
|
|
|
|
"xhci_hcd"
|
2009-12-15 15:10:06 +01:00
|
|
|
|
"usbhid"
|
2013-05-14 14:23:53 +02:00
|
|
|
|
"hid_generic"
|
2009-12-15 15:10:06 +01:00
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
# Unix domain sockets (needed by udev).
|
2009-12-15 15:10:06 +01:00
|
|
|
|
"unix"
|
2011-09-02 15:19:45 +02:00
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
# Misc. stuff.
|
2013-05-14 14:24:29 +02:00
|
|
|
|
"pcips2" "xtkbd"
|
2012-04-06 16:20:43 +02:00
|
|
|
|
|
|
|
|
|
# To wait for SCSI devices to appear.
|
|
|
|
|
"scsi_wait_scan"
|
2009-12-15 15:10:06 +01:00
|
|
|
|
];
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2009-12-15 17:38:20 +01:00
|
|
|
|
boot.initrd.kernelModules =
|
|
|
|
|
[ # For LVM.
|
|
|
|
|
"dm_mod"
|
|
|
|
|
];
|
2009-01-25 16:48:48 +01:00
|
|
|
|
|
2009-12-15 15:10:06 +01:00
|
|
|
|
# The Linux kernel >= 2.6.27 provides firmware.
|
|
|
|
|
hardware.firmware = [ "${kernel}/lib/firmware" ];
|
2009-12-15 14:09:06 +01:00
|
|
|
|
|
2012-08-06 22:52:08 +02:00
|
|
|
|
# Create /etc/modules-load.d/nixos.conf, which is read by
|
|
|
|
|
# systemd-modules-load.service to load required kernel modules.
|
|
|
|
|
# FIXME: ensure that systemd-modules-load.service is restarted if
|
|
|
|
|
# this file changes.
|
|
|
|
|
environment.etc = singleton
|
|
|
|
|
{ target = "modules-load.d/nixos.conf";
|
2012-10-11 23:58:46 +02:00
|
|
|
|
source = kernelModulesConf;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# Sigh. This overrides systemd's systemd-modules-load.service
|
|
|
|
|
# just so we can set a restart trigger. Also make
|
|
|
|
|
# multi-user.target pull it in so that it gets started if it
|
|
|
|
|
# failed earlier.
|
2013-01-16 12:33:18 +01:00
|
|
|
|
systemd.services."systemd-modules-load" =
|
2012-10-11 23:58:46 +02:00
|
|
|
|
{ description = "Load Kernel Modules";
|
|
|
|
|
wantedBy = [ "sysinit.target" "multi-user.target" ];
|
|
|
|
|
before = [ "sysinit.target" "shutdown.target" ];
|
2013-11-18 15:42:05 +01:00
|
|
|
|
conflicts = [ "shutdown.target" ];
|
|
|
|
|
unitConfig.DefaultDependencies = "no";
|
2012-10-11 23:58:46 +02:00
|
|
|
|
serviceConfig =
|
|
|
|
|
{ Type = "oneshot";
|
|
|
|
|
RemainAfterExit = true;
|
2013-01-16 13:17:57 +01:00
|
|
|
|
ExecStart = "${config.systemd.package}/lib/systemd/systemd-modules-load";
|
2012-10-12 23:39:06 +02:00
|
|
|
|
# Ignore failed module loads. Typically some of the
|
|
|
|
|
# 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 23:58:46 +02:00
|
|
|
|
};
|
|
|
|
|
restartTriggers = [ kernelModulesConf ];
|
2012-08-06 22:52:08 +02:00
|
|
|
|
};
|
|
|
|
|
|
2012-08-02 03:50:43 +02:00
|
|
|
|
lib.kernelConfig = {
|
|
|
|
|
isYes = option: {
|
|
|
|
|
assertion = config: config.isYes option;
|
|
|
|
|
message = "CONFIG_${option} is not yes!";
|
2012-08-02 04:32:16 +02:00
|
|
|
|
configLine = "CONFIG_${option}=y";
|
2012-08-02 03:50:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isNo = option: {
|
|
|
|
|
assertion = config: config.isNo option;
|
|
|
|
|
message = "CONFIG_${option} is not no!";
|
2012-08-02 04:32:16 +02:00
|
|
|
|
configLine = "CONFIG_${option}=n";
|
2012-08-02 03:50:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isModule = option: {
|
|
|
|
|
assertion = config: config.isModule option;
|
|
|
|
|
message = "CONFIG_${option} is not built as a module!";
|
2012-08-02 04:32:16 +02:00
|
|
|
|
configLine = "CONFIG_${option}=m";
|
2012-08-02 03:50:43 +02: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 04:32:16 +02:00
|
|
|
|
configLine = "CONFIG_${option}=y";
|
2012-08-02 03:50:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# True if no or omitted
|
|
|
|
|
isDisabled = option: {
|
|
|
|
|
assertion = config: config.isDisabled option;
|
|
|
|
|
message = "CONFIG_${option} is not disabled!";
|
2012-08-02 04:32:16 +02:00
|
|
|
|
configLine = "CONFIG_${option}=n";
|
2012-08-02 03:50:43 +02:00
|
|
|
|
};
|
|
|
|
|
};
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2012-08-02 03:50:43 +02:00
|
|
|
|
# The config options that all modules can depend upon
|
|
|
|
|
system.requiredKernelConfig = with config.lib.kernelConfig; [
|
2012-08-08 00:09:08 +02:00
|
|
|
|
# !!! Should this really be needed?
|
2012-08-02 03:50:43 +02:00
|
|
|
|
(isYes "MODULES")
|
2012-08-02 06:47:36 +02:00
|
|
|
|
(isYes "BINFMT_ELF")
|
2012-08-02 03:50:43 +02: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 15:10:06 +01:00
|
|
|
|
};
|
2011-09-07 22:36:13 +02:00
|
|
|
|
|
2009-01-25 16:48:48 +01:00
|
|
|
|
}
|