From 9e387aa6731792dc879afd5a6ad98a3e63571387 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Wed, 8 Jan 2025 13:25:35 +0300 Subject: [PATCH] nix: enable power-profiles-daemon while batmon is enabled; assert --- nix/module.nix | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/nix/module.nix b/nix/module.nix index 7e94df7..bbfe79e 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -4,7 +4,7 @@ self: { lib, ... }: let - inherit (lib.modules) mkIf mkForce; + inherit (lib.modules) mkIf mkForce mkDefault; inherit (lib.options) mkOption mkEnableOption; inherit (lib) types; @@ -37,16 +37,25 @@ in { }; config = mkIf cfg.enable { - # Create the batmon configuration file in /etc/batmon.json - environment.etc."batmon.json".source = format.generate "batmon.json" cfg.settings; + environment = { + 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 = { description = "Simple, reactive power management service"; documentation = ["https://github.com/NotAShelf/batmon"]; 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 = '' ${lib.getExe cfg.package} --config /etc/batmon.json ''; @@ -56,5 +65,12 @@ in { Restart = "on-failure"; }; }; + + assertions = [ + { + assertion = config.services.power-profiles-daemon.enable; + message = "Batmon requies 'services.power-profiles-daemon.enable' to be true!"; + } + ]; }; }