# This file is a modified version of config.txt generator # Licensed under the terms of MIT License # https://raw.githubusercontent.com/nix-community/raspberry-pi-nix/refs/heads/master/rpi/config.nix # with modifications # https://raw.githubusercontent.com/nvmd/raspberry-pi-nix/refs/heads/master/rpi/config.nix { lib, config, namespace, ... }: let cfg = config.${namespace}.hardware.raspberry-pi; render-raspberrypi-config = let render-kvs = kvs: let render-kv = k: v: if v.value == null then k else "${k}=${toString v.value}"; in lib.attrsets.mapAttrsToList render-kv (lib.filterAttrs (_k: v: v.enable) kvs); render-dt-param = x: "dtparam=" + x; render-dt-params = params: lib.strings.concatMapStringsSep "\n" render-dt-param (render-kvs params); render-dt-overlay = { overlay, params }: lib.concatStringsSep "\n" ( lib.filter (x: x != "") [ ("dtoverlay=" + overlay) (render-dt-params params) "dtoverlay=" ] ); render-options = opts: lib.strings.concatStringsSep "\n" (render-kvs opts); render-base-dt-params = render-dt-params; render-dt-overlays = overlays: lib.strings.concatMapStringsSep "\n" render-dt-overlay ( lib.attrsets.mapAttrsToList (overlay: params: { inherit overlay; inherit (params) params; }) (lib.filterAttrs (_k: v: v.enable) overlays) ); render-config-section = conditionalFilter: { options, base-dt-params, dt-overlays, }: let all-config = lib.concatStringsSep "\n" ( lib.filter (x: x != "") [ (render-options options) (render-base-dt-params base-dt-params) (render-dt-overlays dt-overlays) ] ); in '' [${conditionalFilter}] ${all-config} ''; in conf: lib.strings.concatStringsSep "\n" ( (lib.attrsets.mapAttrsToList render-config-section conf) ++ [ cfg.extra-config ] ); in { options.${namespace}.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); default = { }; }; }; }; raspberry-pi-config-options = { options = { options = lib.mkOption { type = with lib.types; attrsOf (submodule rpi-config-param); default = { }; description = '' Common hardware configuration options, translates to `