diff options
Diffstat (limited to 'nixpkgs/nixos/modules/system/boot')
5 files changed, 133 insertions, 59 deletions
diff --git a/nixpkgs/nixos/modules/system/boot/kernel.nix b/nixpkgs/nixos/modules/system/boot/kernel.nix index 0298e28f3289..9ea611919676 100644 --- a/nixpkgs/nixos/modules/system/boot/kernel.nix +++ b/nixpkgs/nixos/modules/system/boot/kernel.nix @@ -309,6 +309,38 @@ in system.modulesTree = [ kernel ] ++ config.boot.extraModulePackages; + # Not required for, e.g., containers as they don't have their own kernel or initrd. + # They boot directly into stage 2. + system.systemBuilderArgs.kernelParams = config.boot.kernelParams; + system.systemBuilderCommands = + let + kernelPath = "${config.boot.kernelPackages.kernel}/" + + "${config.system.boot.loader.kernelFile}"; + initrdPath = "${config.system.build.initialRamdisk}/" + + "${config.system.boot.loader.initrdFile}"; + in + '' + if [ ! -f ${kernelPath} ]; then + echo "The bootloader cannot find the proper kernel image." + echo "(Expecting ${kernelPath})" + false + fi + + ln -s ${kernelPath} $out/kernel + ln -s ${config.system.modulesTree} $out/kernel-modules + ${optionalString (config.hardware.deviceTree.package != null) '' + ln -s ${config.hardware.deviceTree.package} $out/dtbs + ''} + + echo -n "$kernelParams" > $out/kernel-params + + ln -s ${initrdPath} $out/initrd + + ln -s ${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets $out + + ln -s ${config.hardware.firmware}/lib/firmware $out/firmware + ''; + # Implement consoleLogLevel both in early boot and using sysctl # (so you don't need to reboot to have changes take effect). boot.kernelParams = diff --git a/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix b/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix index 8f2f578e3070..468f701ae5bc 100644 --- a/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixpkgs/nixos/modules/system/boot/loader/grub/grub.nix @@ -1,8 +1,32 @@ { config, options, lib, pkgs, ... }: -with lib; - let + inherit (lib) + all + concatMap + concatMapStrings + concatStrings + concatStringsSep + escapeShellArg + flip + foldr + forEach + hasPrefix + mapAttrsToList + literalExpression + makeBinPath + mkDefault + mkIf + mkMerge + mkOption + mkRemovedOptionModule + mkRenamedOptionModule + optional + optionals + optionalString + replaceStrings + types + ; cfg = config.boot.loader.grub; @@ -63,7 +87,9 @@ let extraGrubInstallArgs extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels default fsIdentifier efiSupport efiInstallAsRemovable gfxmodeEfi gfxmodeBios gfxpayloadEfi gfxpayloadBios - users; + users + timeoutStyle + ; path = with pkgs; makeBinPath ( [ coreutils gnused gnugrep findutils diffutils btrfs-progs util-linux mdadm ] ++ optional cfg.efiSupport efibootmgr @@ -148,7 +174,7 @@ in (as opposed to external files) will be copied into the Nix store, and will be visible to all local users. ''; - type = with types; attrsOf (submodule { + type = types.attrsOf (types.submodule { options = { hashedPasswordFile = mkOption { example = "/path/to/file"; @@ -425,6 +451,28 @@ in ''; }; + timeoutStyle = mkOption { + default = "menu"; + type = types.enum [ "menu" "countdown" "hidden" ]; + description = lib.mdDoc '' + - `menu` shows the menu. + - `countdown` uses a text-mode countdown. + - `hidden` hides GRUB entirely. + + When using a theme, the default value (`menu`) is appropriate for the graphical countdown. + + When attempting to do flicker-free boot, `hidden` should be used. + + See the [GRUB documentation section about `timeout_style`](https://www.gnu.org/software/grub/manual/grub/html_node/timeout.html). + + ::: {.note} + If this option is set to ‘countdown’ or ‘hidden’ [...] and ESC or F4 are pressed, or SHIFT is held down during that time, it will display the menu and wait for input. + ::: + + From: [Simple configuration handling page, under GRUB_TIMEOUT_STYLE](https://www.gnu.org/software/grub/manual/grub/html_node/Simple-configuration.html). + ''; + }; + entryOptions = mkOption { default = "--class nixos --unrestricted"; type = types.nullOr types.str; @@ -699,7 +747,7 @@ in boot.loader.grub.extraPrepareConfig = concatStrings (mapAttrsToList (n: v: '' - ${pkgs.coreutils}/bin/cp -pf "${v}" "@bootPath@/${n}" + ${pkgs.coreutils}/bin/install -Dp "${v}" "${efi.efiSysMountPoint}/"${escapeShellArg n} '') config.boot.loader.grub.extraFiles); assertions = [ diff --git a/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl index 27f03f2fb58c..a84e374624d1 100644 --- a/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixpkgs/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -75,6 +75,7 @@ my $backgroundColor = get("backgroundColor"); my $configurationLimit = int(get("configurationLimit")); my $copyKernels = get("copyKernels") eq "true"; my $timeout = int(get("timeout")); +my $timeoutStyle = get("timeoutStyle"); my $defaultEntry = get("default"); my $fsIdentifier = get("fsIdentifier"); my $grubEfi = get("grubEfi"); @@ -319,6 +320,7 @@ $conf .= " set default=$defaultEntryText set timeout=$timeout fi + set timeout_style=$timeoutStyle function savedefault { if [ -z \"\${boot_once}\"]; then @@ -383,6 +385,31 @@ rmtree("$bootPath/theme") or die "cannot clean up theme folder in $bootPath\n" i if ($theme) { # Copy theme rcopy($theme, "$bootPath/theme") or die "cannot copy $theme to $bootPath\n"; + + # Detect which modules will need to be loaded + my $with_png = 0; + my $with_jpeg = 0; + + find({ wanted => sub { + if ($_ =~ /\.png$/i) { + $with_png = 1; + } + elsif ($_ =~ /\.jpe?g$/i) { + $with_jpeg = 1; + } + }, no_chdir => 1 }, $theme); + + if ($with_png) { + $conf .= " + insmod png + " + } + if ($with_jpeg) { + $conf .= " + insmod jpeg + " + } + $conf .= " # Sets theme. set theme=" . ($grubBoot->path eq "/" ? "" : $grubBoot->path) . "/theme/theme.txt @@ -725,9 +752,8 @@ if (($requireNewInstall != 0) && ($efiTarget eq "only" || $efiTarget eq "both")) if ($forceInstall eq "true") { push @command, "--force"; } - if ($canTouchEfiVariables eq "true") { - push @command, "--bootloader-id=$bootloaderId"; - } else { + push @command, "--bootloader-id=$bootloaderId"; + if ($canTouchEfiVariables ne "true") { push @command, "--no-nvram"; push @command, "--removable" if $efiInstallAsRemovable eq "true"; } diff --git a/nixpkgs/nixos/modules/system/boot/loader/grub/memtest.nix b/nixpkgs/nixos/modules/system/boot/loader/grub/memtest.nix index ee969e9bff5b..8e68431ac571 100644 --- a/nixpkgs/nixos/modules/system/boot/loader/grub/memtest.nix +++ b/nixpkgs/nixos/modules/system/boot/loader/grub/memtest.nix @@ -1,12 +1,10 @@ -# This module adds Memtest86+/Memtest86 to the GRUB boot menu. - +# This module adds Memtest86+ to the GRUB boot menu. { config, lib, pkgs, ... }: with lib; let memtest86 = pkgs.memtest86plus; - efiSupport = config.boot.loader.grub.efiSupport; cfg = config.boot.loader.grub.memtest86; in @@ -19,11 +17,8 @@ in default = false; type = types.bool; description = lib.mdDoc '' - Make Memtest86+ (or MemTest86 if EFI support is enabled), - a memory testing program, available from the - GRUB boot menu. MemTest86 is an unfree program, so - this requires `allowUnfree` to be set to - `true`. + Make Memtest86+, a memory testing program, available from the GRUB + boot menu. ''; }; @@ -63,34 +58,12 @@ in }; }; - config = mkMerge [ - (mkIf (cfg.enable && efiSupport) { - assertions = [ - { - assertion = cfg.params == []; - message = "Parameters are not available for MemTest86"; - } - ]; - - boot.loader.grub.extraFiles = { - "memtest86.efi" = "${pkgs.memtest86-efi}/BOOTX64.efi"; - }; - - boot.loader.grub.extraEntries = '' - menuentry "Memtest86" { - chainloader /memtest86.efi - } - ''; - }) - - (mkIf (cfg.enable && !efiSupport) { - boot.loader.grub.extraEntries = '' - menuentry "Memtest86+" { - linux16 @bootRoot@/memtest.bin ${toString cfg.params} - } - ''; - - boot.loader.grub.extraFiles."memtest.bin" = "${memtest86}/memtest.bin"; - }) - ]; + config = mkIf cfg.enable { + boot.loader.grub.extraEntries = '' + menuentry "Memtest86+" { + linux @bootRoot@/memtest.bin ${toString cfg.params} + } + ''; + boot.loader.grub.extraFiles."memtest.bin" = "${memtest86}/memtest.bin"; + }; } diff --git a/nixpkgs/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix b/nixpkgs/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix index 8a3e89e5888b..1770f0759434 100644 --- a/nixpkgs/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix +++ b/nixpkgs/nixos/modules/system/boot/loader/systemd-boot/systemd-boot.nix @@ -32,7 +32,7 @@ let inherit (config.system.nixos) distroName; - memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86-efi; + memtest86 = optionalString cfg.memtest86.enable pkgs.memtest86plus; netbootxyz = optionalString cfg.netbootxyz.enable pkgs.netbootxyz-efi; @@ -147,10 +147,8 @@ in { default = false; type = types.bool; description = lib.mdDoc '' - Make MemTest86 available from the systemd-boot menu. MemTest86 is a - program for testing memory. MemTest86 is an unfree program, so - this requires `allowUnfree` to be set to - `true`. + Make MemTest86+ available from the systemd-boot menu. MemTest86+ is a + program for testing memory. ''; }; @@ -193,8 +191,8 @@ in { default = {}; example = literalExpression '' { "memtest86.conf" = ''' - title MemTest86 - efi /efi/memtest86/memtest86.efi + title MemTest86+ + efi /efi/memtest86/memtest.efi '''; } ''; description = lib.mdDoc '' @@ -213,7 +211,7 @@ in { type = types.attrsOf types.path; default = {}; example = literalExpression '' - { "efi/memtest86/memtest86.efi" = "''${pkgs.memtest86-efi}/BOOTX64.efi"; } + { "efi/memtest86/memtest.efi" = "''${pkgs.memtest86plus}/memtest.efi"; } ''; description = lib.mdDoc '' A set of files to be copied to {file}`/boot`. @@ -276,11 +274,8 @@ in { boot.loader.supportsInitrdSecrets = true; boot.loader.systemd-boot.extraFiles = mkMerge [ - # TODO: This is hard-coded to use the 64-bit EFI app, but it could probably - # be updated to use the 32-bit EFI app on 32-bit systems. The 32-bit EFI - # app filename is BOOTIA32.efi. (mkIf cfg.memtest86.enable { - "efi/memtest86/BOOTX64.efi" = "${pkgs.memtest86-efi}/BOOTX64.efi"; + "efi/memtest86/memtest.efi" = "${pkgs.memtest86plus.efi}"; }) (mkIf cfg.netbootxyz.enable { "efi/netbootxyz/netboot.xyz.efi" = "${pkgs.netbootxyz-efi}"; @@ -291,7 +286,7 @@ in { (mkIf cfg.memtest86.enable { "${cfg.memtest86.entryFilename}" = '' title MemTest86 - efi /efi/memtest86/BOOTX64.efi + efi /efi/memtest86/memtest.efi ''; }) (mkIf cfg.netbootxyz.enable { |