aboutsummaryrefslogtreecommitdiff
path: root/infra/corenix/modules
diff options
context:
space:
mode:
Diffstat (limited to 'infra/corenix/modules')
-rw-r--r--infra/corenix/modules/coreinfo/default.nix28
-rw-r--r--infra/corenix/modules/corenix/default.nix64
-rw-r--r--infra/corenix/modules/default.nix6
-rw-r--r--infra/corenix/modules/grub2/default.nix123
-rw-r--r--infra/corenix/modules/grub2/files/background.pngbin0 -> 390630 bytes
-rw-r--r--infra/corenix/modules/grub2/files/grub-scan.cfg30
-rw-r--r--infra/corenix/modules/grub2/files/grub.cfg46
-rw-r--r--infra/corenix/modules/nvramcui/default.nix19
-rw-r--r--infra/corenix/modules/seabios/default.nix61
-rw-r--r--infra/corenix/modules/tianocore/default.nix28
-rw-r--r--infra/corenix/modules/tint/default.nix17
11 files changed, 422 insertions, 0 deletions
diff --git a/infra/corenix/modules/coreinfo/default.nix b/infra/corenix/modules/coreinfo/default.nix
new file mode 100644
index 000000000000..d1a2a19ecf34
--- /dev/null
+++ b/infra/corenix/modules/coreinfo/default.nix
@@ -0,0 +1,28 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let cfg = config.coreinfo;
+in {
+ options.coreinfo = {
+ enable = mkEnableOption "coreinfo coreboot secondary payload";
+
+ coreinfoConfig = mkOption {
+ type = types.attrsOf (types.nullOr types.str);
+ default = { };
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ corenix.extraFiles = {
+ "img/coreinfo" = {
+ type = "payload";
+ src = "${
+ pkgs.coreboot-payload-coreinfo.override {
+ inherit (cfg) coreinfoConfig;
+ }
+ }/coreinfo.elf";
+ };
+ };
+ };
+}
diff --git a/infra/corenix/modules/corenix/default.nix b/infra/corenix/modules/corenix/default.nix
new file mode 100644
index 000000000000..0ab4e996ff2a
--- /dev/null
+++ b/infra/corenix/modules/corenix/default.nix
@@ -0,0 +1,64 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+ cfg = config.corenix;
+
+ fileOptions.options = {
+ src = mkOption { type = types.nullOr types.path; };
+
+ type = mkOption {
+ type = types.str;
+ default = "raw";
+ };
+ };
+in {
+ options.corenix = {
+ installCommands = mkOption { type = types.lines; };
+
+ extraFiles =
+ mkOption { type = types.attrsOf (types.submodule fileOptions); };
+
+ corebootConfig = mkOption {
+ type = types.attrsOf (types.nullOr types.str);
+ default = { };
+ };
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.coreboot;
+ };
+
+ rom = mkOption {
+ readOnly = true;
+ type = types.path;
+ };
+ };
+
+ config = {
+ corenix.installCommands = let
+ filteredFiles = filterAttrs (k: v: v.src != null) cfg.extraFiles;
+ filesList = mapAttrsToList (k: v: v // { name = k; }) filteredFiles;
+ in concatMapStringsSep "\n" (file:
+ if file.type == "payload" then ''
+ cbfstool $out/coreboot.rom add-payload \
+ -f "${file.src}" \
+ -n "${file.name}" \
+ '' else ''
+ cbfstool $out/coreboot.rom add \
+ -f "${file.src}" \
+ -n "${file.name}" \
+ -t "${file.type}"
+ '') filesList;
+
+ corenix.rom =
+ let base = cfg.package.override { inherit (cfg) corebootConfig; };
+ in pkgs.runCommand "coreboot-rom" {
+ buildInputs = with pkgs; [ cbfstool ];
+ } ''
+ install -D ${base}/coreboot.rom -t $out
+ ${cfg.installCommands}
+ '';
+ };
+}
diff --git a/infra/corenix/modules/default.nix b/infra/corenix/modules/default.nix
new file mode 100644
index 000000000000..c461f820cab5
--- /dev/null
+++ b/infra/corenix/modules/default.nix
@@ -0,0 +1,6 @@
+{ ... }:
+
+{
+ imports =
+ [ ./corenix ./grub2 ./tianocore ./seabios ./tint ./nvramcui ./coreinfo ];
+}
diff --git a/infra/corenix/modules/grub2/default.nix b/infra/corenix/modules/grub2/default.nix
new file mode 100644
index 000000000000..39fa13f73026
--- /dev/null
+++ b/infra/corenix/modules/grub2/default.nix
@@ -0,0 +1,123 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.grub2;
+ payloadName =
+ if cfg.asSecondaryPayload then "img/grub2" else "fallback/payload";
+
+ configText = (readFile ./files/grub.cfg) + cfg.extraConfig
+ + (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";
+
+ asSecondaryPayload = mkOption {
+ type = types.bool;
+ 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.unifont}/share/fonts/truetype/unifont.ttf";
+ example = "${pkgs.dejavu_fonts}/share/fonts/truetype/DejaVuSansMono.ttf";
+ };
+
+ package = mkOption {
+ type = types.package;
+ default = pkgs.coreboot-payload-grub2;
+ };
+
+ extraPayloadModules = mkOption {
+ type = types.listOf types.str;
+ default = [ ];
+ };
+ };
+
+ config = mkIf cfg.enable {
+ grub2.configFile = pkgs.writeText "grub.cfg" configText;
+ grub2.extraPayloadModules = [
+ "png"
+ "gfxmenu"
+ "gfxterm_background"
+ "ls"
+ "cat"
+ "echo"
+ "linux"
+ "xfs"
+ "bsd"
+ ];
+
+ corenix.extraFiles = {
+ ${payloadName} = {
+ type = "payload";
+ src = "${
+ cfg.package.override { inherit (cfg) extraPayloadModules; }
+ }/default_payload.elf";
+ };
+ "font.pf2".src =
+ (pkgs.runCommand "font.pf2" { buildInputs = with pkgs; [ grub2 ]; }
+ "grub-mkfont --range=0x20-0x7E,0x2501-0x251F,0x2191-0x2193 --size=14 -o $out ${cfg.font}");
+ "etc/grub.cfg".src = cfg.configFile;
+ "background.png".src = ./files/background.png;
+ };
+ };
+}
diff --git a/infra/corenix/modules/grub2/files/background.png b/infra/corenix/modules/grub2/files/background.png
new file mode 100644
index 000000000000..29275058f283
--- /dev/null
+++ b/infra/corenix/modules/grub2/files/background.png
Binary files differ
diff --git a/infra/corenix/modules/grub2/files/grub-scan.cfg b/infra/corenix/modules/grub2/files/grub-scan.cfg
new file mode 100644
index 000000000000..5aced43ebc3b
--- /dev/null
+++ b/infra/corenix/modules/grub2/files/grub-scan.cfg
@@ -0,0 +1,30 @@
+for x in (ahci*,*) (usb*,*) ; do
+ if [ -f "${x}/netbsd" ] ; then
+ menuentry "Load NetBSD from $x" $x {
+ root=$2
+ knetbsd /netbsd
+ }
+ fi
+ for path in '' /grub /grub2 /boot /boot/grub /boot/grub2 /efi/boot; do
+ if [ -f "${x}${path}/grub.cfg" ] ; then
+ menuentry "Load config from ${x}" $x $path {
+ root=$2
+ configfile "/${3}/grub.cfg"
+ }
+ fi
+ done
+ for path in '' /boot; do
+ if [ -f "${x}${path}/syslinux/syslinux.cfg" ] ; then
+ menuentry "Load syslinux config from ${x}" $x $path {
+ root=$2
+ syslinux_configfile -s "${3}/syslinux/syslinux.cfg"
+ }
+ fi
+ if [ -f "${x}${path}/isolinux/isolinux.cfg" ] ; then
+ menuentry "Load isolinux config from ${x}" $x $path {
+ root=$2
+ syslinux_configfile -i "${3}/isolinux/isolinux.cfg"
+ }
+ fi
+ done
+done
diff --git a/infra/corenix/modules/grub2/files/grub.cfg b/infra/corenix/modules/grub2/files/grub.cfg
new file mode 100644
index 000000000000..9b4548fbf048
--- /dev/null
+++ b/infra/corenix/modules/grub2/files/grub.cfg
@@ -0,0 +1,46 @@
+insmod regexp
+insmod ahci
+insmod part_msdos
+insmod part_gpt
+
+function load_video {
+ if [ x$feature_all_video_module = xy ]; then
+ insmod all_video
+ else
+ insmod efi_gop
+ insmod efi_uga
+ insmod ieee1275_fb
+ insmod vbe
+ insmod vga
+ insmod video_bochs
+ insmod video_cirrus
+ fi
+}
+
+
+if loadfont (cbfsdisk)/font.pf2 ; then
+ set gfxmode=auto
+ load_video
+ insmod gfxterm
+ set locale_dir=$prefix/locale
+ set lang=en_US
+ insmod gettext
+fi
+
+terminal_input console
+terminal_output gfxterm
+gfxpayload=keep
+
+if [ x$feature_timeout_style = xy ] ; then
+ set timeout_style=menu
+ set timeout=1
+# Fallback normal timeout code in case the timeout_style feature is
+# unavailable.
+else
+ set timeout=5
+fi
+
+insmod png
+if background_image (cbfsdisk)/background.png; then
+ true
+fi
diff --git a/infra/corenix/modules/nvramcui/default.nix b/infra/corenix/modules/nvramcui/default.nix
new file mode 100644
index 000000000000..b2838a2ff4cd
--- /dev/null
+++ b/infra/corenix/modules/nvramcui/default.nix
@@ -0,0 +1,19 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let cfg = config.nvramcui;
+in {
+ options.nvramcui = {
+ enable = mkEnableOption "nvramcui coreboot secondary payload";
+ };
+
+ config = lib.mkIf cfg.enable {
+ corenix.extraFiles = {
+ "img/nvramcui" = {
+ type = "payload";
+ src = "${pkgs.coreboot-payload-nvramcui}/nvramcui.elf";
+ };
+ };
+ };
+}
diff --git a/infra/corenix/modules/seabios/default.nix b/infra/corenix/modules/seabios/default.nix
new file mode 100644
index 000000000000..711fc2c84f13
--- /dev/null
+++ b/infra/corenix/modules/seabios/default.nix
@@ -0,0 +1,61 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.seabios;
+ payloadName =
+ if cfg.asSecondaryPayload then "img/seabios" else "fallback/payload";
+
+in {
+ options.seabios = {
+ enable = mkEnableOption "seabios coreboot primary payload";
+
+ withVgaBios = mkOption {
+ type = types.bool;
+ default = true;
+ };
+
+ asSecondaryPayload = mkOption {
+ type = types.bool;
+ default = false;
+ };
+
+ ps2Timeout = mkOption {
+ type = types.int;
+ default = 0;
+ };
+
+ seabiosConfig = mkOption {
+ type = types.attrsOf (types.nullOr types.str);
+ default = { };
+ };
+ };
+
+ config = mkIf cfg.enable {
+ seabios.seabiosConfig = {
+ CONFIG_COREBOOT = "y";
+ } // (lib.optionalAttrs cfg.withVgaBios {
+ CONFIG_VGA_COREBOOT = "y";
+ CONFIG_BUILD_VGABIOS = "y";
+ });
+
+ corenix.extraFiles = let
+ package =
+ pkgs.coreboot-payload-seabios.override { inherit (cfg) seabiosConfig; };
+ in {
+ ${payloadName} = {
+ type = "payload";
+ src = "${package}/bios.bin.elf";
+ };
+ } // (optionalAttrs cfg.withVgaBios {
+ "vgaroms/seavgabios.bin".src = "${package}/vgabios.bin";
+ });
+
+ corenix.installCommands = optionalString (cfg.ps2Timeout != 0) ''
+ cbfstool $out/coreboot.rom add-int \
+ -i ${toString cfg.ps2Timeout} \
+ -n etc/ps2-keyboard-spinup
+ '';
+ };
+}
diff --git a/infra/corenix/modules/tianocore/default.nix b/infra/corenix/modules/tianocore/default.nix
new file mode 100644
index 000000000000..59266c1aa058
--- /dev/null
+++ b/infra/corenix/modules/tianocore/default.nix
@@ -0,0 +1,28 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.tianocore;
+ payloadName =
+ if cfg.asSecondaryPayload then "img/tianocore" else "fallback/payload";
+
+in {
+ options.tianocore = {
+ enable = mkEnableOption "tianocore coreboot primary payload";
+
+ asSecondaryPayload = mkOption {
+ type = types.bool;
+ default = false;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ corenix.extraFiles = {
+ ${payloadName} = {
+ type = "payload";
+ src = "${pkgs.coreboot-payload-tianocore}/FV/UEFIPAYLOAD.fd";
+ };
+ };
+ };
+}
diff --git a/infra/corenix/modules/tint/default.nix b/infra/corenix/modules/tint/default.nix
new file mode 100644
index 000000000000..35f292be17f0
--- /dev/null
+++ b/infra/corenix/modules/tint/default.nix
@@ -0,0 +1,17 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let cfg = config.tint;
+in {
+ options.tint = { enable = mkEnableOption "tint coreboot secondary payload"; };
+
+ config = lib.mkIf cfg.enable {
+ corenix.extraFiles = {
+ "img/tint" = {
+ type = "payload";
+ src = "${pkgs.coreboot-payload-tint}/tint.elf";
+ };
+ };
+ };
+}