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

View file

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