chore: format repo using treefmt-nix and nixfmt-rfc-style

This commit is contained in:
Andre 2025-06-04 12:11:03 -04:00
parent fc7c471412
commit 51e51e6014
266 changed files with 3721 additions and 2733 deletions

View file

@ -1,4 +1,4 @@
{ lib, pkgs, ...}:
{ lib, pkgs, ... }:
{
boot = {

View file

@ -1,6 +1,7 @@
{ lib
, pkgs
, ...
{
lib,
pkgs,
...
}:
{
@ -11,8 +12,7 @@
# https://github.com/NixOS/nixpkgs/issues/154163#issuecomment-1350599022
nixpkgs.overlays = [
(_final: super: {
makeModulesClosure = x:
super.makeModulesClosure (x // { allowMissing = true; });
makeModulesClosure = x: super.makeModulesClosure (x // { allowMissing = true; });
})
];

View file

@ -1,48 +1,67 @@
# modification of nixpkgs deviceTree.applyOverlays to resolve https://github.com/NixOS/nixpkgs/issues/125354
# derived from https://github.com/NixOS/nixpkgs/blob/916ca8f2b0c208def051f8ea9760c534a40309db/pkgs/os-specific/linux/device-tree/default.nix
{ lib, stdenvNoCC, dtc, libraspberrypi }:
{
lib,
stdenvNoCC,
dtc,
libraspberrypi,
}:
with lib; (base: overlays': stdenvNoCC.mkDerivation {
name = "device-tree-overlays";
nativeBuildInputs = [ dtc libraspberrypi ];
buildCommand = let
overlays = toList overlays';
in ''
mkdir -p $out
cd "${base}"
find . -type f -name '*.dtb' -print0 \
| xargs -0 cp -v --no-preserve=mode --target-directory "$out" --parents
with lib;
(
base: overlays':
stdenvNoCC.mkDerivation {
name = "device-tree-overlays";
nativeBuildInputs = [
dtc
libraspberrypi
];
buildCommand =
let
overlays = toList overlays';
in
''
mkdir -p $out
cd "${base}"
find . -type f -name '*.dtb' -print0 \
| xargs -0 cp -v --no-preserve=mode --target-directory "$out" --parents
for dtb in $(find "$out" -type f -name '*.dtb'); do
dtbCompat=$(fdtget -t s "$dtb" / compatible 2>/dev/null || true)
# skip files without `compatible` string
test -z "$dtbCompat" && continue
for dtb in $(find "$out" -type f -name '*.dtb'); do
dtbCompat=$(fdtget -t s "$dtb" / compatible 2>/dev/null || true)
# skip files without `compatible` string
test -z "$dtbCompat" && continue
${flip (concatMapStringsSep "\n") overlays (o: ''
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
${flip (concatMapStringsSep "\n") overlays (o: ''
overlayCompat="$(fdtget -t s "${o.dtboFile}" / compatible)"
# skip incompatible and non-matching overlays
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
elif ${if ((o.filter or null) == null) then "false" else ''
[[ "''${dtb//${o.filter}/}" == "$dtb" ]]
''}
then
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
else
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
mv "$dtb"{,.in}
# skip incompatible and non-matching overlays
if [[ ! "$dtbCompat" =~ "$overlayCompat" ]]; then
echo "Skipping overlay ${o.name}: incompatible with $(basename "$dtb")"
elif ${
if ((o.filter or null) == null) then
"false"
else
''
[[ "''${dtb//${o.filter}/}" == "$dtb" ]]
''
}
then
echo "Skipping overlay ${o.name}: filter does not match $(basename "$dtb")"
else
echo -n "Applying overlay ${o.name} to $(basename "$dtb")... "
mv "$dtb"{,.in}
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
cp -r ${o.dtboFile} "$dtboWithExt"
# dtmerge requires a .dtbo ext for dtbo files, otherwise it adds it to the given file implicitly
dtboWithExt="$TMPDIR/$(basename "${o.dtboFile}").dtbo"
cp -r ${o.dtboFile} "$dtboWithExt"
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
dtmerge "$dtb.in" "$dtb" "$dtboWithExt"
echo "ok"
rm "$dtb.in" "$dtboWithExt"
fi
'')}
echo "ok"
rm "$dtb.in" "$dtboWithExt"
fi
'')}
done'';
})
done'';
}
)

View file

@ -1,4 +1,9 @@
{ config, lib, pkgs, ... }:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.hardware.raspberry-pi."4".audio;
@ -38,9 +43,10 @@ in
# set tsched=0 in pulseaudio config to avoid audio glitches
# see https://wiki.archlinux.org/title/PulseAudio/Troubleshooting#Glitches,_skips_or_crackling
hardware.pulseaudio.configFile = lib.mkOverride 990 (pkgs.runCommand "default.pa" {} ''
sed 's/module-udev-detect$/module-udev-detect tsched=0/' ${config.hardware.pulseaudio.package}/etc/pulse/default.pa > $out
'');
hardware.pulseaudio.configFile = lib.mkOverride 990 (
pkgs.runCommand "default.pa" { } ''
sed 's/module-udev-detect$/module-udev-detect tsched=0/' ${config.hardware.pulseaudio.package}/etc/pulse/default.pa > $out
''
);
};
}

View file

@ -1,4 +1,9 @@
{ lib, pkgs, config, ... }:
{
lib,
pkgs,
config,
...
}:
{
imports = [
@ -40,7 +45,6 @@
hardware.deviceTree.filter = lib.mkDefault "bcm2711-rpi-*.dtb";
assertions = [
{
assertion = (lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.1");

View file

@ -25,7 +25,11 @@ in
https://www.kernel.org/doc/Documentation/usb/gadget-testing.txt
'';
dr_mode = lib.mkOption {
type = lib.types.enum [ "host" "peripheral" "otg" ];
type = lib.types.enum [
"host"
"peripheral"
"otg"
];
default = "otg";
description = ''
Dual role mode setting for the dwc2 USB controller driver.

View file

@ -1,36 +1,41 @@
{ pkgs, lib, config, ... }:
{
pkgs,
lib,
config,
...
}:
{
options.hardware.raspberry-pi."4".gpio = {
enable = lib.mkOption {
type = lib.types.bool;
description =
"Enable udev rules and kernelParams that make lgpio and pigpio work";
description = "Enable udev rules and kernelParams that make lgpio and pigpio work";
default = false;
};
};
config = let
cfg = config.hardware.raspberry-pi."4".gpio;
config =
let
cfg = config.hardware.raspberry-pi."4".gpio;
in
lib.mkIf cfg.enable {
users.groups.gpio = lib.mkDefault { };
lib.mkIf cfg.enable {
users.groups.gpio = lib.mkDefault { };
# the bit that matters to lgpio here is
# "${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k"
# see https://github.com/NixOS/nixpkgs/pull/352308
# the bit that matters to lgpio here is
# "${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k"
# see https://github.com/NixOS/nixpkgs/pull/352308
# sudo udevadm test --action=add /dev/gpiochip0 to test
# sudo udevadm test --action=add /dev/gpiochip0 to test
# import lgpio; lgpio.gpiochip_open(0) should show "1" and not raise
# an exception
# import lgpio; lgpio.gpiochip_open(0) should show "1" and not raise
# an exception
services.udev.extraRules = lib.mkBefore ''
KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k && ${pkgs.coreutils}/bin/chgrp -R gpio /sys/class/gpio && ${pkgs.coreutils}/bin/chmod -R g=u /sys/class/gpio'"
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp -R gpio /sys%p && ${pkgs.coreutils}/bin/chmod -R g=u /sys%p'"
'';
services.udev.extraRules = lib.mkBefore ''
KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp gpio /dev/%k && chmod 660 /dev/%k && ${pkgs.coreutils}/bin/chgrp -R gpio /sys/class/gpio && ${pkgs.coreutils}/bin/chmod -R g=u /sys/class/gpio'"
SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/chgrp -R gpio /sys%p && ${pkgs.coreutils}/bin/chmod -R g=u /sys%p'"
'';
boot.kernelParams = [
"iomem=relaxed" # for pigpiod
];
};
boot.kernelParams = [
"iomem=relaxed" # for pigpiod
];
};
}

View file

@ -2,24 +2,31 @@
let
cfg = config.hardware.raspberry-pi."4";
optionalProperty = name: value: lib.optionalString (value != null) "${name} = <${builtins.toString value}>;";
simple-overlay = { target, status, frequency }: {
name = "${target}-${status}-overlay";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&${target}>;
__overlay__ {
status = "${status}";
${optionalProperty "clock-frequency" frequency}
optionalProperty =
name: value: lib.optionalString (value != null) "${name} = <${builtins.toString value}>;";
simple-overlay =
{
target,
status,
frequency,
}:
{
name = "${target}-${status}-overlay";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&${target}>;
__overlay__ {
status = "${status}";
${optionalProperty "clock-frequency" frequency}
};
};
};
};
'';
};
'';
};
in
{
options.hardware.raspberry-pi."4" = {
@ -54,21 +61,25 @@ in
(lib.mkIf cfg.i2c0.enable {
i2c.enable = lib.mkDefault true;
deviceTree = {
overlays = [ (simple-overlay {
target = "i2c0if";
status = "okay";
inherit (cfg.i2c0) frequency;
}) ];
overlays = [
(simple-overlay {
target = "i2c0if";
status = "okay";
inherit (cfg.i2c0) frequency;
})
];
};
})
(lib.mkIf cfg.i2c1.enable {
i2c.enable = lib.mkDefault true;
deviceTree = {
overlays = [ (simple-overlay {
target = "i2c1";
status = "okay";
inherit (cfg.i2c1) frequency;
}) ];
overlays = [
(simple-overlay {
target = "i2c1";
status = "okay";
inherit (cfg.i2c1) frequency;
})
];
};
})
];

View file

@ -2,12 +2,14 @@
let
cfg = config.hardware.raspberry-pi."4".leds;
mkDisableOption = name: lib.mkOption {
default = false;
example = true;
description = "Whether to disable ${name}.";
type = lib.types.bool;
};
mkDisableOption =
name:
lib.mkOption {
default = false;
example = true;
description = "Whether to disable ${name}.";
type = lib.types.bool;
};
in
{
options.hardware = {
@ -71,23 +73,25 @@ in
{
name = "disable-act-led";
filter = "*rpi-4-b*";
dtsText = let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_act>" else "<&act_led>";
in ''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&gpio 42 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "none";
};
};
};
'';
dtsText =
let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_act>" else "<&act_led>";
in
''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&gpio 42 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "none";
};
};
};
'';
}
];
};
@ -101,23 +105,25 @@ in
{
name = "disable-pwr-led";
filter = "*rpi-4-b*";
dtsText = let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_pwr>" else "<&pwr_led>";
in ''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&expgpio 2 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "default-on";
};
};
};
'';
dtsText =
let
kernelVersion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.2";
target = if kernelVersion then "<&led_pwr>" else "<&pwr_led>";
in
''
/dts-v1/;
/plugin/;
/{
compatible = "raspberrypi,4-model-b";
fragment@0 {
target = ${target};
__overlay__ {
gpios = <&expgpio 2 0>; /* first two values copied from bcm2711-rpi-4-b.dts */
linux,default-trigger = "default-on";
};
};
};
'';
}
];
};

View file

@ -6,7 +6,8 @@ let
applyOverlays = _final.callPackage ./apply-overlays-dtmerge.nix { };
};
};
in {
in
{
options.hardware = {
raspberry-pi."4".apply-overlays-dtmerge = {
enable = lib.mkEnableOption ''

View file

@ -2,7 +2,8 @@
let
cfg = config.hardware.raspberry-pi."4".poe-hat;
in {
in
{
options.hardware = {
raspberry-pi."4".poe-hat = {
enable = lib.mkEnableOption ''

View file

@ -2,7 +2,8 @@
let
cfg = config.hardware.raspberry-pi."4".poe-plus-hat;
in {
in
{
options.hardware = {
raspberry-pi."4".poe-plus-hat = {
enable = lib.mkEnableOption ''

View file

@ -14,37 +14,39 @@ in
config = lib.mkIf cfg.enable {
hardware.deviceTree = {
overlays = [{
name = "pwm-overlay";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
overlays = [
{
name = "pwm-overlay";
dtsText = ''
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2711";
fragment@0 {
target = <&gpio>;
__overlay__ {
pwm_pins: pwm_pins {
brcm,pins = <18>;
brcm,function = <2>; /* Alt5 */
fragment@0 {
target = <&gpio>;
__overlay__ {
pwm_pins: pwm_pins {
brcm,pins = <18>;
brcm,function = <2>; /* Alt5 */
};
};
};
};
fragment@1 {
target = <&pwm>;
__overlay__ {
pinctrl-names = "default";
assigned-clock-rates = <100000000>;
status = "okay";
pinctrl-0 = <&pwm_pins>;
fragment@1 {
target = <&pwm>;
__overlay__ {
pinctrl-names = "default";
assigned-clock-rates = <100000000>;
status = "okay";
pinctrl-0 = <&pwm_pins>;
};
};
};
};
'';
}];
};
'';
}
];
};
};
}

View file

@ -2,7 +2,8 @@
let
cfg = config.hardware.raspberry-pi."4".tv-hat;
in {
in
{
options.hardware = {
raspberry-pi."4".tv-hat = {
enable = lib.mkEnableOption ''

View file

@ -2,9 +2,11 @@
config,
lib,
...
}: let
}:
let
cfg = config.hardware.raspberry-pi."4".xhci;
in {
in
{
options.hardware = {
raspberry-pi."4".xhci = {
enable = lib.mkEnableOption ''

View file

@ -1,4 +1,9 @@
{ lib, pkgs, config, ... }:
{
lib,
pkgs,
config,
...
}:
let
linux_rpi5 = pkgs.linux_rpi4.override {
rpiVersion = 5;
@ -18,12 +23,12 @@ in
# Needed for Xorg to start (https://github.com/raspberrypi-ui/gldriver-test/blob/master/usr/lib/systemd/scripts/rp1_test.sh)
# This won't work for displays connected to the RP1 (DPI/composite/MIPI DSI), since I don't have one to test.
services.xserver.extraConfig = ''
Section "OutputClass"
Identifier "vc4"
MatchDriver "vc4"
Driver "modesetting"
Option "PrimaryGPU" "true"
EndSection
Section "OutputClass"
Identifier "vc4"
MatchDriver "vc4"
Driver "modesetting"
Option "PrimaryGPU" "true"
EndSection
'';
assertions = [