{ config, pkgs, lib, ... }: with lib; let cfg = config.corenix; fileOptions.options = { src = mkOption { type = types.path; }; type = mkOption { type = types.str; default = "raw"; }; }; in { options.corenix = { extraFiles = mkOption { type = types.attrsOf (types.submodule fileOptions); }; corebootConfig = mkOption { type = types.attrsOf (types.nullOr types.str); default = {}; }; rom = mkOption { readOnly = true; type = types.path; }; }; config = { corenix.rom = let base = pkgs.coreboot.override { inherit (cfg) corebootConfig; }; filteredFiles = filterAttrs (k: v: v != null) cfg.extraFiles; filesList = mapAttrsToList (k: v: v // { name = k; }) filteredFiles; installCommands = 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; in pkgs.runCommand "coreboot-rom" { buildInputs = with pkgs; [ cbfstool ]; } '' install -D ${base}/coreboot.rom -t $out ${installCommands} ''; }; }