From 139e36a39353d9821e773743ed4e796d8c96a58d Mon Sep 17 00:00:00 2001 From: aszlig Date: Fri, 2 May 2014 02:27:33 +0200 Subject: i3: Factor out conky configuration for i3bar. Now we're generating full conky config files and we now have a new conky.nix, which generates shell scripts for the left and right screens, that run conky with the right configuration files. Signed-off-by: aszlig --- modules/i3/conky.nix | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ modules/i3/default.nix | 30 +++++++----------- modules/i3/i3.conf | 4 +-- 3 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 modules/i3/conky.nix (limited to 'modules') diff --git a/modules/i3/conky.nix b/modules/i3/conky.nix new file mode 100644 index 00000000..9463ae32 --- /dev/null +++ b/modules/i3/conky.nix @@ -0,0 +1,84 @@ +{ pkgs ? import {} }: + +with pkgs.lib; + +let + mkConfig = text: pkgs.writeText "conkyrc" '' + cpu_avg_samples 2 + net_avg_samples 2 + no_buffers yes + out_to_console yes + out_to_ncurses no + out_to_stderr no + extra_newline no + update_interval 1.0 + uppercase no + use_spacer none + pad_percents 3 + use_spacer left + TEXT + ${text} + ''; + + cexpr = name: args: "\${${name} ${concatStringsSep " " args}}"; + + primaryNetInterface = "enp0s25"; + + mkCpuLoad = threads: let + mkThread = thread: (cexpr "cpu" [ "cpu${toString thread}" ]) + "%"; + loads = map mkThread (range 1 threads); + in concatStringsSep " " loads; + + mkCpuTemp = cores: let + mkCore = core: (cexpr "platform" [ + "coretemp.0" + "temp" + "${toString (core + 1)}" + ]) + "C"; + temps = map mkCore (range 1 cores); + in concatStringsSep " " temps; + + mkNetInfo = iface: let + upspeed = cexpr "upspeed" [ iface ]; + downspeed = cexpr "downspeed" [ iface ]; + in "${upspeed} ${downspeed}"; + + mkDiskFree = path: let + used = cexpr "fs_used" [ path ]; + size = cexpr "fs_size" [ path ]; + in "${used}/${size}"; + + gpuTemp = "${cexpr "hwmon" [ "0" "temp" "1" ]}C"; + + weather = (cexpr "weather" [ + "http://weather.noaa.gov/pub/data/observations/metar/stations/" + "EDMA" + "temperature" + ]) + "C"; + + mkConky = args: let + time = cexpr "time" [ "%a %b %d %T %Z %Y" ]; + text = concatStringsSep " | " (args ++ singleton time); + conky = pkgs.conky.override { + weatherMetar = true; + }; + cfg = mkConfig text; + in pkgs.writeScript "conky-run.sh" '' + #!${pkgs.stdenv.shell} + ${conky}/bin/conky -c "${cfg}" + ''; + +in { + left = mkConky [ + "CPU: ${mkCpuLoad 8} - ${cexpr "cpu" [ "cpu0" ]}%" + "MEM: $mem/$memmax - $memperc%" + "SWAP: $swap/$swapmax $swapperc%" + ]; + + right = mkConky [ + "NET: ${mkNetInfo primaryNetInterface}" + "DF: ${mkDiskFree "/"}" + "LAVG: $loadavg" + "TEMP - CPU: ${mkCpuTemp 4} - GPU: ${gpuTemp} - OUTSIDE: ${weather}" + ]; +} diff --git a/modules/i3/default.nix b/modules/i3/default.nix index 99849bf4..bbfe4658 100644 --- a/modules/i3/default.nix +++ b/modules/i3/default.nix @@ -1,36 +1,28 @@ { pkgs, config, ... }: +with pkgs.lib; + { services.xserver.windowManager = { default = "i3"; i3.enable = true; - i3.configFile = with pkgs.lib; pkgs.substituteAll ({ + i3.configFile = let + conky = import ./conky.nix { + inherit pkgs; + }; + in pkgs.substituteAll ({ name = "i3.conf"; src = ./i3.conf; - inherit (pkgs) conky dmenu xterm pvolctrl; + inherit (pkgs) dmenu xterm pvolctrl; inherit (pkgs.xorg) xsetroot; + leftHead = head config.services.xserver.xrandrHeads; rightHead = last config.services.xserver.xrandrHeads; - primaryNetInterface = "enp0s25"; - - conkyrc = pkgs.writeText "conkyrc" '' - cpu_avg_samples 2 - net_avg_samples 2 - no_buffers yes - out_to_console yes - out_to_ncurses no - out_to_stderr no - extra_newline no - update_interval 1.0 - uppercase no - use_spacer none - pad_percents 3 - use_spacer left - TEXT - ''; + leftConky = conky.left; + rightConky = conky.right; } // (let # Workaround for Synergy: we need to have polarizing heads. leftHead = head config.services.xserver.xrandrHeads; diff --git a/modules/i3/i3.conf b/modules/i3/i3.conf index 6ae4a3a7..d6273489 100644 --- a/modules/i3/i3.conf +++ b/modules/i3/i3.conf @@ -166,7 +166,7 @@ for_window [class="^Dia$"] floating enable # bar configuration bar { output @leftHead@ - status_command @conky@/bin/conky -c "@conkyrc@" -t 'CPU: ${cpu cpu1}% ${cpu cpu2}% ${cpu cpu3}% ${cpu cpu4}% ${cpu cpu5}% ${cpu cpu6}% ${cpu cpu7}% ${cpu cpu8}% - ${cpu cpu0}% | MEM: $mem/$memmax - $memperc% | SWAP: $swap/$swapmax $swapperc% | ${time %a %b %d %T %Z %Y}' + status_command @leftConky@ colors { focused_workspace #5c5cff #e5e5e5 @@ -178,7 +178,7 @@ bar { bar { output @rightHead@ - status_command @conky@/bin/conky -c "@conkyrc@" -t 'NET: ${upspeed @primaryNetInterface@} ${downspeed @primaryNetInterface@} | DF: ${fs_used /}/${fs_size /} | LAVG: $loadavg | TEMP - CPU: ${platform coretemp.0 temp 2}C ${platform coretemp.0 temp 3}C ${platform coretemp.0 temp 4}C ${platform coretemp.0 temp 5}C - GPU: ${hwmon 0 temp 1}C - OUTSIDE: ${weather http://weather.noaa.gov/pub/data/observations/metar/stations/ EDMA temperature}C | ${time %a %b %d %T %Z %Y}' + status_command @rightConky@ colors { focused_workspace #5c5cff #e5e5e5 -- cgit 1.4.1