add enable option to config

This commit is contained in:
Travis Staton 2023-03-04 14:46:48 -05:00
parent 739c404f11
commit 9f89c2dcf5
3 changed files with 109 additions and 23 deletions

View file

@ -6,8 +6,13 @@ let
lib.strings.concatStringsSep "\n" (render-dt-kvs opts); lib.strings.concatStringsSep "\n" (render-dt-kvs opts);
render-dt-param = x: "dtparam=" + x; render-dt-param = x: "dtparam=" + x;
render-dt-kv = k: v: render-dt-kv = k: v:
if isNull v then k else let vstr = toString v; in "${k}=${vstr}"; if isNull v.value then
render-dt-kvs = x: lib.attrsets.mapAttrsToList render-dt-kv x; k
else
let vstr = toString v.value; in "${k}=${vstr}";
render-dt-kvs = x:
lib.attrsets.mapAttrsToList render-dt-kv
(lib.filterAttrs (k: v: v.enable) x);
render-dt-overlay = { overlay, args }: render-dt-overlay = { overlay, args }:
"dtoverlay=" + overlay + "\n" "dtoverlay=" + overlay + "\n"
+ lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n" + lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n"
@ -19,8 +24,8 @@ let
lib.strings.concatMapStringsSep "\n" render-dt-overlay lib.strings.concatMapStringsSep "\n" render-dt-overlay
(lib.attrsets.mapAttrsToList (k: v: { (lib.attrsets.mapAttrsToList (k: v: {
overlay = k; overlay = k;
args = render-dt-kvs v; args = render-dt-kvs v.params;
}) overlays); }) (lib.filterAttrs (k: v: v.enable) overlays));
render-config-section = k: render-config-section = k:
{ options, base-dt-params, dt-overlays }: { options, base-dt-params, dt-overlays }:
let let
@ -40,29 +45,65 @@ in {
options = { options = {
hardware.raspberry-pi = { hardware.raspberry-pi = {
config = let config = let
rpi-config-param = {
options = {
enable = lib.mkEnableOption "attr";
value =
lib.mkOption { type = with lib.types; oneOf [ int str bool ]; };
};
};
dt-param = {
options = {
enable = lib.mkEnableOption "attr";
value = lib.mkOption {
type = with lib.types; nullOr (oneOf [ int str bool ]);
default = null;
};
};
};
dt-overlay = {
options = {
enable = lib.mkEnableOption "overlay";
params = lib.mkOption {
type = with lib.types; attrsOf (submodule dt-param);
};
};
};
raspberry-pi-config-options = { raspberry-pi-config-options = {
options = { options = {
options = lib.mkOption { options = lib.mkOption {
type = with lib.types; attrsOf anything; type = with lib.types; attrsOf (submodule rpi-config-param);
default = { }; default = { };
example = { example = {
enable_gic = true; enable_gic = {
arm_boost = true; enable = true;
value = true;
};
arm_boost = {
enable = true;
value = true;
};
}; };
}; };
base-dt-params = lib.mkOption { base-dt-params = lib.mkOption {
type = with lib.types; attrsOf anything; type = with lib.types; attrsOf (submodule rpi-config-param);
default = { }; default = { };
example = { example = {
i2c = "on"; i2c = {
audio = "on"; enable = true;
value = "on";
};
audio = {
enable = true;
value = "on";
};
}; };
description = "parameters to pass to the base dtb"; description = "parameters to pass to the base dtb";
}; };
dt-overlays = lib.mkOption { dt-overlays = lib.mkOption {
type = with lib.types; attrsOf (attrsOf (nullOr str)); type = with lib.types; attrsOf (submodule dt-overlay);
default = { }; default = { };
example = { vc4-kms-v3d = { cma-256 = null; }; }; example = { vc4-kms-v3d = { cma-256 = { enable = true; }; }; };
description = "dtb overlays to apply"; description = "dtb overlays to apply";
}; };
}; };

View file

@ -20,21 +20,61 @@
# Default config.txt on Raspberry Pi OS: # Default config.txt on Raspberry Pi OS:
# https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt # https://github.com/RPi-Distro/pi-gen/blob/master/stage1/00-boot-files/files/config.txt
hardware.raspberry-pi.config = { hardware.raspberry-pi.config = {
cm4 = { options = { otg_mode = true; }; }; cm4 = {
pi4 = { options = { arm_boost = true; }; }; options = {
otg_mode = {
enable = true;
value = true;
};
};
};
pi4 = {
options = {
arm_boost = {
enable = true;
value = true;
};
};
};
all = { all = {
options = { options = {
# The firmware will start our u-boot binary rather than a # The firmware will start our u-boot binary rather than a
# linux kernel. # linux kernel.
kernel = "u-boot-rpi-arm64.bin"; kernel = {
arm_64bit = true; enable = true;
enable_uart = true; value = "u-boot-rpi-arm64.bin";
avoid_warnings = true; };
camera_auto_detect = true; arm_64bit = {
display_auto_detect = true; enable = true;
disable_overscan = true; value = true;
};
enable_uart = {
enable = true;
value = true;
};
avoid_warnings = {
enable = true;
value = true;
};
camera_auto_detect = {
enable = true;
value = true;
};
display_auto_detect = {
enable = true;
value = true;
};
disable_overscan = {
enable = true;
value = true;
};
};
dt-overlays = {
vc4-kms-v3d = {
enable = true;
params = { cma-256 = { enable = true; }; };
};
}; };
dt-overlays = { vc4-kms-v3d = { }; };
}; };
}; };

View file

@ -7,7 +7,12 @@ in {
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
hardware = { hardware = {
raspberry-pi.config.all.base-dt-params = { i2c = "on"; }; raspberry-pi.config.all.base-dt-params = {
i2c = {
enable = true;
value = "on";
};
};
i2c.enable = true; i2c.enable = true;
}; };
}; };