aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/hardware
diff options
context:
space:
mode:
authorKai Wohlfahrt <kai@prodo.ai>2019-04-24 18:24:16 +0100
committerKai Wohlfahrt <kai@prodo.ai>2019-08-07 13:51:22 +0100
commitdd0a9512797faa83bd1f974b10ef4d620200a79a (patch)
tree5b97f95445c6e3724520f184cdedd6d4d25d9827 /nixos/modules/hardware
parent0a477846af2837752687ced588b71108ff010bb2 (diff)
nixos/hardware.deviceTree: new module
Add support for custom device-tree files, and applying overlays to them. This is useful for supporting non-discoverable hardware, such as sensors attached to GPIO pins on a Raspberry Pi.
Diffstat (limited to 'nixos/modules/hardware')
-rw-r--r--nixos/modules/hardware/device-tree.nix56
1 files changed, 56 insertions, 0 deletions
diff --git a/nixos/modules/hardware/device-tree.nix b/nixos/modules/hardware/device-tree.nix
new file mode 100644
index 00000000000..20066939572
--- /dev/null
+++ b/nixos/modules/hardware/device-tree.nix
@@ -0,0 +1,56 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.hardware.deviceTree;
+in {
+ options = {
+ hardware.deviceTree = {
+ enable = mkOption {
+ default = pkgs.stdenv.hostPlatform.platform.kernelDTB or false;
+ type = types.bool;
+ description = ''
+ Build device tree files. These are used to describe the
+ non-discoverable hardware of a system.
+ '';
+ };
+
+ base = mkOption {
+ default = "${config.boot.kernelPackages.kernel}/dtbs";
+ defaultText = "\${config.boot.kernelPackages.kernel}/dtbs";
+ example = literalExample "pkgs.deviceTree.raspberryPiDtbs";
+ type = types.nullOr types.path;
+ description = ''
+ The package containing the base device-tree (.dtb) to boot. Contains
+ device trees bundled with the Linux kernel by default.
+ '';
+ };
+
+ overlays = mkOption {
+ default = [];
+ example = literalExample
+ "[\"\${pkgs.deviceTree.raspberryPiOverlays}/w1-gpio.dtbo\"]";
+ type = types.listOf types.path;
+ description = ''
+ A path containing device tree overlays (.dtbo) to be applied to all
+ base device-trees.
+ '';
+ };
+
+ package = mkOption {
+ default = null;
+ type = types.nullOr types.path;
+ description = ''
+ A path containing device tree overlays (.dtbo) to be applied to all
+ base device-trees. Overrides `base` and `overlays`.
+ '';
+ };
+ };
+ };
+
+ config = mkIf (cfg.enable) {
+ hardware.deviceTree.package = if (cfg.overlays != [])
+ then pkgs.deviceTree.applyOverlays cfg.base cfg.overlays else cfg.base;
+ };
+}