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

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

View file

@ -44,7 +44,7 @@ directory. You can specify a different configuration file using the `--config`
flag: flag:
```console ```console
gomon -c /path/to/config.json batmon -c /path/to/config.json
``` ```
The configuration file should contain a list of batteries to monitor, along The configuration file should contain a list of batteries to monitor, along

26
flake.lock Normal file
View file

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1705003311,
"narHash": "sha256-7JtTAgeUHGKA9phwPveHtwvaQCDrta1yR5t7MYSMcCU=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3680fef792863c8b7bf52f0d474a16319995eabd",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

View file

@ -10,13 +10,19 @@
forEachSystem = nixpkgs.lib.genAttrs systems; forEachSystem = nixpkgs.lib.genAttrs systems;
pkgsForEach = nixpkgs.legacyPackages; pkgsForEach = nixpkgs.legacyPackages;
in { in {
nixosModules = {
batmon = ./nix/module.nix {inherit self;};
};
packages = forEachSystem (system: { packages = forEachSystem (system: {
batmon = pkgsForEach.${system}.callPackage ./nix/package.nix {}; batmon = pkgsForEach.${system}.callPackage ./nix/package.nix {};
default = self.${system}.batmon; default = self.packages.${system}.batmon;
}); });
devShells = forEachSystem (system: { devShells = forEachSystem (system: {
default = pkgsForEach.${system}.callPackage ./nix/shell.nix {}; default = pkgsForEach.${system}.callPackage ./nix/shell.nix {
packagePath = ./nix/package.nix;
};
}); });
}; };
} }

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}:
buildGoModule { buildGoModule {
pname = "sample-go"; pname = "Batmon";
version = "0.0.1"; version = "0.1.0";
src = ./.; src = ../.;
vendorHash = null; vendorHash = null;

View file

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