-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nix): flake + home manager module
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "nixpkgs/nixos-unstable"; | ||
systems.url = "github:nix-systems/default-linux"; | ||
}; | ||
|
||
outputs = inputs @ { | ||
self, | ||
nixpkgs, | ||
systems, | ||
... | ||
}: let | ||
inherit (nixpkgs) lib; | ||
eachSystem = lib.genAttrs (import systems); | ||
pkgsFor = eachSystem (system: | ||
import nixpkgs { | ||
localSystem = system; | ||
}); | ||
in { | ||
packages = eachSystem (system: let | ||
pkgs = pkgsFor.${system}; | ||
in { | ||
default = self.packages.${system}.battery-notifier; | ||
battery-notifier = pkgs.callPackage ./default.nix {}; | ||
}); | ||
|
||
homeManagerModule.default = import ./nix/hm-module.nix self; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
self: { | ||
config, | ||
pkgs, | ||
lib, | ||
... | ||
}: | ||
with lib; let | ||
inherit (pkgs.stdenv.hostPlatform) system; | ||
tomlFormat = pkgs.formats.toml {}; | ||
flake-pkgs = self.packages.${system}; | ||
in { | ||
options.programs.battery-notifier = let | ||
settingsModule = types.submodule { | ||
options = { | ||
interval_ms = mkOption { | ||
type = types.int; | ||
default = 700; | ||
}; | ||
|
||
reminder_threshold = mkOption { | ||
type = types.int; | ||
default = 30; | ||
}; | ||
|
||
warn_threshold = mkOption { | ||
type = types.int; | ||
default = 15; | ||
}; | ||
|
||
threat_threshold = mkOption { | ||
type = types.int; | ||
default = 5; | ||
}; | ||
}; | ||
}; | ||
in { | ||
enable = mkEnableOption "battery-notifier"; | ||
|
||
settings = mkOption { | ||
default = null; | ||
type = types.nullOr settingsModule; | ||
}; | ||
}; | ||
|
||
config = let | ||
cfg = config.programs.battery-notifier; | ||
in | ||
mkIf cfg.enable { | ||
assertions = mkIf (cfg.settings != null) [ | ||
{ | ||
assertion = builtins.length (lib.attrsets.attrValues (lib.attrsets.filterAttrs (k: v: lib.strings.hasSuffix k "threshold" && v >= 0 && v <= 100) cfg.settings)) == 0; | ||
message = "threshold values must be greater equal than 0 and less equal than 100"; | ||
} | ||
{ | ||
assertion = cfg.settings.reminder_threshold > cfg.settings.warn_threshold; | ||
message = "'reminder' threshold must be greater than 'warn' threshold"; | ||
} | ||
{ | ||
assertion = cfg.settings.warn_threshold > cfg.settings.threat_threshold; | ||
message = "'warn' threshold must be greater than 'threat' threshold"; | ||
} | ||
{ | ||
assertion = cfg.settings.sleep_ms > 0; | ||
message = "sleep time must be greater than zero"; | ||
} | ||
]; | ||
|
||
xdg.configFile = mkIf (cfg.settings != null) { | ||
"battery-notifier/config.toml".source = tomlFormat.generate "battery-notifier-config" cfg.settings; | ||
}; | ||
|
||
systemd.user.services = { | ||
battery-notifier = { | ||
Unit = { | ||
Description = "A very useful battery notifier for window managers"; | ||
}; | ||
|
||
Service = { | ||
Type = "simple"; | ||
ExecStart = "${flake-pkgs.battery-notifier}/bin/battery-notifier"; | ||
Restart = "on-failure"; | ||
}; | ||
|
||
Install = { | ||
WantedBy = ["default.target"]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |