From 502a19b2b47418393ff00c38622285207884d460 Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Wed, 10 Jun 2015 15:47:08 -0700 Subject: [PATCH] nixos/grub: Support labeling efi bootloaders with independent id's --- .../modules/system/boot/loader/grub/grub.nix | 21 +++++++++++++++++-- .../system/boot/loader/grub/install-grub.pl | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix index cb01774f9ab6..449f58ae4dda 100644 --- a/nixos/modules/system/boot/loader/grub/grub.nix +++ b/nixos/modules/system/boot/loader/grub/grub.nix @@ -27,7 +27,12 @@ let f = x: if x == null then "" else "" + x; - grubConfig = args: pkgs.writeText "grub-config.xml" (builtins.toXML + grubConfig = args: + let + efiSysMountPoint = if args.efiSysMountPoint == null then args.path else args.efiSysMountPoint; + efiSysMountPoint' = replaceChars [ "/" ] [ "-" ] efiSysMountPoint; + in + pkgs.writeText "grub-config.xml" (builtins.toXML { splashImage = f cfg.splashImage; grub = f grub; grubTarget = f (grub.grubTarget or ""); @@ -36,7 +41,8 @@ let grubEfi = f grubEfi; grubTargetEfi = if cfg.efiSupport && (cfg.version == 2) then f (grubEfi.grubTarget or "") else ""; bootPath = args.path; - efiSysMountPoint = if args.efiSysMountPoint == null then args.path else args.efiSysMountPoint; + bootloaderId = if args.efiBootloaderId == null then "NixOS${efiSysMountPoint'}" else args.efiBootloaderId; + inherit efiSysMountPoint; inherit (args) devices; inherit (efi) canTouchEfiVariables; inherit (cfg) @@ -141,6 +147,17 @@ in ''; }; + efiBootloaderId = mkOption { + default = null; + example = "NixOS-fsid"; + type = types.nullOr types.str; + description = '' + The id of the bootloader to store in efi nvram. + The default is to name it NixOS and append the path or efiSysMountPoint. + This is only used if boot.loader.efi.canTouchEfiVariables is true. + ''; + }; + devices = mkOption { default = [ ]; example = [ "/dev/sda" "/dev/sdb" ]; diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 016b5a23ed4b..66d82e091d1f 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -59,6 +59,7 @@ my $canTouchEfiVariables = get("canTouchEfiVariables"); my $efiSysMountPoint = get("efiSysMountPoint"); my $gfxmodeEfi = get("gfxmodeEfi"); my $gfxmodeBios = get("gfxmodeBios"); +my $bootloaderId = get("bootloaderId"); $ENV{'PATH'} = get("path"); die "unsupported GRUB version\n" if $grubVersion != 1 && $grubVersion != 2; @@ -521,7 +522,7 @@ if (($requireNewInstall != 0) && ($efiTarget eq "no" || $efiTarget eq "both")) { if (($requireNewInstall != 0) && ($efiTarget eq "only" || $efiTarget eq "both")) { print STDERR "installing the GRUB $grubVersion EFI boot loader into $efiSysMountPoint...\n"; if ($canTouchEfiVariables eq "true") { - system("$grubEfi/sbin/grub-install", "--recheck", "--target=$grubTargetEfi", "--boot-directory=$bootPath", "--efi-directory=$efiSysMountPoint") == 0 + system("$grubEfi/sbin/grub-install", "--recheck", "--target=$grubTargetEfi", "--boot-directory=$bootPath", "--efi-directory=$efiSysMountPoint", "--bootloader-id=$bootloaderId") == 0 or die "$0: installation of GRUB EFI into $efiSysMountPoint failed\n"; } else { system("$grubEfi/sbin/grub-install", "--recheck", "--target=$grubTargetEfi", "--boot-directory=$bootPath", "--efi-directory=$efiSysMountPoint", "--no-nvram") == 0