1
0

hd-idle.nix 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. { lib, pkgs, ... }:
  2. let
  3. disks = [
  4. "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV023WG"
  5. "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV07RMA"
  6. "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV020CG"
  7. ];
  8. mkArgString = disks:
  9. lib.concatStringsSep " " (lib.map (disk: "-a ${disk} -i 600") disks);
  10. args = mkArgString disks;
  11. fatrace = lib.getExe' pkgs.fatrace "fatrace";
  12. hd-idle = lib.getExe' pkgs.hd-idle "hd-idle";
  13. in
  14. {
  15. environment.systemPackages = [ pkgs.hd-idle pkgs.fatrace ];
  16. systemd.services.hd-idle = {
  17. description = "hd-idle - spin down idle hard disks";
  18. after = [
  19. "suspend.target"
  20. "hibernate.target"
  21. "hybrid-sleep.target"
  22. "suspend-then-hibernate.target"
  23. ];
  24. wantedBy = [ "multi-user.target" ];
  25. serviceConfig = {
  26. Type = "simple";
  27. ExecStart = "${hd-idle} ${args}";
  28. Restart = "always";
  29. };
  30. };
  31. systemd.services.fatrace = {
  32. description = "File access tracing service";
  33. after = [ "local-fs.target" ];
  34. wants = [ "local-fs.target" ];
  35. serviceConfig = {
  36. ExecStart = "${fatrace} --timestamp /mnt/storage";
  37. Restart = "always";
  38. User = "root";
  39. };
  40. };
  41. }