gummiboot-builder.py: Update to latest gummiboot

This commit is contained in:
Shea Levy 2013-02-21 12:33:54 -05:00
parent 7b8958b6c5
commit 5f29704861
5 changed files with 20 additions and 81 deletions

View File

@ -104,6 +104,7 @@ in zipModules ([]
++ rename obsolete "boot.loader.efiBootStub.efiDisk" "boot.loader.efi.efibootmgr.efiDisk"
++ rename obsolete "boot.loader.efiBootStub.efiPartition" "boot.loader.efi.efibootmgr.efiPartition"
++ rename obsolete "boot.loader.efiBootStub.postEfiBootMgrCommands" "boot.loader.efi.efibootmgr.postEfiBootMgrCommands"
++ rename obsolete "boot.loader.efiBootStub.runEfibootmgr" "boot.loader.efi.efibootmgr.enable"
++ rename obsolete "boot.loader.efiBootStub.runEfibootmgr" "boot.loader.efi.canTouchEfiVariables"
++ rename obsolete "boot.loader.efi.efibootmgr.enable" "boot.loader.efi.canTouchEfiVariables"
) # do not add renaming after this.

View File

@ -14,7 +14,7 @@ let
inherit (config.boot.loader.efi.efibootmgr) efiDisk efiPartition postEfiBootMgrCommands;
runEfibootmgr = config.boot.loader.efi.efibootmgr.enable;
runEfibootmgr = config.boot.loader.efi.canTouchEfiVariables;
efiShell = if config.boot.loader.efiBootStub.installShell then
if pkgs.stdenv.isi686 then

View File

@ -4,6 +4,14 @@ with pkgs.lib;
{
options.boot.loader.efi = {
canTouchEfiVariables = mkOption {
default = false;
type = types.bool;
description = "Whether or not the installation process should modify efi boot variables.";
};
efibootmgr = {
efiDisk = mkOption {
default = "/dev/sda";
@ -13,18 +21,6 @@ with pkgs.lib;
description = "The disk that contains the EFI system partition.";
};
enable = mkOption {
default = false;
type = types.bool;
description = ''
Whether to run efibootmgr to add the efi bootloaders configuration to the boot options list.
WARNING! efibootmgr has been rumored to brick Apple firmware on
old kernels! Don't use it on kernels older than 2.6.39!
'';
};
efiPartition = mkOption {
default = "1";
description = "The partition number of the EFI system partition.";

View File

@ -80,65 +80,17 @@ def remove_old_entries(gens):
if not path in known_paths:
os.unlink(path)
def update_gummiboot():
mkdir_p("@efiSysMountPoint@/efi/gummiboot")
store_file_path = "@gummiboot@/bin/gummiboot.efi"
store_dir = os.path.basename("@gummiboot@")
efi_file_path = "/efi/gummiboot/%s-gummiboot.efi" % (store_dir)
copy_if_not_exists(store_file_path, "@efiSysMountPoint@%s" % (efi_file_path))
return efi_file_path
def update_efibootmgr(path):
subprocess.call(["@kmod@/sbin/modprobe", "efivars"])
post_efibootmgr = """
@postEfiBootMgrCommands@
"""
efibootmgr_entries = subprocess.check_output(["@efibootmgr@/sbin/efibootmgr"]).split("\n")
for entry in efibootmgr_entries:
columns = entry.split()
if len(columns) > 2:
if ' '.join(columns[1:3]) == "NixOS gummiboot":
subprocess.call([
"@efibootmgr@/sbin/efibootmgr",
"-B",
"-b",
columns[0][4:8]
])
subprocess.call([
"@efibootmgr@/sbin/efibootmgr",
"-c",
"-d",
"@efiDisk@",
"-g",
"-l",
path.replace("/", "\\"),
"-L",
"NixOS gummiboot",
"-p",
"@efiPartition@",
])
efibootmgr_entries = subprocess.check_output(["@efibootmgr@/sbin/efibootmgr"]).split("\n")
for entry in efibootmgr_entries:
columns = entry.split()
if len(columns) > 1 and columns[0] == "BootOrder:":
boot_order = columns[1].split(',')
if len(columns) > 2:
if ' '.join(columns[1:3]) == "NixOS gummiboot":
bootnum = columns[0][4:8]
if not bootnum in boot_order:
boot_order.insert(0, bootnum)
with open("/dev/null", 'w') as dev_null:
subprocess.call([
"@efibootmgr@/sbin/efibootmgr",
"-o",
','.join(boot_order)
], stdout=dev_null)
subprocess.call(post_efibootmgr, shell=True)
parser = argparse.ArgumentParser(description='Update NixOS-related gummiboot files')
parser.add_argument('default_config', metavar='DEFAULT-CONFIG', help='The default NixOS config to boot')
args = parser.parse_args()
# We deserve our own env var!
if os.getenv("NIXOS_INSTALL_GRUB") == "1":
if "@canTouchEfiVariables@" == "1":
subprocess.check_call(["@gummiboot@/bin/gummiboot", "--path=@efiSysMountPoint@", "install"])
else:
subprocess.check_call(["@gummiboot@/bin/gummiboot", "--path=@efiSysMountPoint@", "--no-variables", "install"])
known_paths = []
mkdir_p("@efiSysMountPoint@/efi/nixos")
mkdir_p("@efiSysMountPoint@/loader/entries")
@ -157,9 +109,3 @@ for gen in gens:
write_loader_conf(gen)
remove_old_entries(gens)
# We deserve our own env var!
if os.getenv("NIXOS_INSTALL_GRUB") == "1":
gummiboot_path = update_gummiboot()
if "@runEfibootmgr@" == "1":
update_efibootmgr(gummiboot_path)

View File

@ -12,17 +12,13 @@ let
isExecutable = true;
inherit (pkgs) python gummiboot kmod efibootmgr;
inherit (pkgs) python gummiboot;
inherit (config.environment) nix;
inherit (cfg) timeout;
inherit (efi) efiSysMountPoint;
inherit (efi.efibootmgr) postEfiBootMgrCommands efiDisk efiPartition;
runEfibootmgr = efi.efibootmgr.enable;
inherit (efi) efiSysMountPoint canTouchEfiVariables;
};
in {
options.boot.loader.gummiboot = {