summary refs log tree commit diff
path: root/nixos/modules/system/boot
diff options
context:
space:
mode:
authorGauvain 'GovanifY' Roussel-Tarbouriech <gauvain@govanify.com>2021-01-02 18:23:49 +0100
committerGauvain 'GovanifY' Roussel-Tarbouriech <gauvain@govanify.com>2021-01-03 09:31:51 +0100
commit771ba47d564b734ac7644c19032b19a95a9e840e (patch)
tree6464b2c09b50404bf31a90f5f32bbd844f954ad7 /nixos/modules/system/boot
parent071eb8b265793098468fd321e5c6900eec149910 (diff)
downloadnixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar.gz
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar.bz2
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar.lz
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar.xz
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.tar.zst
nixpkgs-771ba47d564b734ac7644c19032b19a95a9e840e.zip
boot.loader.grub: add extraInstallCommands option
Diffstat (limited to 'nixos/modules/system/boot')
-rw-r--r--nixos/modules/system/boot/loader/grub/grub.nix22
1 files changed, 21 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/loader/grub/grub.nix b/nixos/modules/system/boot/loader/grub/grub.nix
index df5dfaa554b..289c2b19986 100644
--- a/nixos/modules/system/boot/loader/grub/grub.nix
+++ b/nixos/modules/system/boot/loader/grub/grub.nix
@@ -327,6 +327,26 @@ in
         '';
       };
 
+      extraInstallCommands = mkOption {
+        default = "";
+        example = literalExample ''
+          # the example below generates detached signatures that GRUB can verify
+          # https://www.gnu.org/software/grub/manual/grub/grub.html#Using-digital-signatures
+          ''${pkgs.findutils}/bin/find /boot -not -path "/boot/efi/*" -type f -name '*.sig' -delete
+          old_gpg_home=$GNUPGHOME
+          export GNUPGHOME="$(mktemp -d)"
+          ''${pkgs.gnupg}/bin/gpg --import ''${priv_key} > /dev/null 2>&1
+          ''${pkgs.findutils}/bin/find /boot -not -path "/boot/efi/*" -type f -exec ''${pkgs.gnupg}/bin/gpg --detach-sign "{}" \; > /dev/null 2>&1
+          rm -rf $GNUPGHOME
+          export GNUPGHOME=$old_gpg_home
+        '';
+        type = types.lines;
+        description = ''
+          Additional shell commands inserted in the bootloader installer
+          script after generating menu entries.
+        '';
+      };
+
       extraPerEntryConfig = mkOption {
         default = "";
         example = "root (hd0)";
@@ -715,7 +735,7 @@ in
         ${optionalString cfg.enableCryptodisk "export GRUB_ENABLE_CRYPTODISK=y"}
       '' + flip concatMapStrings cfg.mirroredBoots (args: ''
         ${pkgs.perl}/bin/perl ${install-grub-pl} ${grubConfig args} $@
-      ''));
+      '') + cfg.extraInstallCommands);
 
       system.build.grub = grub;