0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

Merge pull request #80114 from rnhmjoj/initrd

nixos/boot: add option to disable initrd
This commit is contained in:
Danylo Hlynskyi 2020-03-16 20:04:24 +02:00 committed by GitHub
commit fab05f17d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 128 additions and 112 deletions

View file

@ -192,139 +192,144 @@ in
###### implementation ###### implementation
config = mkIf (!config.boot.isContainer) { 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.
system.build = { inherit kernel; }; # Some SATA/PATA stuff.
"ahci"
"sata_nv"
"sata_via"
"sata_sis"
"sata_uli"
"ata_piix"
"pata_marvell"
system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; # Standard SCSI stuff.
"sd_mod"
"sr_mod"
# Implement consoleLogLevel both in early boot and using sysctl # SD cards and internal eMMC drives.
# (so you don't need to reboot to have changes take effect). "mmc_block"
boot.kernelParams =
[ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
optionals config.boot.vesa [ "vga=0x317" "nomodeset" ];
boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel; # 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"
boot.kernelModules = [ "loop" "atkbd" ]; ] ++ optionals (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
# Misc. x86 keyboard stuff.
"pcips2" "atkbd" "i8042"
boot.initrd.availableKernelModules = # x86 RTC needed by the stage 2 init script.
[ # Note: most of these (especially the SATA/PATA modules) "rtc_cmos"
# 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. boot.initrd.kernelModules =
"ahci" [ # For LVM.
"sata_nv" "dm_mod"
"sata_via" ];
"sata_sis" })
"sata_uli"
"ata_piix"
"pata_marvell"
# Standard SCSI stuff. (mkIf (!config.boot.isContainer) {
"sd_mod" system.build = { inherit kernel; };
"sr_mod"
# SD cards and internal eMMC drives. system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages;
"mmc_block"
# Support USB keyboards, in case the boot fails and we only have # Implement consoleLogLevel both in early boot and using sysctl
# a USB keyboard, or for LUKS passphrase prompt. # (so you don't need to reboot to have changes take effect).
"uhci_hcd" boot.kernelParams =
"ehci_hcd" [ "loglevel=${toString config.boot.consoleLogLevel}" ] ++
"ehci_pci" optionals config.boot.vesa [ "vga=0x317" "nomodeset" ];
"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) [ boot.kernel.sysctl."kernel.printk" = mkDefault config.boot.consoleLogLevel;
# Misc. x86 keyboard stuff.
"pcips2" "atkbd" "i8042"
# x86 RTC needed by the stage 2 init script. boot.kernelModules = [ "loop" "atkbd" ];
"rtc_cmos"
];
boot.initrd.kernelModules = # The Linux kernel >= 2.6.27 provides firmware.
[ # For LVM. hardware.firmware = [ kernel ];
"dm_mod"
];
# The Linux kernel >= 2.6.27 provides firmware. # Create /etc/modules-load.d/nixos.conf, which is read by
hardware.firmware = [ kernel ]; # systemd-modules-load.service to load required kernel modules.
environment.etc =
# Create /etc/modules-load.d/nixos.conf, which is read by { "modules-load.d/nixos.conf".source = kernelModulesConf;
# 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";
}; };
};
lib.kernelConfig = { systemd.services.systemd-modules-load =
isYes = option: { { wantedBy = [ "multi-user.target" ];
assertion = config: config.isYes option; restartTriggers = [ kernelModulesConf ];
message = "CONFIG_${option} is not yes!"; serviceConfig =
configLine = "CONFIG_${option}=y"; { # 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";
};
};
isNo = option: { lib.kernelConfig = {
assertion = config: config.isNo option; isYes = option: {
message = "CONFIG_${option} is not no!"; assertion = config: config.isYes option;
configLine = "CONFIG_${option}=n"; message = "CONFIG_${option} is not yes!";
}; configLine = "CONFIG_${option}=y";
};
isModule = option: { isNo = option: {
assertion = config: config.isModule option; assertion = config: config.isNo option;
message = "CONFIG_${option} is not built as a module!"; message = "CONFIG_${option} is not no!";
configLine = "CONFIG_${option}=m"; configLine = "CONFIG_${option}=n";
}; };
### Usually you will just want to use these two isModule = option: {
# True if yes or module assertion = config: config.isModule option;
isEnabled = option: { message = "CONFIG_${option} is not built as a module!";
assertion = config: config.isEnabled option; configLine = "CONFIG_${option}=m";
message = "CONFIG_${option} is not enabled!"; };
configLine = "CONFIG_${option}=y";
};
# True if no or omitted ### Usually you will just want to use these two
isDisabled = option: { # True if yes or module
assertion = config: config.isDisabled option; isEnabled = option: {
message = "CONFIG_${option} is not disabled!"; assertion = config: config.isEnabled option;
configLine = "CONFIG_${option}=n"; message = "CONFIG_${option} is not enabled!";
}; configLine = "CONFIG_${option}=y";
}; };
# The config options that all modules can depend upon # True if no or omitted
system.requiredKernelConfig = with config.lib.kernelConfig; [ isDisabled = option: {
# !!! Should this really be needed? assertion = config: config.isDisabled option;
(isYes "MODULES") message = "CONFIG_${option} is not disabled!";
(isYes "BINFMT_ELF") configLine = "CONFIG_${option}=n";
] ++ (optional (randstructSeed != "") (isYes "GCC_PLUGIN_RANDSTRUCT")); };
};
# nixpkgs kernels are assumed to have all required features # The config options that all modules can depend upon
assertions = if config.boot.kernelPackages.kernel ? features then [] else system.requiredKernelConfig = with config.lib.kernelConfig;
let cfg = config.boot.kernelPackages.kernel.config; in map (attrs: [
{ assertion = attrs.assertion cfg; inherit (attrs) message; } # !!! Should this really be needed?
) config.system.requiredKernelConfig; (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;
})
];
} }

View file

@ -390,6 +390,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 { boot.initrd.prepend = mkOption {
default = [ ]; default = [ ];
type = types.listOf types.str; type = types.listOf types.str;
@ -555,7 +566,7 @@ in
}; };
config = mkIf (!config.boot.isContainer) { config = mkIf config.boot.initrd.enable {
assertions = [ assertions = [
{ assertion = any (fs: fs.mountPoint == "/") fileSystems; { assertion = any (fs: fs.mountPoint == "/") fileSystems;
message = "The fileSystems option does not specify your root file system."; message = "The fileSystems option does not specify your root file system.";