nix-git/modules/de-p1st-monitor.nix

90 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2023-11-20 14:09:10 +01:00
{ lib, config, options, pkgs, modulesPath, ... }:
with lib;
2023-11-14 19:00:13 +01:00
let
2023-11-20 14:09:10 +01:00
cfg = config.yoda.de-p1st-monitor;
2023-11-14 19:00:13 +01:00
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";
2024-08-15 21:06:18 +02:00
# Important: When updating the version number, adjust the Git revision below accordingly!
version = "0.13.0";
2023-11-14 19:00:13 +01:00
# https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py
format = "pyproject";
2024-08-15 21:06:18 +02:00
src = builtins.fetchGit {
url = "https://codeberg.org/privacy1st/de-p1st-monitor";
rev = "7c57eba12a512a3a4fe72c2d5cbfa80cebdbd3bd";
2023-11-14 19:00:13 +01:00
};
propagatedBuildInputs = [
# Dependencies
pkgs.python3Packages.psutil
# Build dependencies
2024-08-15 21:06:18 +02:00
setuptools
2023-11-14 19:00:13 +01:00
build
twine
];
}
)
];
in
{
2023-11-20 14:09:10 +01:00
options = {
yoda.de-p1st-monitor = mkOption {
type = types.str;
example = ''
[logging]
dir = /var/log/de-p1st-monitor/
[network.1]
network_interface = wlan0
'';
description = ''
Content of /etc/de-p1st-monitor/''${hostname}.ini
'';
};
};
2023-11-14 19:00:13 +01:00
2023-11-20 14:09:10 +01:00
config = {
# 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" ];
2023-11-14 19:00:13 +01:00
2023-11-20 14:09:10 +01:00
# Create configuration file.
environment.etc."de-p1st-monitor/${config.networking.hostName}.ini".text = cfg;
# 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";
};
2023-11-14 19:00:13 +01:00
};
2023-11-20 14:09:10 +01:00
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
];
2023-11-14 19:00:13 +01:00
};
};
}