~sumner/home-manager-config

309ae9cd5574721c5b14b86d58c0da0fee4c62c6 — Sumner Evans 8 months ago 4a9739a
i3 to home-manager
M host-configurations/coruscant.nix => host-configurations/coruscant.nix +9 -0
@@ 1,4 1,13 @@
{ ... }: {
  xorg.enable = true;
  networking.interfaces = [ "enp37s0" "wlp35s0" ];
  programs.i3status-rust.extraBlocks = [
    {
      block = "custom";
      command = ''[[ "$(~/bin/current_audio_device)" =~ "PCM2704 16-bit stereo audio DAC" ]] && echo  ||  echo  '';
      on_click = "~/bin/toggle_audio";
      interval = 5;
      priority = 89;
    }
  ];
}

M programs/i3status-rust.nix => programs/i3status-rust.nix +134 -110
@@ 1,4 1,4 @@
{ config, lib, ... }: with lib; {
{ config, lib, pkgs, ... }: with lib; {
  options = {
    laptop.enable = mkOption {
      type = types.bool;


@@ 10,6 10,11 @@
      description = "A list of the network interfaces on the machine";
      default = [];
    };
    programs.i3status-rust.extraBlocks = mkOption {
      type = types.listOf (types.attrsOf types.anything);
      description = "A list of extra blocks to add.";
      default = [];
    };
  };

  config = {


@@ 17,116 22,135 @@
      enable = true;

      bars = {
        top = {
          icons = "awesome";
          theme = "slick";

          blocks = [
            {
              block = "custom";
              command = "echo  $(ls ~/.offlinemsmtp-outbox | wc -l)";
              interval = 10;
            }
            {
              block = "maildir";
              interval = 10;
              inboxes = map (f: "/home/sumner/Mail/${f}/INBOX")
                [ "Personal" "Mines" "Gmail" "TEF" ];
              threshold_warning = 25;
              threshold_critical = 50;
            }
            {
              block = "toggle";
              text = "Send Email?";
              command_state = "ls ~/tmp/offlinemsmtp-sendmail >/dev/null && echo 'Send Email'";
              command_on = "touch ~/tmp/offlinemsmtp-sendmail";
              command_off = "rm ~/tmp/offlinemsmtp-sendmail";
              interval = 5;
            }
            {
              block = "memory";
              format_mem = "{Mug}GiB";
              format_swap = "{SUg}GiB";
              warning_mem = 90;
              warning_swap = 90;
              critical_mem = 95;
              critical_swap = 95;
            }
            {
              block = "music";
              player = "sublimemusic";
              buttons = [ "play" "next" ];
            }

            (
              mkIf config.laptop.enable {
                block = "backlight";
              }
            )

            {
              block = "toggle";
              text = "CSM";
              command_state = "nmcli con show --active | grep 'Mines VPN'";
              command_on = "nmcli con up id 'Mines VPN'";
              command_off = "nmcli con down id 'Mines VPN'";
              interval = 5;
            }

            # Ping time
            {
              block = "custom";
              command = ''printf "P: %s" $(~/bin/parse-rolling-ping.sh)'';
              interval = 1;
            }
          ] ++ (
            # TODO: include the second "net" block if on a computer with two net blocks.
            map (
              dev: {
                block = "net";
                device = dev;
                ip = true;
                speed_down = false;
                graph_down = false;
                speed_up = false;
                graph_up = false;
                interval = 5;
                hide_missing = true;
                hide_inactive = true;
              }
            ) config.networking.interfaces
          ) ++ [
            {
              block = "sound";
              step_width = 2;
            }
            {
              block = "time";
              format = "%F %R:%S";
              interval = 1;
            }
            (
              mkIf config.laptop.enable {
                block = "battery";
                interval = 30;
                format = "{percentage}% {time}";
                device = "BAT0";
              }
            )
        top = let
          cu = "${pkgs.coreutils}/bin";
          dunstctl = "${pkgs.dunst}/bin/dunstctl";
          home = config.home.homeDirectory;
          homeTmp = "${config.home.homeDirectory}/tmp";
          nmcli = "${pkgs.networkmanager}/bin/nmcli";
        in
          {
            icons = "awesome";
            theme = "slick";

            # TODO need to figure out how to do this for Sway
            (
              mkIf config.xorg.enable {
                block = "toggle";
                text = "DND";
                command_state = "ls ~/tmp/dnd >/dev/null && echo 'DND'";
                command_on = "notify-send 'DUNST_COMMAND_PAUSE' && touch ~/tmp/dnd";
                command_off = "notify-send 'DUNST_COMMAND_RESUME' && rm ~/tmp/dnd";
                interval = 60;
              }
            )
          ];
        };
            blocks = map (x: builtins.removeAttrs x [ "priority" ]) (
              sort (a: b: a.priority < b.priority) (
                [
                  # Common blocks
                  {
                    block = "custom";
                    command = "echo  $(ls ${home}/.offlinemsmtp-outbox | ${cu}/wc -l)";
                    interval = 10;
                    priority = 0;
                  }
                  {
                    block = "maildir";
                    interval = 10;
                    inboxes = map (f: "${home}/Mail/${f}/INBOX") [ "Personal" "Mines" "Gmail" "TEF" ];
                    threshold_warning = 25;
                    threshold_critical = 50;
                    priority = 10;
                  }
                  {
                    block = "toggle";
                    text = "Send Email?";
                    command_state = "ls ${homeTmp}/offlinemsmtp-sendmail >/dev/null && echo 'Send Email'";
                    command_on = "${cu}/touch ${homeTmp}/offlinemsmtp-sendmail";
                    command_off = "${cu}/rm ${homeTmp}/offlinemsmtp-sendmail";
                    interval = 5;
                    priority = 20;
                  }
                  {
                    block = "memory";
                    format_mem = "{Mug}GiB";
                    format_swap = "{SUg}GiB";
                    warning_mem = 90;
                    warning_swap = 90;
                    critical_mem = 95;
                    critical_swap = 95;
                    priority = 30;
                  }
                  {
                    block = "music";
                    player = "sublimemusic";
                    buttons = [ (mkIf (!config.laptop.enable) "prev") "play" "next" ];
                    priority = 40;
                  }
                  {
                    block = "toggle";
                    text = "CSM";
                    command_state = "${nmcli} con show --active | ${pkgs.gnugrep}/bin/grep 'Mines VPN'";
                    command_on = "${nmcli} con up id 'Mines VPN'";
                    command_off = "${nmcli} con down id 'Mines VPN'";
                    interval = 5;
                    priority = 60;
                  }
                  {
                    # Ping time
                    block = "custom";
                    command = ''printf "P: %s" $(${home}/bin/parse-rolling-ping.sh)'';
                    interval = 1;
                    priority = 70;
                  }
                  {
                    block = "sound";
                    step_width = 2;
                    priority = 90;
                  }
                  {
                    block = "time";
                    format = "%F %R:%S";
                    interval = 1;
                    priority = 100;
                  }
                ] ++ (
                  # Include a "net" block for each of the network interfaces.
                  imap0 (
                    i: dev: {
                      block = "net";
                      device = dev;
                      ip = true;
                      speed_down = false;
                      graph_down = false;
                      speed_up = false;
                      graph_up = false;
                      interval = 5;
                      hide_missing = true;
                      hide_inactive = true;
                      priority = 80 + i;
                    }
                  ) config.networking.interfaces
                ) ++ (
                  optionals config.laptop.enable [
                    {
                      block = "backlight";
                      priority = 50;
                    }
                    {
                      block = "battery";
                      interval = 30;
                      format = "{percentage}% {time}";
                      device = "BAT0";
                      priority = 110;
                    }
                  ]
                ) ++ (
                  # TODO need to figure out how to do this for Sway
                  optionals config.xorg.enable [
                    {
                      block = "toggle";
                      text = "DND";
                      command_state = "[[ $(${dunstctl} is-paused) == true ]]";
                      command_on = "${dunstctl} set-paused true";
                      command_off = "${dunstctl} set-paused false";
                      interval = 60;
                      priority = 120;
                    }
                  ]
                ) ++ config.programs.i3status-rust.extraBlocks
              )
            );
          };
      };
    };
  };

M services/window-manager/common.nix => services/window-manager/common.nix +1 -7
@@ 46,7 46,7 @@
    down = "j";
    up = "k";
    right = "l";
    fonts = [ "Iosevka" "FontAwesome 12" ];
    fonts = [ "Iosevka" "FontAwesome 10" ];

    menucalc = pkgs.callPackage ../../pkgs/menucalc.nix {};
  in


@@ 54,7 54,6 @@
      enable = true;
      config = rec {
        inherit fonts;
        focus.forceWrapping = true;
        gaps.inner = gapSize;
        modifier = config.windowManager.modKey;
        terminal = config.home.sessionVariables.TERMINAL;


@@ 205,10 204,5 @@
          hideEdgeBorders = "both";
        };
      };
      extraConfig = ''
        seat * hide_cursor 2000
        # TODO REMOVE
        # vim ft=i3config
      '';
    };
}

M services/window-manager/wayland.nix => services/window-manager/wayland.nix +7 -1
@@ 11,7 11,6 @@ in
      description = "Enable the wayland stack";
      default = false;
    };

    wayland.extraSwayConfig = mkOption {
      type = types.attrsOf types.anything;
      description = "Extra config for Sway";


@@ 24,6 23,7 @@ in
      common.i3SwayConfig
      {
        wrapperFeatures.gtk = true;
        config.focus.forceWrapping = true;
        config.startup = let
          wlpaste = "${pkgs.wl-clipboard}/bin/wl-paste";
        in


@@ 64,6 64,12 @@ in
            "${modifier}+shift+c" = ''exec ${grim} -g "$(${slurp})" ${screenshotOutfile}'';
            "${modifier}+shift+ctrl+c" = "exec ${grim} ${screenshotOutfile}";
          };

        extraConfig = ''
          seat * hide_cursor 2000
          # TODO REMOVE
          # vim ft=i3config
        '';
      }
      cfg.extraSwayConfig
    ];

M services/window-manager/xorg.nix => services/window-manager/xorg.nix +44 -8
@@ 9,10 9,45 @@ in
      description = "Enable Xorg stack";
      default = false;
    };
    xorg.extrai3wmConfig = mkOption {
      type = types.attrsOf types.anything;
      description = "Extra config for i3wm";
      default = {};
    };
  };

  config = mkIf cfg.enable {
    xsession.windowManager.i3 = mkMerge [ common.i3SwayConfig ];
    xsession.windowManager.i3 = mkMerge [
      common.i3SwayConfig
      {
        config.startup = [
          { command = "${config.home.homeDirectory}/bin/display-configuration.sh"; }
        ];

        config.keybindings = let
          modifier = config.windowManager.modKey;
          scrot = "${pkgs.scrot}/bin/scrot";
          i3lockcmd = "${pkgs.i3lock-fancy}/bin/i3lock-fancy --font Iosevka -- ${scrot} -z";
          tmpdir = "${config.home.homeDirectory}/tmp";
        in
          {
            # Popup Clipboard Manager
            "${modifier}+c" = "exec ${pkgs.clipmenu}/bin/clipmenu";

            # Lock screen
            "${modifier}+Shift+x" = "exec ${config.home.homeDirectory}/bin/fuzzy_lock_sleep.sh";

            # exit i3wm (logs you out of your session)
            "${modifier}+Shift+e" = "exec ${pkgs.i3-gaps}/bin/i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'";

            # Screenshots
            "${modifier}+shift+c" = "${scrot} -s '%Y-%m-%d-%T.png' -e 'mv $f ${tmpdir} && xclip -selection clipboard -i ${tmpdir}/$f -t image/png'";
            "${modifier}+shift+ctrl+c" = "exec ${scrot}";
            "${modifier}+shift+f" = "exec ${pkgs.flameshot}/bin/flameshot gui -p ${tmpdir}";
          };
      }
      cfg.extrai3wmConfig
    ];

    services.clipmenu.enable = true;
    home.sessionVariables = {


@@ 36,20 71,21 @@ in
      };
      settings = {
        global = {
          corner_radius = 5;
          frame_color = "#8EC07C";
          geometry = "350x50-15+45";
          transparency = 10;
          padding = 6;
          horizontal_padding = 6;
          frame_color = "#8EC07C";
          corner_radius = 5;
          sort = false;
          idle_threshold = 30;
          markup = true;
          padding = 6;
          show_age_threshold = 20;
          show_indicators = false;
          transparency = 10;

          # Text
          font = "Iosevka Term 11";
          line_height = 3;
          font = "Iosevka 10";
          format = "<b>%s</b>\\n%b\\n%p";
          line_height = 3;
        };
      } // common.notificationColorConfig;
    };