summary refs log tree commit diff
path: root/nixos/modules/system/boot/loader/grub
diff options
context:
space:
mode:
authorsymphorien <symphorien@users.noreply.github.com>2017-02-13 14:53:15 +0100
committerRobin Gloster <mail@glob.in>2017-02-13 14:53:15 +0100
commit0b87efacb14425f65e75c489e26b21952ece805c (patch)
treed096cfbd3ec3c079d1dfd212b902dc4694614485 /nixos/modules/system/boot/loader/grub
parent5d00edcf4f018d80dbed9e55e431d2054faf7078 (diff)
downloadnixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar.gz
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar.bz2
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar.lz
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar.xz
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.tar.zst
nixlib-0b87efacb14425f65e75c489e26b21952ece805c.zip
grub: add grub.useOSProber option (#22558)
Diffstat (limited to 'nixos/modules/system/boot/loader/grub')
-rw-r--r--nixos/modules/system/boot/loader/grub/grub.nix14
-rw-r--r--nixos/modules/system/boot/loader/grub/install-grub.pl9
2 files changed, 20 insertions, 3 deletions
diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix
index 294fc1988e9f..23b970186a39 100644
--- a/nixos/modules/system/boot/loader/grub/grub.nix
+++ b/nixos/modules/system/boot/loader/grub/grub.nix
@@ -53,12 +53,14 @@ let
       inherit (args) devices;
       inherit (efi) canTouchEfiVariables;
       inherit (cfg)
-        version extraConfig extraPerEntryConfig extraEntries forceInstall 
+        version extraConfig extraPerEntryConfig extraEntries forceInstall useOSProber
         extraEntriesBeforeNixOS extraPrepareConfig configurationLimit copyKernels
         default fsIdentifier efiSupport efiInstallAsRemovable gfxmodeEfi gfxmodeBios;
       path = (makeBinPath ([
         pkgs.coreutils pkgs.gnused pkgs.gnugrep pkgs.findutils pkgs.diffutils pkgs.btrfs-progs
-        pkgs.utillinux ] ++ (if cfg.efiSupport && (cfg.version == 2) then [pkgs.efibootmgr ] else [])
+        pkgs.utillinux ]
+        ++ (optional (cfg.efiSupport && (cfg.version == 2)) pkgs.efibootmgr)
+        ++ (optionals cfg.useOSProber [pkgs.busybox pkgs.os-prober])
       )) + ":" + (makeSearchPathOutput "bin" "sbin" [
         pkgs.mdadm pkgs.utillinux
       ]);
@@ -265,6 +267,14 @@ in
         '';
       };
 
+      useOSProber = mkOption {
+        default = false;
+        type = types.bool;
+        description = ''
+          If set to true, append entries for other OSs detected by os-prober.
+        '';
+      };
+
       splashImage = mkOption {
         type = types.nullOr types.path;
         example = literalExample "./my-background.png";
diff --git a/nixos/modules/system/boot/loader/grub/install-grub.pl b/nixos/modules/system/boot/loader/grub/install-grub.pl
index f92b17720f65..74eb32d1fc13 100644
--- a/nixos/modules/system/boot/loader/grub/install-grub.pl
+++ b/nixos/modules/system/boot/loader/grub/install-grub.pl
@@ -424,10 +424,17 @@ if ($extraPrepareConfig ne "") {
   system((get("shell"), "-c", $extraPrepareConfig));
 }
 
-# Atomically update the GRUB config.
+# write the GRUB config.
 my $confFile = $grubVersion == 1 ? "$bootPath/grub/menu.lst" : "$bootPath/grub/grub.cfg";
 my $tmpFile = $confFile . ".tmp";
 writeFile($tmpFile, $conf);
+
+# Append entries detected by os-prober
+if (get("useOsprober") eq "true") {
+    system(get("shell"), "-c", "pkgdatadir=$grub/share/grub $grub/etc/grub.d/30_os-prober >> $tmpFile");
+}
+
+# Atomically switch to the new config
 rename $tmpFile, $confFile or die "cannot rename $tmpFile to $confFile\n";