deskpi (rpi4b case)

This commit is contained in:
robert jakub 2024-10-19 00:12:51 +02:00
parent 43edfd4578
commit 49f898bfbc
4 changed files with 105 additions and 0 deletions

44
deskpi/default.nix Normal file
View File

@ -0,0 +1,44 @@
{
nixos-hardware,
lib,
config,
...
}: let
inherit (lib) mkEnableOption mkOption types mkDefault;
cfg = config.hardware.deskpi;
in {
options.hardware.deskpi = {
enable = mkEnableOption "enable DeskPi Pro daemons";
device = mkOption {
type = types.str;
default = "/dev/deskPi";
};
};
imports =
[nixos-hardware.nixosModules.raspberry-pi-4]
++ [../raspberry-pi/overlays]
++ [../raspberry-pi/apply-overlays]
++ [./deskpi-tools.nix]
++ [./trim.nix];
config = {
hardware.raspberry-pi."4" = {
xhci.enable = mkDefault false;
dwc2.enable = mkDefault true;
dwc2.dr_mode = mkDefault "host";
overlays = {
rpi4-disable-pwrled.enable = mkDefault true;
};
};
hardware.deviceTree = {
enable = true;
filter = "bcm2711-rpi-4-b.dtb";
};
services.udev.extraRules = ''
ACTION=="add", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SUBSYSTEM=="tty", SYMLINK+="${builtins.baseNameOf cfg.device}"
'';
};
}

43
deskpi/deskpi-tools.nix Normal file
View File

@ -0,0 +1,43 @@
{
config,
pkgs,
...
}: let
deskpi-tools = pkgs.callPackage ../raspberry-pi/packages/deskpi-tools {};
cfg = config.hardware.deskpi;
in {
systemd.packages = [deskpi-tools];
systemd.services."deskpi-safe-shut" = {
description = "DeskPi Safe-Shutdown Service";
after = ["shutdown.target"];
before = ["final.target"];
wantedBy = ["shutdown.target"];
conflicts = ["reboot.target"];
unitConfig = {
ConditionPathExists = cfg.device;
DefaultDependencies = "no";
};
serviceConfig = {
Type = "oneshot";
ExecStart = "${deskpi-tools}/bin/safeCutOffPower";
RemainAfterExit = "yes";
TimeoutSec = "infinity";
StandardOutput = "tty";
};
};
systemd.services."deskpi" = {
description = "DeskPi PWM Control Fan Service";
after = ["multi-user.target"];
wantedBy = ["multi-user.target"];
unitConfig = {
ConditionPathExists = cfg.device;
};
serviceConfig = {
Type = "simple";
ExecStart = "${deskpi-tools}/bin/pwmFanControl";
RemainAfterExit = "no";
};
};
}

17
deskpi/trim.nix Normal file
View File

@ -0,0 +1,17 @@
{
config,
lib,
...
}: let
inherit (lib) mkIf mkEnableOption types;
cfg = config.hardware.deskpi.trim;
in {
options.hardware.deskpi.trim = {
enable = mkEnableOption "enable uas fstrim support";
};
config = mkIf cfg.enable {
services.udev.extraRules = ''
ACTION=="add|change", ATTRS{idVendor}=="174c", ATTRS{idProduct}=="55aa", SUBSYSTEM=="scsi_disk", ATTR{provisioning_mode}="unmap"
'';
};
}

View File

@ -15,6 +15,7 @@
in {
nixosModules = {
uconsole = import ./uconsole {inherit pkgs nixos-hardware;};
deskpi = import ./deskpi {inherit pkgs nixos-hardware;};
};
};
}