From c0e79671baa5eab50f47ee186cf064d0f4fb5a46 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 14 Nov 2023 19:00:13 +0100 Subject: [PATCH] refactor de-p1st-monitor --- modules/de-p1st-monitor.nix | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 modules/de-p1st-monitor.nix diff --git a/modules/de-p1st-monitor.nix b/modules/de-p1st-monitor.nix new file mode 100644 index 0000000..e85f449 --- /dev/null +++ b/modules/de-p1st-monitor.nix @@ -0,0 +1,64 @@ +{ config, pkgs, ... }: +let + my-python-packages = ps: with ps; [ + # de-p1st-monitor is not (yet) packaged, thus we build it from PyPI + ( + buildPythonPackage rec { + pname = "de.p1st.monitor"; + version = "0.11.2"; + # https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py + format = "pyproject"; + src = fetchPypi { + inherit pname version; + sha256 = "sha256-8rrDuG893gz4B83R8C5U+3AQLK3rPpPoJTTi+C7BL9o="; + }; + propagatedBuildInputs = [ + # Dependencies + pkgs.python3Packages.psutil + # Build dependencies + build + twine + ]; + } + ) + ]; +in +{ + # Install de.p1st.monitor packages. + environment.systemPackages = [ + (pkgs.python3.withPackages my-python-packages) + # Dependency of de.p1st.monitor. + pkgs.smartmontools + ]; + # Dependency of de.p1st.monitor + boot.kernelModules = [ "drivetemp" ]; + + # Create de.p1st.monitor timer. + systemd.timers."de.p1st.monitor" = { + wantedBy = [ "timers.target" ]; + partOf = [ "de.p1st.monitor.service" ]; + timerConfig = { + OnBootSec = "0m"; + OnUnitInactiveSec = "3m"; + + AccuracySec = "15s"; + RandomizedDelaySec = "15s"; + }; + }; + systemd.services."de.p1st.monitor" = { + serviceConfig = { + Type = "oneshot"; + PrivateTmp = true; + # `smartctl` requires root to access /dev/* devices and read their temperatures. + User = "root"; + Nice = 19; + IOSchedulingClass = "idle"; + ExecStart = "${pkgs.python3.withPackages my-python-packages}/bin/de-p1st-monitor"; + }; + path = with pkgs; [ + # Provides `findmnt` binary. + libuuid + smartmontools + ]; + }; +}