aboutsummaryrefslogtreecommitdiff
path: root/modules/grub2/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/grub2/default.nix')
-rw-r--r--modules/grub2/default.nix69
1 files changed, 66 insertions, 3 deletions
diff --git a/modules/grub2/default.nix b/modules/grub2/default.nix
index 2f918f476eef..d2da4dd6cf0f 100644
--- a/modules/grub2/default.nix
+++ b/modules/grub2/default.nix
@@ -9,6 +9,39 @@ let
else
"fallback/payload";
+ configText = (readFile ./files/grub.cfg) +
+ (optionalString (cfg.scanDevices) (readFile ./files/grub-scan.cfg)) +
+ (optionalString (cfg.users != {})
+ (concatStringsSep "\n" (mapAttrsToList (n: u: ''
+ ${if u.passwordIsHashed then "password_pbkdf2" else "password"} ${n} ${u.password}
+ '') cfg.users)) + ''
+ set superusers="${concatStringsSep " " (attrNames (filterAttrs (n: u: u.superuser) cfg.users))}"
+ export superusers
+ ''
+ ) +
+ (optionalString cfg.generateSecondaryPayloadEntries (
+ concatMapStrings (n: ''
+ menuentry '${removePrefix "img/" n}' {
+ chainloader (cbfsdisk)/${n}
+ }
+ '') (filter (hasPrefix "img/") (attrNames config.corenix.extraFiles))
+ ));
+
+ userOpts = { ... }: {
+ options = {
+ superuser = mkOption {
+ type = types.bool;
+ default = true;
+ };
+ password = mkOption {
+ type = types.str;
+ };
+ passwordIsHashed = mkOption {
+ type = types.bool;
+ default = true;
+ };
+ };
+ };
in {
options.grub2 = {
enable = mkEnableOption "grub2 coreboot primary payload";
@@ -18,14 +51,44 @@ in {
default = false;
};
+ generateSecondaryPayloadEntries = mkOption {
+ type = types.bool;
+ default = true;
+ };
+
+ scanDevices = mkOption {
+ type = types.bool;
+ default = true;
+ description = ''
+ Scan internal and external storage devices for GRUB2/syslinux/isolinux/NetBSD
+ configs and at runtime and create boot entries for each of them.
+ '';
+ };
+
+ extraConfig = mkOption {
+ type = types.lines;
+ default = "";
+ };
+
+ configFile = mkOption {
+ type = types.path;
+ };
+
+ users = mkOption {
+ type = types.attrsOf (types.submodule userOpts);
+ default = {};
+ };
+
font = mkOption {
type = types.path;
- #default = "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuSansMono.ttf";
default = "${pkgs.unifont}/share/fonts/truetype/unifont.ttf";
+ example = "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuSansMono.ttf";
};
};
- config = lib.mkIf cfg.enable {
+ config = mkIf cfg.enable {
+ grub2.configFile = pkgs.writeText "grub.cfg" configText;
+
corenix.extraFiles = {
${payloadName} = {
type = "payload";
@@ -36,7 +99,7 @@ in {
buildInputs = with pkgs; [ grub2 ];
} "grub-mkfont --range=0x20-0x7E,0x2501-0x251F,0x2191-0x2193 --size=14 -o $out ${cfg.font}"
);
- "etc/grub.cfg".src = ./files/grub.cfg;
+ "etc/grub.cfg".src = cfg.configFile;
"background.png".src = ./files/background.png;
};
};