mirror of
https://github.com/nix-community/raspberry-pi-nix.git
synced 2025-11-09 12:06:02 +01:00
add hardware.raspberrypi.config-generated option
outputs the generated config as text
This commit is contained in:
parent
6e0da67830
commit
24f5b92db8
1 changed files with 118 additions and 100 deletions
218
rpi/config.nix
218
rpi/config.nix
|
|
@ -1,126 +1,144 @@
|
||||||
{ lib, config, pkgs, ... }:
|
{ lib, config, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.hardware.raspberry-pi;
|
cfg = config.hardware.raspberry-pi;
|
||||||
render-raspberrypi-config = let
|
render-raspberrypi-config =
|
||||||
render-options = opts:
|
let
|
||||||
lib.strings.concatStringsSep "\n" (render-dt-kvs opts);
|
render-options = opts:
|
||||||
render-dt-param = x: "dtparam=" + x;
|
lib.strings.concatStringsSep "\n" (render-dt-kvs opts);
|
||||||
render-dt-kv = k: v:
|
render-dt-param = x: "dtparam=" + x;
|
||||||
if isNull v.value then
|
render-dt-kv = k: v:
|
||||||
k
|
if isNull v.value then
|
||||||
else
|
k
|
||||||
let vstr = toString v.value; in "${k}=${vstr}";
|
else
|
||||||
render-dt-kvs = x:
|
let vstr = toString v.value; in "${k}=${vstr}";
|
||||||
lib.attrsets.mapAttrsToList render-dt-kv
|
render-dt-kvs = x:
|
||||||
(lib.filterAttrs (k: v: v.enable) x);
|
lib.attrsets.mapAttrsToList render-dt-kv
|
||||||
render-dt-overlay = { overlay, args }:
|
(lib.filterAttrs (k: v: v.enable) x);
|
||||||
"dtoverlay=" + overlay + "\n"
|
render-dt-overlay = { overlay, args }:
|
||||||
+ lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n"
|
"dtoverlay=" + overlay + "\n"
|
||||||
+ "dtoverlay=";
|
+ lib.strings.concatMapStringsSep "\n" render-dt-param args + "\n"
|
||||||
render-base-dt-params = params:
|
+ "dtoverlay=";
|
||||||
lib.strings.concatMapStringsSep "\n" render-dt-param
|
render-base-dt-params = params:
|
||||||
(render-dt-kvs params);
|
lib.strings.concatMapStringsSep "\n" render-dt-param
|
||||||
render-dt-overlays = overlays:
|
(render-dt-kvs params);
|
||||||
lib.strings.concatMapStringsSep "\n" render-dt-overlay
|
render-dt-overlays = overlays:
|
||||||
(lib.attrsets.mapAttrsToList (k: v: {
|
lib.strings.concatMapStringsSep "\n" render-dt-overlay
|
||||||
overlay = k;
|
(lib.attrsets.mapAttrsToList
|
||||||
args = render-dt-kvs v.params;
|
(k: v: {
|
||||||
}) (lib.filterAttrs (k: v: v.enable) overlays));
|
overlay = k;
|
||||||
render-config-section = k:
|
args = render-dt-kvs v.params;
|
||||||
{ options, base-dt-params, dt-overlays }:
|
})
|
||||||
let
|
(lib.filterAttrs (k: v: v.enable) overlays));
|
||||||
all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [
|
render-config-section = k:
|
||||||
(render-options options)
|
{ options, base-dt-params, dt-overlays }:
|
||||||
(render-base-dt-params base-dt-params)
|
let
|
||||||
(render-dt-overlays dt-overlays)
|
all-config = lib.concatStringsSep "\n" (lib.filter (x: x != "") [
|
||||||
]);
|
(render-options options)
|
||||||
in ''
|
(render-base-dt-params base-dt-params)
|
||||||
[${k}]
|
(render-dt-overlays dt-overlays)
|
||||||
${all-config}
|
]);
|
||||||
'';
|
in
|
||||||
in conf:
|
''
|
||||||
lib.strings.concatStringsSep "\n"
|
[${k}]
|
||||||
(lib.attrsets.mapAttrsToList render-config-section conf);
|
${all-config}
|
||||||
in {
|
'';
|
||||||
|
in
|
||||||
|
conf:
|
||||||
|
lib.strings.concatStringsSep "\n"
|
||||||
|
(lib.attrsets.mapAttrsToList render-config-section conf);
|
||||||
|
in
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
hardware.raspberry-pi = {
|
hardware.raspberry-pi = {
|
||||||
config = let
|
config =
|
||||||
rpi-config-param = {
|
let
|
||||||
options = {
|
rpi-config-param = {
|
||||||
enable = lib.mkEnableOption "attr";
|
options = {
|
||||||
value =
|
enable = lib.mkEnableOption "attr";
|
||||||
lib.mkOption { type = with lib.types; oneOf [ int str bool ]; };
|
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-param = {
|
||||||
dt-overlay = {
|
options = {
|
||||||
options = {
|
enable = lib.mkEnableOption "attr";
|
||||||
enable = lib.mkEnableOption "overlay";
|
value = lib.mkOption {
|
||||||
params = lib.mkOption {
|
type = with lib.types; nullOr (oneOf [ int str bool ]);
|
||||||
type = with lib.types; attrsOf (submodule dt-param);
|
default = null;
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
raspberry-pi-config-options = {
|
|
||||||
options = {
|
|
||||||
options = lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf (submodule rpi-config-param);
|
|
||||||
default = { };
|
|
||||||
example = {
|
|
||||||
enable_gic = {
|
|
||||||
enable = true;
|
|
||||||
value = true;
|
|
||||||
};
|
|
||||||
arm_boost = {
|
|
||||||
enable = true;
|
|
||||||
value = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
base-dt-params = lib.mkOption {
|
};
|
||||||
type = with lib.types; attrsOf (submodule rpi-config-param);
|
dt-overlay = {
|
||||||
default = { };
|
options = {
|
||||||
example = {
|
enable = lib.mkEnableOption "overlay";
|
||||||
i2c = {
|
params = lib.mkOption {
|
||||||
enable = true;
|
type = with lib.types; attrsOf (submodule dt-param);
|
||||||
value = "on";
|
|
||||||
};
|
|
||||||
audio = {
|
|
||||||
enable = true;
|
|
||||||
value = "on";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
description = "parameters to pass to the base dtb";
|
|
||||||
};
|
|
||||||
dt-overlays = lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf (submodule dt-overlay);
|
|
||||||
default = { };
|
|
||||||
example = { vc4-kms-v3d = { cma-256 = { enable = true; }; }; };
|
|
||||||
description = "dtb overlays to apply";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
raspberry-pi-config-options = {
|
||||||
|
options = {
|
||||||
|
options = lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf (submodule rpi-config-param);
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
enable_gic = {
|
||||||
|
enable = true;
|
||||||
|
value = true;
|
||||||
|
};
|
||||||
|
arm_boost = {
|
||||||
|
enable = true;
|
||||||
|
value = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
base-dt-params = lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf (submodule rpi-config-param);
|
||||||
|
default = { };
|
||||||
|
example = {
|
||||||
|
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 (submodule dt-overlay);
|
||||||
|
default = { };
|
||||||
|
example = { vc4-kms-v3d = { cma-256 = { enable = true; }; }; };
|
||||||
|
description = "dtb overlays to apply";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
lib.mkOption {
|
||||||
|
type = with lib.types; attrsOf (submodule raspberry-pi-config-options);
|
||||||
};
|
};
|
||||||
in lib.mkOption {
|
|
||||||
type = with lib.types; attrsOf (submodule raspberry-pi-config-options);
|
config-generated = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "the config text generated by raspberrypi.hardware.config";
|
||||||
|
readOnly = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
config-output = lib.mkOption {
|
config-output = lib.mkOption {
|
||||||
type = lib.types.package;
|
type = lib.types.package;
|
||||||
default = pkgs.writeTextFile {
|
default = pkgs.writeTextFile {
|
||||||
name = "config.txt";
|
name = "config.txt";
|
||||||
text = ''
|
text = ''
|
||||||
# This is a generated file. Do not edit!
|
# This is a generated file. Do not edit!
|
||||||
${render-raspberrypi-config cfg.config}
|
${cfg.config-generated}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
config = {
|
||||||
|
hardware.raspberry-pi.config-generated = render-raspberrypi-config cfg.config;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue