[Nix-dev] [PATCH] Put old generations in grub submenu (NixOS)

Andreas Källberg anka.213 at gmail.com
Thu Feb 2 23:13:57 CET 2012


Hi everyone!

I have made a patch which adds an option
(config.boot.loader.grub.oldVersionsInSubmenu)
for hiding the old versions of the system in a submenu to reduce cluttering.
This is my first patch, so bare with me if I made any stupid mistakes ;-)

Now that I think of it, I should probably make sure the option is disabled if
grub.version = 1, not sure how to do that though.

Regards,
Andreas Källberg


Index: modules/installer/grub/grub.nix
===================================================================
--- modules/installer/grub/grub.nix	(revision 31746)
+++ modules/installer/grub/grub.nix	(working copy)
@@ -14,7 +14,7 @@
     path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
     inherit (config.boot.loader.grub) copyKernels
       extraConfig extraEntries extraEntriesBeforeNixOS extraPerEntryConfig
-      splashImage configurationLimit version default timeout;
+      oldVersionsInSubmenu splashImage configurationLimit version
default timeout;
   };

 in
@@ -107,6 +107,13 @@
         '';
       };

+	  oldVersionsInSubmenu = mkOption {
+        default = false;
+        description = ''
+          Whether the old versions of NixOS should appear in a submenu.
+        '';
+      };
+
       splashImage = mkOption {
         default =
           if config.boot.loader.grub.version == 1
Index: modules/installer/grub/grub-menu-builder.sh
===================================================================
--- modules/installer/grub/grub-menu-builder.sh	(revision 31746)
+++ modules/installer/grub/grub-menu-builder.sh	(working copy)
@@ -257,6 +257,7 @@

 addEntry "NixOS - Default" $defaultConfig ""

+
 if test -z "@extraEntriesBeforeNixOS@"; then
     echo "$extraEntries" >> $tmp
 fi
@@ -268,6 +269,12 @@
     addEntry "NixOS - variation" $link ""
 done

+if test -n "@oldVersionsInSubmenu@"; then
+    cat >> $tmp <<EOF
+submenu "NixOS - Old versions" {
+EOF
+fi
+
 for generation in $(
     (cd /nix/var/nix/profiles && for i in system-*-link; do echo $i; done) \
     | sed 's/system-\([0-9]\+\)-link/\1/' \
@@ -278,7 +285,13 @@
     addEntry "NixOS - Configuration $generation ($date -
$kernelVersion)" $link "$generation ($date)"
 done

+if test -n "@oldVersionsInSubmenu@"; then
+    cat >> $tmp <<EOF
+}
+EOF
+fi

+
 # Atomically update the GRUB configuration file.
 mv $tmp $target


More information about the nix-dev mailing list