mirror of
https://github.com/NotAShelf/batmon.git
synced 2025-01-19 00:12:40 +00:00
nix: modernize
This commit is contained in:
parent
514eb6617e
commit
0e6979f684
5 changed files with 48 additions and 39 deletions
|
@ -2,15 +2,16 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1705003311,
|
||||
"narHash": "sha256-7JtTAgeUHGKA9phwPveHtwvaQCDrta1yR5t7MYSMcCU=",
|
||||
"lastModified": 1736012469,
|
||||
"narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "3680fef792863c8b7bf52f0d474a16319995eabd",
|
||||
"rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
description = "Batmon - battery monitor";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
|
@ -11,7 +11,8 @@
|
|||
pkgsForEach = nixpkgs.legacyPackages;
|
||||
in {
|
||||
nixosModules = {
|
||||
batmon = ./nix/module.nix {inherit self;};
|
||||
batmon = import ./nix/module.nix self;
|
||||
default = self.nixosModules.batmon;
|
||||
};
|
||||
|
||||
packages = forEachSystem (system: {
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
{
|
||||
self,
|
||||
self: {
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkIf mkForce types;
|
||||
inherit (lib.modules) mkIf mkForce;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib) types;
|
||||
|
||||
format = pkgs.formats.json {};
|
||||
cfg = config.services.batmon;
|
||||
in {
|
||||
options.services.batmon = {
|
||||
|
@ -20,25 +21,26 @@ in {
|
|||
};
|
||||
|
||||
settings = mkOption {
|
||||
description = "Settings for Batmon";
|
||||
type = types.attrs;
|
||||
type = format.type;
|
||||
default = {};
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
example = {
|
||||
batPaths = [
|
||||
{
|
||||
path = "/sys/class/power_supply/BAT0";
|
||||
extraCommand = "notify-send 'State changed!'";
|
||||
}
|
||||
];
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
description = "Settings for BatmoSettings for Batmonn";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.user.services."batmon" = {
|
||||
description = "Power Monitoring Service";
|
||||
wants = ["power-profiles-daemon.service"];
|
||||
wantedBy = ["default.target"];
|
||||
environment.PATH = mkForce "/run/wrappers/bin:${lib.makeBinPath cfg.package}";
|
||||
script = ''
|
||||
${lib.getExe cfg.package} --config ${builtins.toJSON cfg.settings}
|
||||
|
@ -47,10 +49,8 @@ in {
|
|||
serviceConfig = {
|
||||
Type = "simple";
|
||||
Restart = "on-failure";
|
||||
DynamicUser = true;
|
||||
};
|
||||
|
||||
wants = ["power-profiles-daemon.service"];
|
||||
wantedBy = ["default.target"];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
{buildGoModule}:
|
||||
{
|
||||
lib,
|
||||
buildGoModule,
|
||||
}:
|
||||
buildGoModule {
|
||||
pname = "Batmon";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ../.;
|
||||
src = builtins.path {
|
||||
path = ../.;
|
||||
name = "batmon-src";
|
||||
};
|
||||
|
||||
vendorHash = null;
|
||||
|
||||
ldflags = ["-s" "-w"];
|
||||
|
||||
meta = {
|
||||
license = lib.licenses.gpl3Only;
|
||||
maintainers = [lib.maintainers.NotAShelf];
|
||||
mainProgram = "batmon";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
{
|
||||
packagePath,
|
||||
callPackage,
|
||||
mkShellNoCC,
|
||||
gopls,
|
||||
go,
|
||||
}: let
|
||||
mainPkg = callPackage packagePath {};
|
||||
in
|
||||
mainPkg.overrideAttrs (oa: {
|
||||
nativeBuildInputs =
|
||||
(oa.nativeBuildInputs or [])
|
||||
++ [
|
||||
}:
|
||||
mkShellNoCC {
|
||||
name = "batmon";
|
||||
packages = [
|
||||
gopls
|
||||
go
|
||||
];
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue