summaryrefslogtreecommitdiffstats
path: root/nixos/modules/system
diff options
context:
space:
mode:
authorrnhmjoj <rnhmjoj@inventati.org>2020-02-14 14:11:33 +0100
committerrnhmjoj <rnhmjoj@inventati.org>2020-02-15 12:13:33 +0100
commitdea79b56f7218ba75653260232c07d2f5ad2f109 (patch)
tree24555f8024e8cafd6a89d2db6a3c24ce4a37a2dc /nixos/modules/system
parent3b7f5c6762bb174bd9951a697b636e1db531e98a (diff)
nixos/boot: add option to disable initrd
Diffstat (limited to 'nixos/modules/system')
-rw-r--r--nixos/modules/system/boot/kernel.nix265
-rw-r--r--nixos/modules/system/boot/stage-1.nix13
2 files changed, 147 insertions, 131 deletions
diff --git a/nixos/modules/system/boot/kernel.nix b/nixos/modules/system/boot/kernel.nix
index 6edb9082e75a..7ca63a88b3db 100644
--- a/nixos/modules/system/boot/kernel.nix
+++ b/nixos/modules/system/boot/kernel.nix
@@ -187,139 +187,144 @@ in
###### implementation
- config = mkIf (!config.boot.isContainer) {
-
- system.build = { inherit kernel; };
-
- system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
-
- # Implement consoleLogLevel both in early boot and using sysctl
- # (so you don't need to reboot to have changes take effect).
- boot.kernelParams =
- [ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
- optionals config.boot.vesa [ "vga=0x317" "nomodeset" ];
-
- boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
-
- boot.kernelModules = [ "loop" "atkbd" ];
-
- boot.initrd.availableKernelModules =
- [ # Note: most of these (especially the SATA/PATA modules)
- # shouldn't be included by default since nixos-generate-config
- # detects them, but I'm keeping them for now for backwards
- # compatibility.
-
- # Some SATA/PATA stuff.
- "ahci"
- "sata_nv"
- "sata_via"
- "sata_sis"
- "sata_uli"
- "ata_piix"
- "pata_marvell"
-
- # Standard SCSI stuff.
- "sd_mod"
- "sr_mod"
-
- # SD cards and internal eMMC drives.
- "mmc_block"
-
- # Support USB keyboards, in case the boot fails and we only have
- # a USB keyboard, or for LUKS passphrase prompt.
- "uhci_hcd"
- "ehci_hcd"
- "ehci_pci"
- "ohci_hcd"
- "ohci_pci"
- "xhci_hcd"
- "xhci_pci"
- "usbhid"
- "hid_generic" "hid_lenovo" "hid_apple" "hid_roccat"
- "hid_logitech_hidpp" "hid_logitech_dj"
-
- ] ++ optionals (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
- # Misc. x86 keyboard stuff.
- "pcips2" "atkbd" "i8042"
-
- # x86 RTC needed by the stage 2 init script.
- "rtc_cmos"
- ];
-
- boot.initrd.kernelModules =
- [ # For LVM.
- "dm_mod"
- ];
-
- # The Linux kernel >= 2.6.27 provides firmware.
- hardware.firmware = [ kernel ];
-
- # Create /etc/modules-load.d/nixos.conf, which is read by
- # systemd-modules-load.service to load required kernel modules.
- environment.etc =
- { "modules-load.d/nixos.conf".source = kernelModulesConf;
- };
-
- systemd.services.systemd-modules-load =
- { wantedBy = [ "multi-user.target" ];
- restartTriggers = [ kernelModulesConf ];
- serviceConfig =
- { # 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";
+ config = mkMerge
+ [ (mkIf config.boot.initrd.enable {
+ boot.initrd.availableKernelModules =
+ [ # Note: most of these (especially the SATA/PATA modules)
+ # shouldn't be included by default since nixos-generate-config
+ # detects them, but I'm keeping them for now for backwards
+ # compatibility.
+
+ # Some SATA/PATA stuff.
+ "ahci"
+ "sata_nv"
+ "sata_via"
+ "sata_sis"
+ "sata_uli"
+ "ata_piix"
+ "pata_marvell"
+
+ # Standard SCSI stuff.
+ "sd_mod"
+ "sr_mod"
+
+ # SD cards and internal eMMC drives.
+ "mmc_block"
+
+ # Support USB keyboards, in case the boot fails and we only have
+ # a USB keyboard, or for LUKS passphrase prompt.
+ "uhci_hcd"
+ "ehci_hcd"
+ "ehci_pci"
+ "ohci_hcd"
+ "ohci_pci"
+ "xhci_hcd"
+ "xhci_pci"
+ "usbhid"
+ "hid_generic" "hid_lenovo" "hid_apple" "hid_roccat"
+ "hid_logitech_hidpp" "hid_logitech_dj"
+
+ ] ++ optionals (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
+ # Misc. x86 keyboard stuff.
+ "pcips2" "atkbd" "i8042"
+
+ # x86 RTC needed by the stage 2 init script.
+ "rtc_cmos"
+ ];
+
+ boot.initrd.kernelModules =
+ [ # For LVM.
+ "dm_mod"
+ ];
+ })
+
+ (mkIf (!config.boot.isContainer) {
+ system.build = { inherit kernel; };
+
+ system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
+
+ # Implement consoleLogLevel both in early boot and using sysctl
+ # (so you don't need to reboot to have changes take effect).
+ boot.kernelParams =
+ [ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
+ optionals config.boot.vesa [ "vga=0x317" "nomodeset" ];
+
+ boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
+
+ boot.kernelModules = [ "loop" "atkbd" ];
+
+ # The Linux kernel >= 2.6.27 provides firmware.
+ hardware.firmware = [ kernel ];
+
+ # Create /etc/modules-load.d/nixos.conf, which is read by
+ # systemd-modules-load.service to load required kernel modules.
+ environment.etc =
+ { "modules-load.d/nixos.conf".source = kernelModulesConf;
};
- };
-
- lib.kernelConfig = {
- isYes = option: {
- assertion = config: config.isYes option;
- message = "CONFIG_${option} is not yes!";
- configLine = "CONFIG_${option}=y";
- };
-
- isNo = option: {
- assertion = config: config.isNo option;
- message = "CONFIG_${option} is not no!";
- configLine = "CONFIG_${option}=n";
- };
-
- isModule = option: {
- assertion = config: config.isModule option;
- message = "CONFIG_${option} is not built as a module!";
- configLine = "CONFIG_${option}=m";
- };
-
- ### 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!";
- configLine = "CONFIG_${option}=y";
- };
-
- # True if no or omitted
- isDisabled = option: {
- assertion = config: config.isDisabled option;
- message = "CONFIG_${option} is not disabled!";
- configLine = "CONFIG_${option}=n";
- };
- };
- # The config options that all modules can depend upon
- system.requiredKernelConfig = with config.lib.kernelConfig; [
- # !!! Should this really be needed?
- (isYes "MODULES")
- (isYes "BINFMT_ELF")
- ] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
+ systemd.services.systemd-modules-load =
+ { wantedBy = [ "multi-user.target" ];
+ restartTriggers = [ kernelModulesConf ];
+ serviceConfig =
+ { # 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";
+ };
+ };
- # 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;
+ lib.kernelConfig = {
+ isYes = option: {
+ assertion = config: config.isYes option;
+ message = "CONFIG_${option} is not yes!";
+ configLine = "CONFIG_${option}=y";
+ };
- };
+ isNo = option: {
+ assertion = config: config.isNo option;
+ message = "CONFIG_${option} is not no!";
+ configLine = "CONFIG_${option}=n";
+ };
+
+ isModule = option: {
+ assertion = config: config.isModule option;
+ message = "CONFIG_${option} is not built as a module!";
+ configLine = "CONFIG_${option}=m";
+ };
+
+ ### 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!";
+ configLine = "CONFIG_${option}=y";
+ };
+
+ # True if no or omitted
+ isDisabled = option: {
+ assertion = config: config.isDisabled option;
+ message = "CONFIG_${option} is not disabled!";
+ configLine = "CONFIG_${option}=n";
+ };
+ };
+
+ # The config options that all modules can depend upon
+ system.requiredKernelConfig = with config.lib.kernelConfig;
+ [
+ # !!! Should this really be needed?
+ (isYes "MODULES")
+ (isYes "BINFMT_ELF")
+ ] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT"));
+
+ # 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;
+
+ })
+
+ ];
}
diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix
index 4c2d130d5a5d..524553bfdaff 100644
--- a/nixos/modules/system/boot/stage-1.nix
+++ b/nixos/modules/system/boot/stage-1.nix
@@ -379,6 +379,17 @@ in
'';
};
+ boot.initrd.enable = mkOption {
+ type = types.bool;
+ default = !config.boot.isContainer;
+ defaultText = "!config.boot.isContainer";
+ description = ''
+ Whether to enable the NixOS initial RAM disk (initrd). This may be
+ needed to perform some initialisation tasks (like mounting
+ network/encrypted file systems) before continuing the boot process.
+ '';
+ };
+
boot.initrd.prepend = mkOption {
default = [ ];
type = types.listOf types.str;
@@ -544,7 +555,7 @@ in
};
- config = mkIf (!config.boot.isContainer) {
+ config = mkIf config.boot.initrd.enable {
assertions = [
{ assertion = any (fs: fs.mountPoint == "/") fileSystems;
message = "The ‘fileSystems’ option does not specify your root file system.";