{ config, pkgs, lib, ... }:
let
  inherit (builtins) listToAttrs;
  inherit (lib.lists) imap1 forEach reverseList elemAt;
  modules = [
    {
      name = "time";
      settings = {
        format = "%Y %m/%d %a | %H:%M:%S";
      };
    }
    {
      name = "load";
      settings = {
        format = "LD %1min:%5min:%15min";
        format_above_threshold = "LD H (%1min:%5min)";
        max_threshold = "4.9";
      };
    }
    {
      name = "memory";
      settings = {
        memory_used_method = "classical";
        decimals = "1";
        unit = "Mi";
        format = "%available (%used) / %total";
        format_degraded = "Mem LOW (%available)";
        threshold_degraded = "10%";
        threshold_critical = "6.25%";
      };
    }
    {
      name = "disk /";
      settings = {
        prefix_type = "decimal";
        format = "/ %percentage_used";
      };
    }
    {
      name = "volume master";
      settings = {
        format = "Vol: %volume";
        format_muted = "Vol: Muted (%volume)";
      };
    }
    {
      name = "wireless _first_";
      settings = {
        format_up = "W: (%quality @ %essid w/ %bitrate) %ip";
        format_down = "W: down";
        format_bitrate = "%g %cb/s";
        format_quality = "%03d%s";
      };
    }
  ];
  numberedModulesList = imap1 (i: v:
    v // { position = i; }
  ) (reverseList modules);
  modNameValList = forEach numberedModulesList (x: {
    name = x.name;
    value = {
      inherit (x) settings position;
    };
  });
  modAttr = listToAttrs modNameValList;
in
{
  programs.i3status = {
    enable = true;
    enableDefault = false;
    general = {
      output_format = "i3bar";
      interval = 1;
      colors = true;
      color_separator = "#FFFFFF";
      color_good = "#00FF00";
      color_degraded = "#00FFFF";
      color_bad = "#FF0000";
      separator = "｜";
    };
    modules = modAttr;
  };
}
