From 49f898bfbc3e4c2282da51a5a3c5c5f2480d6066 Mon Sep 17 00:00:00 2001 From: robert jakub Date: Sat, 19 Oct 2024 00:12:51 +0200 Subject: [PATCH] deskpi (rpi4b case) --- deskpi/default.nix | 44 +++++++++++++++++++++++++++++++++++++++++ deskpi/deskpi-tools.nix | 43 ++++++++++++++++++++++++++++++++++++++++ deskpi/trim.nix | 17 ++++++++++++++++ flake.nix | 1 + 4 files changed, 105 insertions(+) create mode 100644 deskpi/default.nix create mode 100644 deskpi/deskpi-tools.nix create mode 100644 deskpi/trim.nix diff --git a/deskpi/default.nix b/deskpi/default.nix new file mode 100644 index 0000000..d5f4472 --- /dev/null +++ b/deskpi/default.nix @@ -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}" + ''; + }; +} diff --git a/deskpi/deskpi-tools.nix b/deskpi/deskpi-tools.nix new file mode 100644 index 0000000..0384428 --- /dev/null +++ b/deskpi/deskpi-tools.nix @@ -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"; + }; + }; +} diff --git a/deskpi/trim.nix b/deskpi/trim.nix new file mode 100644 index 0000000..e44372f --- /dev/null +++ b/deskpi/trim.nix @@ -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" + ''; + }; +} diff --git a/flake.nix b/flake.nix index 3f8c667..74a7b44 100644 --- a/flake.nix +++ b/flake.nix @@ -15,6 +15,7 @@ in { nixosModules = { uconsole = import ./uconsole {inherit pkgs nixos-hardware;}; + deskpi = import ./deskpi {inherit pkgs nixos-hardware;}; }; }; }