From 9f89c2dcf5953fbe5271f0599ce268b531a5ca73 Mon Sep 17 00:00:00 2001 From: Travis Staton Date: Sat, 4 Mar 2023 14:46:48 -0500 Subject: [PATCH] add enable option to config --- rpi/config.nix | 65 ++++++++++++++++++++++++++++++++++++++++--------- rpi/default.nix | 60 +++++++++++++++++++++++++++++++++++++-------- rpi/i2c.nix | 7 +++++- 3 files changed, 109 insertions(+), 23 deletions(-) diff --git a/rpi/config.nix b/rpi/config.nix index c311124..1226520 100644 --- a/rpi/config.nix +++ b/rpi/config.nix @@ -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"; }; }; diff --git a/rpi/default.nix b/rpi/default.nix index 12a48ae..a45a183 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -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 = { }; }; }; }; diff --git a/rpi/i2c.nix b/rpi/i2c.nix index 07c1762..2bef083 100644 --- a/rpi/i2c.nix +++ b/rpi/i2c.nix @@ -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; }; };