diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index e94cfeaf8d3..5bd056e5bc9 100755 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -359,6 +359,7 @@ ./system/boot/loader/efi.nix ./system/boot/loader/generations-dir/generations-dir.nix ./system/boot/loader/grub/grub.nix + ./system/boot/loader/grub/ipxe.nix ./system/boot/loader/grub/memtest.nix ./system/boot/loader/gummiboot/gummiboot.nix ./system/boot/loader/init-script/init-script.nix diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl index 981b60c004c..ffee0271e93 100644 --- a/nixos/modules/system/boot/loader/grub/install-grub.pl +++ b/nixos/modules/system/boot/loader/grub/install-grub.pl @@ -341,8 +341,9 @@ addEntry("NixOS - Default", $defaultConfig); $conf .= "$extraEntries\n" unless $extraEntriesBeforeNixOS; +my $grubBootPath = $grubBoot->path; # extraEntries could refer to @bootRoot@, which we have to substitute -$conf =~ s/\@bootRoot\@/$grubBoot->path/g; +$conf =~ s/\@bootRoot\@/$grubBootPath/g; # Emit submenus for all system profiles. sub addProfile { diff --git a/nixos/modules/system/boot/loader/grub/ipxe.nix b/nixos/modules/system/boot/loader/grub/ipxe.nix new file mode 100644 index 00000000000..9b5097a4cfd --- /dev/null +++ b/nixos/modules/system/boot/loader/grub/ipxe.nix @@ -0,0 +1,64 @@ +# This module adds a scripted iPXE entry to the GRUB boot menu. + +{ config, lib, pkgs, ... }: + +with lib; + +let + scripts = builtins.attrNames config.boot.loader.grub.ipxe; + + grubEntry = name: + '' + menuentry "iPXE - ${name}" { + linux16 @bootRoot@/ipxe.lkrn + initrd16 @bootRoot@/${name}.ipxe + } + + ''; + + scriptFile = name: + let + value = builtins.getAttr name config.boot.loader.grub.ipxe; + in + if builtins.typeOf value == "path" then value + else builtins.toFile "${name}.ipxe" value; +in +{ + options = + { boot.loader.grub.ipxe = mkOption { + type = types.attrsOf (types.either types.path types.str); + description = + '' + Set of iPXE scripts available for + booting from the GRUB boot menu. + ''; + default = { }; + example = literalExample '' + { demo = ''' + #!ipxe + dhcp + chain http://boot.ipxe.org/demo/boot.php + '''; + }; + ''; + }; + }; + + config = mkIf (builtins.length scripts != 0) { + + boot.loader.grub.extraEntries = + if config.boot.loader.grub.version == 2 then + toString (map grubEntry scripts) + else + throw "iPXE is not supported with GRUB 1."; + + boot.loader.grub.extraFiles = + { "ipxe.lkrn" = "${pkgs.ipxe}/ipxe.lkrn"; } + // + builtins.listToAttrs ( map + (name: { name = name+".ipxe"; value = scriptFile name; }) + scripts + ); + }; + +} diff --git a/pkgs/tools/misc/ipxe/default.nix b/pkgs/tools/misc/ipxe/default.nix new file mode 100644 index 00000000000..1f1302698c1 --- /dev/null +++ b/pkgs/tools/misc/ipxe/default.nix @@ -0,0 +1,39 @@ +{ stdenv, fetchgit, perl, cdrkit, syslinux }: + +let + date = "20141124"; + rev = "5cbdc41778622c07429e00f5aee383b575532bf0"; +in + +stdenv.mkDerivation { + name = "ipxe-${date}-${builtins.substring 0 7 rev}"; + + buildInputs = [ perl cdrkit syslinux ]; + + src = fetchgit { + url = git://git.ipxe.org/ipxe.git; + sha256 = "22f427df9141a2bbb319b51bdca4f2b7d3a4cbb5d1b2dcb35a43460eac59d305"; + inherit rev; + }; + + sourceRoot = "git-export/src"; + + makeFlags = + [ "ECHO_E_BIN_ECHO=echo" "ECHO_E_BIN_ECHO_E=echo" # No /bin/echo here. + "ISOLINUX_BIN_LIST=${syslinux}/share/syslinux/isolinux.bin" + ]; + + installPhase = + '' + mkdir $out + cp bin/ipxe.dsk bin/ipxe.usb bin/ipxe.iso bin/ipxe.lkrn $out + ''; + + meta = with stdenv.lib; + { description = "Network boot firmware"; + homepage = http://ipxe.org/; + license = licenses.gpl2; + maintainers = with maintainers; [ emery ]; + platforms = platforms.all; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 75ae3bf0160..a2a2269757a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1508,6 +1508,8 @@ let ipmiutil = callPackage ../tools/system/ipmiutil {}; + ipxe = callPackage ../tools/misc/ipxe { }; + ised = callPackage ../tools/misc/ised {}; isl = callPackage ../development/libraries/isl { };