diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index c186968f0590..977ca2518ecc 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -240,7 +240,6 @@ ./system/activation/top-level.nix ./system/boot/kernel.nix ./system/boot/kexec.nix - ./system/boot/loader/efi-boot-stub/efi-boot-stub.nix ./system/boot/loader/efi.nix ./system/boot/loader/generations-dir/generations-dir.nix ./system/boot/loader/gummiboot/gummiboot.nix diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix index 631283ce219c..27b6f01c71fb 100644 --- a/nixos/modules/rename.nix +++ b/nixos/modules/rename.nix @@ -101,11 +101,6 @@ in zipModules ([] # ++ rename obsolete "environment.kdePackages" "environment.systemPackages" # !!! doesn't work! # Multiple efi bootloaders now -++ rename obsolete "boot.loader.efiBootStub.efiSysMountPoint" "boot.loader.efi.efiSysMountPoint" -++ 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.canTouchEfiVariables" ++ rename obsolete "boot.loader.efi.efibootmgr.enable" "boot.loader.efi.canTouchEfiVariables" # NixOS environment changes diff --git a/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh b/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh deleted file mode 100644 index 2f550c98428b..000000000000 --- a/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub-builder.sh +++ /dev/null @@ -1,131 +0,0 @@ -#! @bash@/bin/sh -e - -shopt -s nullglob - -export PATH=/empty -for i in @path@; do PATH=$PATH:$i/bin:$i/sbin; done - -default=$1 -if test -z "$1"; then - echo "Syntax: efi-boot-stub-builder.sh " - exit 1 -fi - -echo "updating the efi system partition..." - -# Convert a path to a file in the Nix store such as -# /nix/store/-/file to --. -# Also, efi executables need the .efi extension -cleanName() { - local path="$1" - echo "$path" | sed 's|^/nix/store/||' | sed 's|/|-|g' | sed 's|@kernelFile@$|@kernelFile@.efi|' -} - -# Copy a file from the Nix store to the EFI system partition -declare -A filesCopied - -copyToKernelsDir() { - local src="$1" - local dst="@efiSysMountPoint@/efi/nixos/$(cleanName $src)" - # Don't copy the file if $dst already exists. This means that we - # have to create $dst atomically to prevent partially copied - # kernels or initrd if this script is ever interrupted. - if ! test -e $dst; then - local dstTmp=$dst.tmp.$$ - cp $src $dstTmp - mv $dstTmp $dst - fi - filesCopied[$dst]=1 - result=$dst -} - -# Copy its kernel, initrd, and startup script to the efi system partition -# Add the efibootmgr entry if requested -addEntry() { - local path="$1" - local generation="$2" - - if ! test -e $path/kernel -a -e $path/initrd; then - return - fi - - local kernel=$(readlink -f $path/kernel) - local initrd=$(readlink -f $path/initrd) - copyToKernelsDir $kernel; kernel=$result - copyToKernelsDir $initrd; initrd=$result - - local startup="@efiSysMountPoint@/efi/nixos/generation-$generation-startup.nsh" - if ! test -e $startup; then - local dstTmp=$startup.tmp.$$ - echo "$(echo $kernel | sed 's|@efiSysMountPoint@||' | sed 's|/|\\|g') systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) initrd=$(echo $initrd | sed 's|@efiSysMountPoint@||' | sed 's|/|\\|g') $(cat $path/kernel-params)" > $dstTmp - mv $dstTmp $startup - fi - filesCopied[$startup]=1 - - if test -n "@runEfibootmgr@"; then - set +e - efibootmgr -c -d "@efiDisk@" -g -l $(echo $kernel | sed 's|@efiSysMountPoint@||' | sed 's|/|\\|g') -L "NixOS $generation Generation" -p "@efiPartition@" \ - -u systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) initrd=$(echo $initrd | sed 's|@efiSysMountPoint@||' | sed 's|/|\\|g') $(cat $path/kernel-params) > /dev/null 2>&1 - set -e - fi - - if test $(readlink -f "$path") = "$default"; then - if test -n "@runEfibootmgr@"; then - set +e - defaultbootnum=$(efibootmgr | grep "NixOS $generation Generation" | sed 's/Boot//' | sed 's/\*.*//') - set -e - fi - - if test -n "@installStartupNsh@"; then - sed 's|.*@kernelFile@.efi|@kernelFile@.efi|' < $startup > "@efiSysMountPoint@/startup.nsh" - cp $kernel "@efiSysMountPoint@/@kernelFile@.efi" - fi - fi -} - -mkdir -p "@efiSysMountPoint@/efi/nixos/" - -# Remove all old boot manager entries -if test -n "@runEfibootmgr@"; then - set +e - modprobe efivars > /dev/null 2>&1 - for bootnum in $(efibootmgr | grep "NixOS" | grep "Generation" | sed 's/Boot//' | sed 's/\*.*//'); do - efibootmgr -B -b "$bootnum" > /dev/null 2>&1 - done - set -e -fi - -# Add all generations of the system profile to the system partition, in reverse -# (most recent to least recent) order. -for generation in $( - (cd /nix/var/nix/profiles && ls -d system-*-link) \ - | sed 's/system-\([0-9]\+\)-link/\1/' \ - | sort -n -r); do - link=/nix/var/nix/profiles/system-$generation-link - addEntry $link $generation -done - -if test -n "@runEfibootmgr@"; then - set +e - efibootmgr -o $defaultbootnum > /dev/null 2>&1 - set -e -fi - -if test -n "@efiShell@"; then - mkdir -pv "@efiSysMountPoint@"/efi/boot - cp "@efiShell@" "@efiSysMountPoint@"/efi/boot/boot"@targetArch@".efi -fi - -# Remove obsolete files from the EFI system partition -for fn in "@efiSysMountPoint@/efi/nixos/"*; do - if ! test "${filesCopied[$fn]}" = 1; then - rm -vf -- "$fn" - fi -done - -# Run any extra commands users may need -if test -n "@runEfibootmgr@"; then - set +e - @postEfiBootMgrCommands@ - set -e -fi diff --git a/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix b/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix deleted file mode 100644 index 735784327bcc..000000000000 --- a/nixos/modules/system/boot/loader/efi-boot-stub/efi-boot-stub.nix +++ /dev/null @@ -1,98 +0,0 @@ -{pkgs, config, ...}: - -with pkgs.lib; - -let - efiBootStubBuilder = pkgs.substituteAll { - src = ./efi-boot-stub-builder.sh; - isExecutable = true; - inherit (pkgs) bash; - path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.glibc] ++ (pkgs.stdenv.lib.optionals config.boot.loader.efi.canTouchEfiVariables [pkgs.efibootmgr pkgs.module_init_tools]); - inherit (config.boot.loader.efiBootStub) installStartupNsh; - - inherit (config.boot.loader.efi) efiSysMountPoint; - - inherit (config.boot.loader.efi.efibootmgr) efiDisk efiPartition postEfiBootMgrCommands; - - runEfibootmgr = config.boot.loader.efi.canTouchEfiVariables; - - efiShell = if config.boot.loader.efiBootStub.installShell then - if pkgs.stdenv.isi686 then - pkgs.fetchurl { - url = "https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/Ia32/Shell_Full.efi"; - sha256 = "1gv6kyaspczdp7x8qnx5x76ilriaygkfs99ay7ihhdi6riclkhfl"; - } - else - pkgs.fetchurl { - url = "https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2/EdkShellBinPkg/FullShell/X64/Shell_Full.efi"; - sha256 = "1g18z84rlavxr5gsrh2g942rfr6znv9fs3fqww5m7dhmnysgyv8p"; - } - else - null; - - kernelFile = platform.kernelTarget; - targetArch = if pkgs.stdenv.isi686 then - "IA32" - else if pkgs.stdenv.isx86_64 then - "X64" - else - throw "Unsupported architecture"; - }; - - # Temporary check, for nixos to cope both with nixpkgs stdenv-updates and trunk - platform = pkgs.stdenv.platform; -in -{ - options = { - boot = { - loader = { - efiBootStub = { - - enable = mkOption { - default = false; - description = '' - Whether to use the linux kernel as an EFI bootloader. - When enabled, the kernel, initrd, and an EFI shell script - to boot the system are copied to the EFI system partition. - ''; - }; - - installStartupNsh = mkOption { - default = false; - description = '' - Whether to install a startup.nsh in the root of the EFI system partition. - For now, it will just boot the latest version when run, the eventual goal - is to have a basic menu-type interface. - ''; - }; - - installShell = mkOption { - default = false; - description = '' - Whether to install an EFI shell in \EFI\BOOT. - This _should_ only be needed for removable devices - (CDs, usb sticks, etc.), but it may be an option for broken - systems where efibootmgr doesn't work. Particularly useful in - conjunction with installStartupNsh - ''; - }; - - }; - }; - }; - }; - - config = mkIf config.boot.loader.efiBootStub.enable { - assertions = [ { assertion = ! config.boot.kernelPackages.kernel ? features || config.boot.kernelPackages.kernel.features ? efiBootStub; message = "This kernel does not support the EFI boot stub"; } ]; - - system = { - build.installBootLoader = efiBootStubBuilder; - boot.loader.id = "efiBootStub"; - boot.loader.kernelFile = platform.kernelTarget; - requiredKernelConfig = with config.lib.kernelConfig; [ - (isYes "EFI_STUB") - ]; - }; - }; - -} diff --git a/nixos/modules/system/boot/loader/efi.nix b/nixos/modules/system/boot/loader/efi.nix index 827b3e391222..7e739173f9a3 100644 --- a/nixos/modules/system/boot/loader/efi.nix +++ b/nixos/modules/system/boot/loader/efi.nix @@ -12,32 +12,6 @@ with pkgs.lib; description = "Whether or not the installation process should modify efi boot variables."; }; - efibootmgr = { - efiDisk = mkOption { - default = "/dev/sda"; - - type = types.string; - - description = "The disk that contains the EFI system partition."; - }; - - efiPartition = mkOption { - default = "1"; - description = "The partition number of the EFI system partition."; - }; - - postEfiBootMgrCommands = mkOption { - default = ""; - type = types.string; - description = '' - Shell commands to be executed immediately after efibootmgr has setup the system EFI. - Some systems do not follow the EFI specifications properly and insert extra entries. - Others will brick (fix by removing battery) on boot when it finds more than X entries. - This hook allows for running a few extra efibootmgr commands to combat these issues. - ''; - }; - }; - efiSysMountPoint = mkOption { default = "/boot";