This commit is contained in:
raf 2024-01-11 23:43:27 +03:00
commit 6221a470a3
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
7 changed files with 97 additions and 7 deletions

56
nix/module.nix Normal file
View file

@ -0,0 +1,56 @@
{
self,
config,
pkgs,
lib,
...
}: let
inherit (lib) mkIf mkForce types;
inherit (lib.options) mkOption mkEnableOption;
cfg = config.services.batmon;
in {
options.services.batmon = {
enable = mkEnableOption "batmon for real-time battery monitoring";
package = mkOption {
description = "The batmon package to use";
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.batmon;
};
settings = mkOption {
description = "Settings for Batmon";
type = types.attrs;
default = {};
example = lib.literalExpression ''
{
batPaths = [
{
path = "/sys/class/power_supply/BAT0";
extraCommand = "notify-send 'State changed!'";
}
];
}
'';
};
};
config = mkIf cfg.enable {
systemd.user.services."batmon" = {
description = "Power Monitoring Service";
environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath cfg.package}";
script = ''
${lib.getExe cfg.package} --config ${builtins.toJSON cfg.settings}
'';
serviceConfig = {
Type = "simple";
Restart = "on-failure";
};
wants = ["power-profiles-daemon.service"];
wantedBy = ["default.target"];
};
};
}

View file

@ -1,9 +1,9 @@
{buildGoModule}:
buildGoModule {
pname = "sample-go";
version = "0.0.1";
pname = "Batmon";
version = "0.1.0";
src = ./.;
src = ../.;
vendorHash = null;

View file

@ -1,9 +1,10 @@
{
packagePath,
callPackage,
gopls,
go,
}: let
mainPkg = callPackage ./default.nix {};
mainPkg = callPackage packagePath {};
in
mainPkg.overrideAttrs (oa: {
nativeBuildInputs =