~sumner/home-manager-config

007101e63fc3d74c5a251f22659d40fe9da1d54c — Sumner Evans 8 months ago 4cbfafd
Moving sway config to home-manager
8 files changed, 410 insertions(+), 130 deletions(-)

M host-configurations/mustafar.nix
M pkgs/sublime-music.nix
M services/default.nix
D services/wayland.nix
A services/window-manager/common.nix
R services/{window-manager.nix => window-manager/default.nix}
A services/window-manager/wayland.nix
R services/{xorg.nix => window-manager/xorg.nix}
M host-configurations/mustafar.nix => host-configurations/mustafar.nix +40 -1
@@ 1,5 1,44 @@
{ ... }: {
{ ... }: rec {
  wayland.enable = true;
  laptop.enable = true;
  networking.interfaces = [ "wlp0s20f3" ];
  windowManager.modKey = "Mod1"; # use Alt as modifier on mustafar

  wayland.extraSwayConfig.config = {
    # Scale to 1.75 instead of 2.
    output.eDP-1.scale = "1.75";
    input = {
      "*" = {
        # Use 3l for all keyboards that get attached
        xkb_layout = "us";
        xkb_variant = "3l";

        # Get right click (2 finger) and middle click (3 finger) on touchpad
        click_method = "clickfinger";

        # Always use natural scrolling
        natural_scroll = "enabled";
      };
      "1:1:AT_Translated_Set_2_keyboard" = {
        xkb_layout = "us";
        xkb_variant = "3l-cros";
      };

      # Don't scroll so fast
      "1739:52731:Synaptics_TM3579-001".scroll_factor = "0.75";

      # Map the inputs so rotation works.
      "11551:157:WCOM50C1:00_2D1F:009D".map_to_output = "eDP-1";
      "0:0:Elan_Touchscreen".map_to_output = "eDP-1";
    };

    keybindings = {
      # F6/F7 are the brightness up/down keys. Without mod, change screen
      # brightness. With mod, change the keyboard.
      F6 = "exec brightnessctl s 5%-";
      F7 = "exec brightnessctl s 5%+";
      "${windowManager.modKey}+F6" = "exec brightnessctl -d chromeos::kbd_backlight s 1%-";
      "${windowManager.modKey}+F7" = "exec brightnessctl -d chromeos::kbd_backlight s 1%+";
    };
  };
}

M pkgs/sublime-music.nix => pkgs/sublime-music.nix +23 -17
@@ 1,22 1,28 @@
{ fetchFromGitLab, lib, python3Packages, gobject-introspection, gtk3, pango, wrapGAppsHook
{ fetchFromGitLab
, gobject-introspection
, gtk3
, lib
, networkmanager
, python3
, pango
, python
, python3Packages
, wrapGAppsHook

, chromecastSupport ? true
, serverSupport ? true
, keyringSupport ? true
, notifySupport ? true, libnotify
, networkSupport ? true, networkmanager
, notifySupport ? true
, libnotify
, networkSupport ? true
}:

python3Packages.buildPythonApplication rec {
  pname = "sublime-music";
  pname = "sublime_music";
  version = "0.11.11";

  # src = /home/sumner/projects/sublime-music/sublime-music;
  src = fetchFromGitLab {
    owner = "sublime-music";
    repo = pname;
    rev = "v${version}";
    sha256 = "1147szdkvwvxslsby9scv1i8r4p5rj1if95f06y7q3l6n3zyg15g";
  src = python3.pkgs.fetchPypi {
    inherit pname version;
    sha256 = "0h5fhsl7zcvdrgawa0p118jzjs5ws1rlwbwv05klvdhzzrx2xwrs";
  };

  nativeBuildInputs = [


@@ 29,8 35,8 @@ python3Packages.buildPythonApplication rec {
    gtk3
    pango
  ]
   ++ lib.optional notifySupport libnotify
   ++ lib.optional networkSupport networkmanager
  ++ lib.optional notifySupport libnotify
  ++ lib.optional networkSupport networkmanager
  ;

  propagatedBuildInputs = with python3Packages; [


@@ 41,14 47,14 @@ python3Packages.buildPythonApplication rec {
    mpv
    peewee
    pygobject3
    python-Levenshtein
    python-dateutil
    python-Levenshtein
    requests
    semver
  ]
   ++ lib.optional chromecastSupport PyChromecast
   ++ lib.optional keyringSupport keyring
   ++ lib.optional serverSupport bottle
  ++ lib.optional chromecastSupport PyChromecast
  ++ lib.optional keyringSupport keyring
  ++ lib.optional serverSupport bottle
  ;

  # hook for gobject-introspection doesn't like strictDeps

M services/default.nix => services/default.nix +1 -3
@@ 3,10 3,8 @@
    ./offlinemsmtp.nix
    ./vdirsyncer.nix
    ./wallpaper.nix
    ./wayland.nix
    ./window-manager.nix
    ./window-manager
    ./writeping.nix
    ./xorg.nix
  ];

  services.blueman-applet.enable = true;

D services/wayland.nix => services/wayland.nix +0 -39
@@ 1,39 0,0 @@
{ config, lib, pkgs, ... }: with lib; let
  cfg = config.wayland;
in
{
  options = {
    wayland.enable = mkOption {
      type = types.bool;
      description = "Enable the wayland stack";
      default = false;
    };
  };

  config = mkIf cfg.enable {
    home.sessionVariables = {
      GTK_THEME = "Arc-Dark";
      MOZ_ENABLE_WAYLAND = "1";
      XDG_CURRENT_DESKTOP = "sway";
      XDG_SESSION_TYPE = "wayland";
    };

    home.packages = with pkgs; [
      clipman
    ];

    programs.mako = {
      enable = true;

      borderRadius = 5;
      borderSize = 2;
      defaultTimeout = 8000;
      font = "Iosevka 12";
      groupBy = "app-name,summary";
      sort = "-priority";
      width = 400;
    };

    # wayland.windowManager.sway.enable = true;
  };
}

A services/window-manager/common.nix => services/window-manager/common.nix +207 -0
@@ 0,0 1,207 @@
{ config, lib, pkgs }: with lib; {
  redshiftGammastepCfg = {
    enable = true;
    provider = "geoclue2";
    tray = true;

    temperature = {
      day = 5500;
      night = 4000;
    };
  };

  notificationColorConfig = {
    urgency_low = {
      frame_color = "#777777";
      foreground = "#777777";
      background = "#191311";
      timeout = 4;
    };

    urgency_normal = {
      frame_color = "#5B8234";
      foreground = "#5B8234";
      background = "#191311";
      timeout = 8;
    };

    urgency_critical = {
      frame_color = "#B7472A";
      foreground = "#B7472A";
      background = "#191311";
      timeout = 12;
    };
  };

  i3SwayConfig = let
    resizeStr = "  ";
    gapSize = 6;
    workspaces = [ "1: " "2" "3" "4" "5" "6" "7" "8" "9" "10" ];
    extraWorkspaces = [
      { name = "11: "; keycode = 20; }
      { name = "12: "; keycode = 21; }
    ];

    left = "h";
    down = "j";
    up = "k";
    right = "l";
    fonts = [ "Iosevka" "FontAwesome 12" ];

    menucalc = pkgs.callPackage ../../pkgs/menucalc.nix {};
  in
    {
      enable = true;
      config = rec {
        inherit fonts;
        gaps.inner = gapSize;
        modifier = config.windowManager.modKey;
        terminal = config.home.sessionVariables.TERMINAL;

        assigns = {
          # Browsers
          "${elemAt workspaces 0}" = [
            { class = "Pale moon"; }
            { class = "Firefox"; }
          ];

          # Chat Clients
          "${(elemAt extraWorkspaces 0).name}" = [
            { class = "discord"; }
            { class = "Element"; }
            { class = "HexChat"; }
            { class = "quassel"; }
            { class = "Slack"; }
            { class = "Telegram"; }
            { title = "Mutt"; }
          ];

          # Music
          "${(elemAt extraWorkspaces 1).name}" = [
            { class = "sublime-music"; }
          ];
        };

        bars = [
          {
            inherit fonts;
            position = "top";
            statusCommand = "${pkgs.i3status-rust}/bin/i3status-rs ${config.xdg.configHome}/i3status-rust/config-top.toml";
            colors = {
              background = "#00000090";
              separator = "#aaaaaa";
            };
          }
        ];

        floating.criteria = [
          { instance = "pinentry"; }
          { title = "Firefox - Sharing Indicator"; }
        ];

        keybindings = listToAttrs (
          # Switch to workspace
          (imap1 (i: name: { name = "${modifier}+${toString (mod i 10)}"; value = ''workspace "${name}"''; }) workspaces)
          # Move to workspace
          ++ (imap1 (i: name: { name = "${modifier}+Shift+${toString (mod i 10)}"; value = ''move container to workspace "${name}"''; }) workspaces)
        ) // {
          "${modifier}+Return" = "exec ${terminal}";
          "${modifier}+Shift+q" = "kill";

          # RESTART SWAY IN-PLACE (PRESERVES YOUR LAYOUT/SESSION, CAN BE USED TO UPGRADE SWAY)
          "${modifier}+Shift+R" = "reload";

          # LAUNCHERS
          "${modifier}+d" = "exec ${pkgs.rofi}/bin/rofi -show run";
          "${modifier}+space" = "exec ${pkgs.rofi}/bin/rofi -show drun -show-icons";
          F4 = "exec ${menucalc}/bin/= -- -lines 3"; # menu-calc
          F3 = "exec ${pkgs.rofi-pass}/bin/rofi-pass -- -i";

          # MOVEMENT
          "${modifier}+${left}" = "focus left";
          "${modifier}+${down}" = "focus down";
          "${modifier}+${up}" = "focus up";
          "${modifier}+${right}" = "focus right";

          # SPLIT IN HORIZONTAL/VERTICAL ORIENTATION
          "${modifier}+semicolon" = "split h";
          "${modifier}+v" = "split v";

          # CHANGE CONTAINER LAYOUT (STACKED, TABBED, TOGGLE SPLIT)
          "${modifier}+s" = "layout stacking";
          "${modifier}+w" = "layout tabbed";
          "${modifier}+e" = "layout toggle split";

          # ENTER FULLSCREEN MODE FOR THE FOCUSED CONTAINER
          "${modifier}+f" = "fullscreen toggle";

          # TOGGLE TILING / FLOATING
          button2 = "floating toggle";
          "${modifier}+Shift+space" = "floating toggle";

          # FOCUS THE PARENT CONTAINER
          "${modifier}+a" = "focus parent";

          # RESIZE
          "${modifier}+r" = ''mode "${resizeStr}"'';

          # GAPS
          "${modifier}+F3" = "gaps inner all set 0";
          "${modifier}+Shift+F3" = "gaps inner all set ${toString gapSize}";

          # VOLUME KEYS
          XF86AudioLowerVolume = "exec amixer set Master playback 2%-";
          XF86AudioRaiseVolume = "exec amixer set Master playback 2%+";
        };

        keycodebindings = listToAttrs (
          # Switch to workspace
          (imap1 (i: { name, keycode }: { name = "${modifier}+${toString keycode}"; value = ''workspace "${name}"''; }) extraWorkspaces)
          # Move to workspace
          ++ (imap1 (i: { name, keycode }: { name = "${modifier}+Shift+${toString keycode}"; value = ''move container to workspace "${name}"''; }) extraWorkspaces)
        ) // {
          "${modifier}+34" = "exec ${config.home.homeDirectory}/bin/mutt_helper.sh"; # Launch mutt
          "${modifier}+35" = "exec ${pkgs.element-desktop}/bin/element-desktop"; # Launch Element
        };

        modes = {
          "${resizeStr}" = {
            "${left}" = "resize shrink width 10 px";
            "${down}" = "resize grow height 10 px";
            "${up}" = "resize shrink height 10 px";
            "${right}" = "resize grow width 10 px";
            "Left" = "resize shrink width 10 px";
            "Down" = "resize grow height 10 px";
            "Up" = "resize shrink height 10 px";
            "Right" = "resize grow width 10 px";
            "Escape" = "mode default";
            "Return" = "mode default";
            "${modifier}+r" = "mode default";
          };
        };

        startup = let
          gsettings = "${pkgs.glib}/bin/gsettings";
          gnomeSchema = "org.gnome.desktop.interface";
        in
          [
            { command = "${config.home.homeDirectory}/bin/inactive-windows-transparency.py"; }

            # GTK
            { command = "${gsettings} set ${gnomeSchema} gtk-theme 'Arc-Dark'"; always = true; }
            { command = "${gsettings} set ${gnomeSchema} icon-theme 'Arc'"; always = true; }
            { command = "${gsettings} set ${gnomeSchema} cursor-theme 'breeze_cursors'"; always = true; }
          ];

        window = {
          border = 0;
          hideEdgeBorders = "both";
        };
      };
      extraConfig = ''
        seat * hide_cursor 2000
        # TODO REMOVE
        # vim ft=i3config
      '';
    };
}

R services/window-manager.nix => services/window-manager/default.nix +12 -69
@@ 3,41 3,21 @@
  terminal = "${pkgs.alacritty}/bin/alacritty";
  waylandCfg = config.wayland;
  xorgCfg = config.xorg;

  redshiftGammastepCfg = {
    enable = true;
    provider = "geoclue2";
    tray = true;

    temperature = {
      day = 5500;
      night = 4000;
in
{
  imports = [
    ./wayland.nix
    ./xorg.nix
  ];

  options = {
    windowManager.modKey = mkOption {
      type = types.enum [ "Shift" "Control" "Mod1" "Mod2" "Mod3" "Mod4" "Mod5" ];
      default = "Mod4";
      description = "Modifier key that is used for all default keybindings.";
    };
  };
  notificationColorConfig = {
    urgency_low = {
      frame_color = "#777777";
      foreground = "#777777";
      background = "#191311";
      timeout = 4;
    };

    urgency_normal = {
      frame_color = "#5B8234";
      foreground = "#5B8234";
      background = "#191311";
      timeout = 8;
    };

    urgency_critical = {
      frame_color = "#B7472A";
      foreground = "#B7472A";
      background = "#191311";
      timeout = 12;
    };
  };
in
{
  config = mkIf (waylandCfg.enable || xorgCfg.enable) {
    home.packages = with pkgs; [
      brightnessctl


@@ 52,43 32,6 @@ in
      TERMINAL = "${terminal}";
    };

    services = {
      # Redshift/gammastep
      gammastep = mkIf waylandCfg.enable redshiftGammastepCfg;
      redshift = mkIf xorgCfg.enable redshiftGammastepCfg;

      # Dunst
      dunst.settings = mkIf xorgCfg.enable notificationColorConfig;
    };

    # Mako
    programs.mako.extraConfig = mkIf waylandCfg.enable (
      generators.toINI {} (
        mapAttrs' (
          name: val: nameValuePair
            (builtins.replaceStrings "_" "=" name)
            (
              mapAttrs' (
                k: v:
                  nameValuePair
                    (
                      if k == "timeout" then "default-timeout"
                      else if k == "frame_color" then "border-color"
                      else if k == "foreground" then "text-color"
                      else if k == "background" then "background-color"
                      else k
                    )
                    (
                      if k == "timeout" then v * 1000
                      else if k == "background" then v + "CC"
                      else v
                    )
              ) val
            )
        ) notificationColorConfig
      )
    );

    gtk = {
      enable = true;
      iconTheme = {

A services/window-manager/wayland.nix => services/window-manager/wayland.nix +121 -0
@@ 0,0 1,121 @@
{ config, lib, options, pkgs, ... }: with lib; let
  cfg = config.wayland;
  common = import ./common.nix { inherit config lib pkgs; };
  clipmanHistpath = ''--histpath="${config.xdg.cacheHome}/clipman.json"'';
in
{
  options = {
    wayland.enable = mkOption {
      type = types.bool;
      description = "Enable the wayland stack";
      default = false;
    };

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

  config = mkIf cfg.enable {
    wayland.windowManager.sway = mkMerge [
      common.i3SwayConfig
      {
        config.startup = let
          wlpaste = "${pkgs.wl-clipboard}/bin/wl-paste";
          clipman = "${pkgs.clipman}/bin/clipman";
        in
          [
            { command = "${wlpaste} -t text --watch ${clipman} store ${clipmanHistpath}"; }
            { command = "${wlpaste} -p -t text --watch ${clipman} store -P ${clipmanHistpath}"; }
            { command = "${pkgs.mako}/bin/mako"; }
          ];

        config.keybindings = let
          modifier = config.windowManager.modKey;
          swaylockCmd = concatStringsSep " " [
            "${pkgs.swaylock-effects}/bin/swaylock"
            "--screenshots"
            "--clock"
            "--indicator"
            "--indicator-radius 100"
            "--indicator-thickness 7"
            "--effect-blur 7x5"
            "--effect-vignette 0.7:0.7"
            "--fade-in 0.5"
          ];
          grim = "${pkgs.grim}/bin/grim";
          slurp = "${pkgs.slurp}/bin/slupr";
          screenshotOutfile = "${config.home.homeDirectory}/tmp/$(${pkgs.coreutils}/bin/date +%Y-%m-%d-%T).png";
        in
          {
            # Popup Clipboard Manager
            "${modifier}+c" = "exec ${pkgs.clipman}/bin/clipman pick -t rofi ${clipmanHistpath}";

            # Lock screen
            "${modifier}+Shift+x" = "exec ${swaylockCmd}";

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

            # Screenshots
            "${modifier}+shift+c" = ''exec ${grim} -g "$(${slurp})" ${screenshotOutfile}'';
            "${modifier}+shift+ctrl+c" = "exec ${grim} ${screenshotOutfile}";
          };
      }
      cfg.extraSwayConfig
    ];

    home.sessionVariables = {
      GTK_THEME = "Arc-Dark";
      MOZ_ENABLE_WAYLAND = "1";
      XDG_CURRENT_DESKTOP = "sway";
      XDG_SESSION_TYPE = "wayland";
    };

    home.packages = with pkgs; [
      clipman
    ];

    # Gammastep
    services.gammastep = common.redshiftGammastepCfg;

    programs.mako = {
      enable = true;

      borderRadius = 5;
      borderSize = 2;
      defaultTimeout = 8000;
      font = "Iosevka 12";
      groupBy = "app-name,summary";
      sort = "-priority";
      width = 400;

      extraConfig = generators.toINI {} (
        mapAttrs' (
          name: val: nameValuePair
            (builtins.replaceStrings [ "_" ] [ "=" ] name)
            (
              mapAttrs' (
                k: v:
                  nameValuePair
                    (
                      if k == "timeout" then "default-timeout"
                      else if k == "frame_color" then "border-color"
                      else if k == "foreground" then "text-color"
                      else if k == "background" then "background-color"
                      else k
                    )
                    (
                      if k == "timeout" then v * 1000
                      else if k == "background" then v + "CC"
                      else v
                    )
              ) val
            )
        ) common.notificationColorConfig
      );
    };
  };
}

R services/xorg.nix => services/window-manager/xorg.nix +6 -1
@@ 1,5 1,6 @@
{ config, lib, pkgs, ... }: with lib; let
  cfg = config.xorg;
  common = import ./common.nix { inherit config lib pkgs; };
in
{
  options = {


@@ 11,6 12,8 @@ in
  };

  config = mkIf cfg.enable {
    xsession.windowManager.i3 = mkMerge [ common.i3SwayConfig ];

    services.clipmenu.enable = true;
    home.sessionVariables = {
      CM_HISTLENGTH = "20";


@@ 22,6 25,8 @@ in
    #   name = "Capitaine";
    # };

    services.redshift = common.redshiftGammastepCfg;

    services.dunst = {
      enable = true;
      iconTheme = {


@@ 46,7 51,7 @@ in
          line_height = 3;
          format = "<b>%s</b>\\n%b\\n%p";
        };
      };
      } // common.notificationColorConfig;
    };

    services.picom = {