aboutsummaryrefslogtreecommitdiff
path: root/modules/corenix
diff options
context:
space:
mode:
authorMilan Pässler <milan@petabyte.dev>2020-10-10 21:32:40 +0200
committerMilan Pässler <milan@petabyte.dev>2020-10-10 21:32:40 +0200
commit59320a0d896200e3c6c9e058d1f8f1ecb94b78ec (patch)
tree6513b836c5130bf70958f760cafb0b79494d5675 /modules/corenix
parent3b36a893f76201e00ae4100a32a8e3bccb067ae1 (diff)
.
Diffstat (limited to 'modules/corenix')
-rw-r--r--modules/corenix/default.nix60
1 files changed, 60 insertions, 0 deletions
diff --git a/modules/corenix/default.nix b/modules/corenix/default.nix
new file mode 100644
index 000000000000..ddfde736f8b2
--- /dev/null
+++ b/modules/corenix/default.nix
@@ -0,0 +1,60 @@
+{ 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);
+ };
+ 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}
+ '';
+ };
+}