fork/home-manager
git clone https://git.julia.blue/fork/home-manager
e63a6b34
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . i3status-rust ; 8 9settingsFormat = pkgs . formats . toml { }; 10 11in { 12meta . maintainers = with lib . maintainers ; [ farlion thiagokokada ]; 13 14options . programs . i3status-rust = { 15enable = mkEnableOption "a replacement for i3-status written in Rust" ; 16 17bars = mkOption { 18type = types . attrsOf ( types . submodule { 19options = { 20 21blocks = mkOption { 22type = settingsFormat . type ; 23default = [ 24{ block = "cpu" ; } 25{ 26block = "disk_space" ; 27path = "/" ; 28info_type = "available" ; 29interval = 20 ; 30warning = 20.0 ; 31alert = 10.0 ; 32format = " $icon root: $available.eng(w:2) " ; 33} 34{ 35block = "memory" ; 36format = " $icon $mem_total_used_percents.eng(w:2) " ; 37format_alt = " $icon_swap $swap_used_percents.eng(w:2) " ; 38} 39{ 40block = "sound" ; 41click = [{ 42button = "left" ; 43cmd = "pavucontrol" ; 44}]; 45} 46{ 47block = "time" ; 48interval = 5 ; 49format = " $timestamp.datetime(f:'%a %d/%m %R') " ; 50} 51]; 52description = '' 53Configuration blocks to add to i3status-rust 54{file}`config`. See 55<https://github.com/greshake/i3status-rust/blob/master/blocks.md> 56for block options. 57'' ; 58example = literalExpression '' 59[ 60{ 61block = "disk_space"; 62path = "/"; 63info_type = "available"; 64interval = 60; 65warning = 20.0; 66alert = 10.0; 67} 68{ 69block = "sound"; 70format = " $icon $output_name {$volume.eng(w:2) |}"; 71click = [ 72{ 73button = "left"; 74cmd = "pavucontrol --tab=3"; 75} 76]; 77mappings = { 78"alsa_output.pci-0000_00_1f.3.analog-stereo" = ""; 79"bluez_sink.70_26_05_DA_27_A4.a2dp_sink" = ""; 80}; 81} 82]; 83'' ; 84}; 85 86settings = mkOption { 87type = settingsFormat . type ; 88default = { }; 89description = '' 90Any extra options to add to i3status-rust 91{file}`config`. 92'' ; 93example = literalExpression '' 94{ 95theme = { 96theme = "solarized-dark"; 97overrides = { 98idle_bg = "#123456"; 99idle_fg = "#abcdef"; 100}; 101}; 102} 103'' ; 104}; 105 106icons = mkOption { 107type = types . str ; 108default = "none" ; 109description = '' 110The icons set to use. See 111<https://github.com/greshake/i3status-rust/blob/master/doc/themes.md> 112for a list of available icon sets. 113'' ; 114example = "awesome6" ; 115}; 116 117theme = mkOption { 118type = types . str ; 119default = "plain" ; 120description = '' 121The theme to use. See 122<https://github.com/greshake/i3status-rust/blob/master/doc/themes.md> 123for a list of available themes. 124'' ; 125example = "gruvbox-dark" ; 126}; 127}; 128}); 129 130default = { 131default = { 132blocks = [ 133{ 134block = "disk_space" ; 135path = "/" ; 136info_type = "available" ; 137interval = 60 ; 138warning = 20.0 ; 139alert = 10.0 ; 140} 141{ 142block = "memory" ; 143format = " $icon mem_used_percents " ; 144format_alt = " $icon $swap_used_percents " ; 145} 146{ 147block = "cpu" ; 148interval = 1 ; 149} 150{ 151block = "load" ; 152interval = 1 ; 153format = " $icon $1m " ; 154} 155{ block = "sound" ; } 156{ 157block = "time" ; 158interval = 60 ; 159format = " $timestamp.datetime(f:'%a %d/%m %R') " ; 160} 161]; 162}; 163}; 164description = '' 165Attribute set of i3status-rust bars, each with their own configuration. 166Each bar {var}`name` generates a config file suffixed with 167the bar's {var}`name` from the attribute set, like so: 168{file}`config-''${name}.toml`. 169 170This way, multiple config files can be generated, such as for having a 171top and a bottom bar. 172 173See 174{manpage}`i3status-rust(1)` 175for options. 176'' ; 177example = literalExpression '' 178bottom = { 179blocks = [ 180{ 181block = "disk_space"; 182path = "/"; 183info_type = "available"; 184interval = 60; 185warning = 20.0; 186alert = 10.0; 187} 188{ 189block = "memory"; 190format_mem = " $icon $mem_used_percents "; 191format_swap = " $icon $swap_used_percents "; 192} 193{ 194block = "cpu"; 195interval = 1; 196} 197{ 198block = "load"; 199interval = 1; 200format = " $icon $1m "; 201} 202{ block = "sound"; } 203{ 204block = "time"; 205interval = 60; 206format = " $timestamp.datetime(f:'%a %d/%m %R') "; 207} 208]; 209settings = { 210theme = { 211theme = "solarized-dark"; 212overrides = { 213idle_bg = "#123456"; 214idle_fg = "#abcdef"; 215}; 216}; 217}; 218icons = "awesome5"; 219theme = "gruvbox-dark"; 220}; 221'' ; 222}; 223 224package = mkOption { 225type = types . package ; 226default = pkgs . i3status-rust ; 227defaultText = literalExpression "pkgs.i3status-rust" ; 228description = "Package providing i3status-rust" ; 229}; 230 231}; 232 233config = mkIf cfg . enable { 234assertions = [ 235( hm . assertions . assertPlatform "programs.i3status-rust" pkgs 236platforms . linux ) 237{ 238assertion = lib . versionOlder cfg . package . version "0.31.0" 239|| lib . versionAtLeast cfg . package . version "0.31.2" ; 240message = 241"Only i3status-rust <0.31.0 or ≥0.31.2 is supported due to a config format incompatibility." ; 242} 243]; 244 245home . packages = [ cfg . package ]; 246 247xdg . configFile = mapAttrs' ( cfgFileSuffix :cfgBar : 248nameValuePair ( "i3status-rust/config- ${ cfgFileSuffix } .toml" ) ({ 249onChange = '' 250${ pkgs . procps } /bin/pkill -u $USER -USR2 i3status-rs || true 251'' ; 252 253source = settingsFormat . generate ( "config- ${ cfgFileSuffix } .toml" ) ({ 254theme = if lib . versionAtLeast cfg . package . version "0.30.0" then { 255theme = cfgBar . theme ; 256} else 257cfgBar . theme ; 258icons = if lib . versionAtLeast cfg . package . version "0.30.0" then { 259icons = cfgBar . icons ; 260} else 261cfgBar . icons ; 262block = cfgBar . blocks ; 263} // cfgBar . settings ); 264})) cfg . bars ; 265}; 266}