diff --git a/modules/rename.nix b/modules/rename.nix index 858056732a13..3582f72bfd5b 100644 --- a/modules/rename.nix +++ b/modules/rename.nix @@ -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. diff --git a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix index 529de0f0e541..7c8deba389be 100644 --- a/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix +++ b/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix @@ -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 diff --git a/modules/system/boot/loader/efi.nix b/modules/system/boot/loader/efi.nix index 41074908bffa..827b3e391222 100644 --- a/modules/system/boot/loader/efi.nix +++ b/modules/system/boot/loader/efi.nix @@ -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."; diff --git a/modules/system/boot/loader/gummiboot/gummiboot-builder.py b/modules/system/boot/loader/gummiboot/gummiboot-builder.py index ba4f946fc0f1..b8e9e983e79f 100644 --- a/modules/system/boot/loader/gummiboot/gummiboot-builder.py +++ b/modules/system/boot/loader/gummiboot/gummiboot-builder.py @@ -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) diff --git a/modules/system/boot/loader/gummiboot/gummiboot.nix b/modules/system/boot/loader/gummiboot/gummiboot.nix index 8ae0693923c1..0fd6bbe9c73e 100644 --- a/modules/system/boot/loader/gummiboot/gummiboot.nix +++ b/modules/system/boot/loader/gummiboot/gummiboot.nix @@ -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 = {