fork/home-manager
git clone https://git.julia.blue/fork/home-manager
f540f30f
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . cbatticon ; 8 9package = pkgs . cbatticon ; 10 11makeCommand = commandName :commandArg : 12optional ( commandArg != null ) 13( let cmd = pkgs . writeShellScript commandName commandArg ; 14in "-- ${ commandName } ${ cmd } " ); 15 16commandLine = concatStringsSep " " ([ " ${ package } /bin/cbatticon" ] 17++ makeCommand "command-critical-level" cfg . commandCriticalLevel 18++ makeCommand "command-left-click" cfg . commandLeftClick 19++ optional ( cfg . iconType != null ) "--icon-type ${ cfg . iconType } " 20++ optional ( cfg . lowLevelPercent != null ) 21"--low-level ${ toString cfg . lowLevelPercent } " 22++ optional ( cfg . criticalLevelPercent != null ) 23"--critical-level ${ toString cfg . criticalLevelPercent } " 24++ optional ( cfg . updateIntervalSeconds != null ) 25"--update-interval ${ toString cfg . updateIntervalSeconds } " 26++ optional ( cfg . hideNotification != null && cfg . hideNotification ) 27"--hide-notification" ++ optional ( cfg . batteryId != null ) cfg . batteryId ); 28 29in { 30meta . maintainers = [ maintainers . pmiddend ]; 31 32options = { 33services . cbatticon = { 34enable = mkEnableOption "cbatticon" ; 35 36commandCriticalLevel = mkOption { 37type = types . nullOr types . lines ; 38default = null ; 39example = '' 40notify-send "battery critical!" 41'' ; 42description = '' 43Command to execute when the critical battery level is reached. 44'' ; 45}; 46 47commandLeftClick = mkOption { 48type = types . nullOr types . lines ; 49default = null ; 50description = '' 51Command to execute when left clicking on the tray icon. 52'' ; 53}; 54 55iconType = mkOption { 56type = 57types . nullOr ( types . enum [ "standard" "notification" "symbolic" ]); 58default = null ; 59example = "symbolic" ; 60description = "Icon type to display in the system tray." ; 61}; 62 63lowLevelPercent = mkOption { 64type = types . nullOr ( types . ints . between 0 100 ); 65default = null ; 66example = 20 ; 67description = '' 68Low level percentage of the battery in percent (without the 69percent symbol). 70'' ; 71}; 72 73criticalLevelPercent = mkOption { 74type = types . nullOr ( types . ints . between 0 100 ); 75default = null ; 76example = 5 ; 77description = '' 78Critical level percentage of the battery in percent (without 79the percent symbol). 80'' ; 81}; 82 83updateIntervalSeconds = mkOption { 84type = types . nullOr types . ints . positive ; 85default = null ; 86example = 5 ; 87description = '' 88Number of seconds between updates of the battery information. 89'' ; 90}; 91 92hideNotification = mkOption { 93type = types . nullOr types . bool ; 94default = null ; 95description = "Hide the notification popups." ; 96}; 97 98batteryId = mkOption { 99type = types . nullOr types . str ; 100default = null ; 101description = '' 102ID of the battery to monitor. List with {command}`cbatticon -p`. 103Defaults to the first entry in the list. 104'' ; 105}; 106}; 107}; 108 109config = mkIf cfg . enable { 110assertions = [ 111( lib . hm . assertions . assertPlatform "services.cbatticon" pkgs 112lib . platforms . linux ) 113]; 114 115home . packages = [ package ]; 116 117systemd . user . services . cbatticon = { 118Unit = { 119Description = "cbatticon system tray battery icon" ; 120Requires = [ "tray.target" ]; 121After = [ "graphical-session-pre.target" "tray.target" ]; 122PartOf = [ "graphical-session.target" ]; 123}; 124 125Install = { WantedBy = [ "graphical-session.target" ]; }; 126 127Service = { 128ExecStart = commandLine ; 129Restart = "on-abort" ; 130}; 131}; 132}; 133}