systant/nix/nixos-module.nix
ryan 1629c8d5d2 refactor: switch to home-manager module
Systant is a userspace controller, so it makes sense to manage it
via home-manager rather than as a system service. This allows:
- Declarative per-user configuration
- Access to user's environment, PATH, and session
- Proper handling of audio, display, and other user resources

Usage in home-manager config:
  imports = [ inputs.systant.homeManagerModules.default ];
  services.systant.enable = true;
  services.systant.settings = { ... };

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 21:02:09 -08:00

90 lines
2.3 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.services.systant;
settingsFormat = pkgs.formats.toml { };
configFile =
if cfg.configFile != null
then cfg.configFile
else if cfg.settings != { }
then settingsFormat.generate "systant-config.toml" cfg.settings
else null;
in
{
options.services.systant = {
enable = lib.mkEnableOption "systant system monitoring agent";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.systant;
defaultText = lib.literalExpression "pkgs.systant";
description = "The systant package to use.";
};
configFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to the systant configuration file (TOML).
If set, this takes precedence over the settings option.
'';
};
settings = lib.mkOption {
type = settingsFormat.type;
default = { };
description = ''
Configuration for systant in Nix attribute set form.
Will be converted to TOML. Ignored if configFile is set.
'';
example = lib.literalExpression ''
{
mqtt = {
broker = "mqtt://localhost:1883";
topicPrefix = "systant";
};
entities = {
cpu_usage = {
type = "sensor";
state_command = "awk '/^cpu / {u=$2+$4; t=$2+$4+$5; print int(u*100/t)}' /proc/stat";
unit = "%";
icon = "mdi:cpu-64-bit";
name = "CPU Usage";
};
};
homeassistant = {
discovery = true;
discoveryPrefix = "homeassistant";
};
}
'';
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
systemd.user.services.systant = {
Unit = {
Description = "Systant system monitoring agent";
After = [ "network-online.target" ];
Wants = [ "network-online.target" ];
};
Service = {
Type = "simple";
ExecStart =
if configFile != null
then "${cfg.package}/bin/systant run --config ${configFile}"
else "${cfg.package}/bin/systant run";
Restart = "on-failure";
RestartSec = "5s";
};
Install = {
WantedBy = [ "default.target" ];
};
};
};
}