nix: enable power-profiles-daemon while batmon is enabled; assert

This commit is contained in:
raf 2025-01-08 13:25:35 +03:00
parent cdf8a82c27
commit 9e387aa673
No known key found for this signature in database
GPG key ID: EED98D11B85A2819

View file

@ -4,7 +4,7 @@ self: {
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkForce; inherit (lib.modules) mkIf mkForce mkDefault;
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib) types; inherit (lib) types;
@ -37,16 +37,25 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
# Create the batmon configuration file in /etc/batmon.json environment = {
environment.etc."batmon.json".source = format.generate "batmon.json" cfg.settings; systemPackages = [cfg.package];
environment.systemPackages = [cfg.package]; # Create the batmon configuration file in /etc/batmon.json
etc."batmon.json".source = format.generate "batmon.json" cfg.settings;
};
# Batmon depends on power-profiles daemon
services.power-profiles-daemon.enable = mkDefault true;
systemd.user.services.batmon = { systemd.user.services.batmon = {
description = "Simple, reactive power management service"; description = "Simple, reactive power management service";
documentation = ["https://github.com/NotAShelf/batmon"]; documentation = ["https://github.com/NotAShelf/batmon"];
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath [cfg.package]}"; environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath [
# Batmon expects powerprofilesctl in PATH
config.services.power-profiles-daemon.package
]}";
script = '' script = ''
${lib.getExe cfg.package} --config /etc/batmon.json ${lib.getExe cfg.package} --config /etc/batmon.json
''; '';
@ -56,5 +65,12 @@ in {
Restart = "on-failure"; Restart = "on-failure";
}; };
}; };
assertions = [
{
assertion = config.services.power-profiles-daemon.enable;
message = "Batmon requies 'services.power-profiles-daemon.enable' to be true!";
}
];
}; };
} }