diff --git a/home/modules/programs/my-sway/default.nix b/home/modules/programs/my-sway/default.nix new file mode 100644 index 0000000..f9b8b91 --- /dev/null +++ b/home/modules/programs/my-sway/default.nix @@ -0,0 +1,423 @@ +{ pkgs, lib, config, ... }: +with lib; +let + cfg = config.programs.my-sway; + + mod = "Mod4"; + # List of workspaces + workspaces = [ + "1: web" + "2: chat" + "3: code" + "4: music" + "5: extra" + "6: 6" + "7: 7" + "8: 8" + "9: 9" + "10: 10" + ]; + wsAttrs = builtins.listToAttrs ( + map + (i: { name = toString (remainder i 10); value = builtins.elemAt workspaces (i - 1); }) + (range 1 11) + ); + remainder = x: y: x - (builtins.div x y) * y; + range = from: to: + let + f = cur: if cur == to then [ ] else [ cur ] ++ f (cur + 1); + in + f from; + +in +{ + options.programs.my-sway = { + enable = mkEnableOption "Enable the sway configuration"; + fontSize = mkOption { + type = types.float; + description = "The default font size"; + }; + enableTouchpad = mkOption { + type = types.bool; + description = "Whether to enable the touchpad"; + default = true; + }; + wallpaper = mkOption { + type = types.oneOf [ types.path types.str ]; + description = "Path to the wallpaper to be used"; + default = ""; + }; + terminal = mkOption { + type = types.str; + description = "The command to the terminal emulator to be used"; + default = "${pkgs.alacritty}/bin/alacritty"; + }; + }; + + config.wayland.windowManager.sway = mkIf cfg.enable { + enable = true; + + config = { + ### Inputs + # + # Touchpad + input."type=touchpad" = { + events = if cfg.enableTouchpad then "enabled" else "disabled"; + }; + # TODO: Keyboard + + ### Outputs + # + # Wallpaper + output."*".bg = if cfg.wallpaper == "" then "#000000 solid_color" else "${cfg.wallpaper} fill"; + + ### Programs + # + # Terminal + terminal = cfg.terminal; + # Startup + startup = [ + # Dex for autostart + { command = "${pkgs.dex}/bin/dex -ae sway"; } + # Waybar + { command = "systemctl --user restart waybar"; always = true; } + ]; + + ### Keybindings + # + # Main modifier + modifier = mod; + keybindings = lib.mkOptionDefault ({ + ## Splits + "${mod}+v" = "split v"; + "${mod}+Shift+v" = "split h"; + ## Run + "${mod}+r" = config.wayland.windowManager.sway.config.menu; + "${mod}+Shift+r" = "mode resize"; + # "${mod}+d" = "exec i3-dmenu-desktop --dmenu='${pkgs.dmenu}/bin/dmenu -i'"; + } // ( + # Map the workspaces + builtins.listToAttrs (lib.flatten (map + (key: [ + { + name = "${mod}+${key}"; + value = "workspace ${builtins.getAttr key wsAttrs}"; + } + { + name = "${mod}+Shift+${key}"; + value = "move to workspace ${builtins.getAttr key wsAttrs}"; + } + ]) + (builtins.attrNames wsAttrs)) + ))); + + ### Fonts + # + fonts = { + names = [ "monospace" "FontAwesome5Free" ]; + size = cfg.fontSize; + }; + + ### Workspaces + # + # Default workspace + defaultWorkspace = "workspace ${builtins.elemAt workspaces 0}"; + # Back and Forth + workspaceAutoBackAndForth = true; + + ### Windows + # + # Border + window.border = 2; + # Assigning windows to workspaces + assigns = { + "${builtins.elemAt workspaces 0}" = [ + { class = "^firefox$"; } + ]; + "${builtins.elemAt workspaces 1}" = [ + { class = "^Discord$"; } + ]; + }; + focus.followMouse = true; + focus.mouseWarping = false; + focus.newWindow = "urgent"; + # Gaps + gaps.outer = 3; + gaps.inner = 4; + gaps.smartBorders = "on"; + gaps.smartGaps = true; + + ### Bars + # + # Enable top bar, as waybar + bars = [{ + command = config.programs.waybar.package + "/bin/waybar"; + position = "top"; + }]; + }; + ### Misc + # + # xwayland + xwayland = true; + # swaynag + swaynag.enable = true; + # Environment Variables + extraSessionCommands = '' + export MOZ_ENABLE_WAYLAND=1 + export SDL_VIDEODRIVER=wayland + export QT_QPA_PLATFORM=wayland + export QT_WAYLAND_DISABLE_WINDOWDECORATION="1" + ''; + # Extra + systemdIntegration = true; + wrapperFeatures.base = true; + wrapperFeatures.gtk = true; + }; + + config.programs.waybar = mkIf cfg.enable { + enable = true; + settings = [ + # Top bar + { + layer = "top"; + position = "top"; + modules-left = [ + "sway/workspaces" + "sway/mode" + "sway/window" + ]; + modules-center = [ ]; + modules-right = [ + "tray" + "pulseaudio" + "network" + "cpu" + "memory" + "temperature" + "backlight" + "battery" + "battery#bat2" + "clock" + ]; + + modules = { + "sway/mode" = { + format = "{}"; + }; + "tray" = { + icon-size = 21; + spacing = 10; + }; + "clock" = { + tooltip-format = "{:%Y-%m-%d | %H:%M}"; + format-alt = "{:%Y-%m-%d}"; + }; + "cpu" = { + format = "{usage}% "; + }; + "memory" = { + format = "{}% "; + }; + "temperature" = { + # thermal-zone = 2; + # hwmon-path" = "/sys/class/hwmon/hwmon2/temp1_input"; + critical-threshold = 80; + # format-critical = "{temperatureC}°C "; + format = "{temperatureC}°C "; + }; + "backlight" = { + # device = "acpi_video1"; + format = "{percent}% {icon}"; + states = [ 0 50 ]; + format-icons = [ "" "" ]; + }; + "battery" = { + states = { + good = 95; + warning = 30; + critical = 15; + }; + format = "{capacity}% {icon}"; + # format-good = ""; # An empty format will hide the module + # format-full = ""; + format-icons = [ "" "" "" "" "" ]; + }; + "battery#bat2" = { + bat = "BAT2"; + }; + "network" = { + # interface = wlp2s0 # (Optional) To force the use of this interface + format-wifi = "{essid} ({signalStrength}%) "; + format-ethernet = "{ifname}: {ipaddr}/{cidr} "; + format-disconnected = "Disconnected ⚠"; + interval = 7; + }; + "pulseaudio" = { + # scroll-step = 1; + format = "{volume}% {icon}"; + format-bluetooth = "{volume}% {icon}"; + format-muted = ""; + format-icons = { + headphones = ""; + handsfree = ""; + headset = ""; + phone = ""; + portable = ""; + car = ""; + default = [ "" "" ]; + }; + on-click = "pavucontrol"; + }; + }; + } + ]; + style = '' + * { + border: none; + border-radius: 0; + font-family: IBM Plex Mono,'Font Awesome 5', 'SFNS Display', Helvetica, Arial, sans-serif; + font-size: 13px; + min-height: 0; + } + + window#waybar { + background: rgba(43, 48, 59, 0.5); + border-bottom: 3px solid rgba(100, 114, 125, 0.5); + color: #ffffff; + } + + window#waybar.hidden { + opacity: 0.0; + } + /* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ + #workspaces button { + padding: 0 5px; + background: transparent; + color: #ffffff; + border-bottom: 3px solid transparent; + } + + #workspaces button.focused { + background: #64727D; + border-bottom: 3px solid #ffffff; + } + + #workspaces button.urgent { + background-color: #eb4d4b; + } + + #mode { + background: #64727D; + border-bottom: 3px solid #ffffff; + } + + #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-media, #tray, #mode, #idle_inhibitor { + padding: 0 10px; + margin: 0 5px; + } + + #clock { + background-color: #64727D; + } + + #battery { + background-color: #ffffff; + color: #000000; + } + + #battery.charging { + color: #ffffff; + background-color: #26A65B; + } + + @keyframes blink { + to { + background-color: #ffffff; + color: #000000; + } + } + + #battery.critical:not(.charging) { + background: #f53c3c; + color: #ffffff; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; + } + + #cpu { + background: #2ecc71; + color: #000000; + } + + #memory { + background: #9b59b6; + } + + #backlight { + background: #90b1b1; + } + + #network { + background: #2980b9; + } + + #network.disconnected { + background: #f53c3c; + } + + #pulseaudio { + background: #f1c40f; + color: #000000; + } + + #pulseaudio.muted { + background: #90b1b1; + color: #2a5c45; + } + + #custom-media { + background: #66cc99; + color: #2a5c45; + } + + .custom-spotify { + background: #66cc99; + } + + .custom-vlc { + background: #ffa000; + } + + #temperature { + background: #f0932b; + } + + #temperature.critical { + background: #eb4d4b; + } + + #tray { + background-color: #2980b9; + } + + #idle_inhibitor { + background-color: #2d3436; + } + + #idle_inhibitor.activated { + background-color: #ecf0f1; + color: #2d3436; + } + ''; + }; + + config.home.packages = mkIf cfg.enable (with pkgs; [ + # Needed for QT_QPA_PLATFORM + qt5.qtwayland + # For waybar + font-awesome + ]); +} diff --git a/home/nki-x1c1.nix b/home/nki-x1c1.nix index 503864b..caeab8e 100644 --- a/home/nki-x1c1.nix +++ b/home/nki-x1c1.nix @@ -1,16 +1,20 @@ -{ pkgs, config, lib, ... } : +{ pkgs, config, lib, ... }: { imports = [ - # Common configuration - ./common.nix - # Set up X11-specific common configuration - # ./X11/default.nix - # ./X11/hidpi.nix # Enable hiDPI - # We use our own firefox - # ./firefox.nix - # osu! - # ./osu.nix + # Common configuration + ./common.nix + # Set up X11-specific common configuration + # ./X11/default.nix + # ./X11/hidpi.nix # Enable hiDPI + # We use our own firefox + # ./firefox.nix + # osu! + # ./osu.nix + # Sway + ./modules/programs/my-sway + # Alacritty + ./X11/alacritty.nix ]; # Home Manager needs a bit of information about you and the @@ -20,17 +24,21 @@ # More packages home.packages = (with pkgs; [ - # CLI stuff - python - zip - # TeX - texlive.combined.scheme-full + # CLI stuff + python + zip + # TeX + texlive.combined.scheme-full - # Java & sbt - openjdk11 - sbt + # Java & sbt + openjdk11 + sbt ]); + # Enable sway + programs.my-sway.enable = true; + programs.my-sway.fontSize = 14.0; + # This value determines the Home Manager release that your # configuration is compatible with. This helps avoid breakage # when a new Home Manager release introduces backwards diff --git a/nki-x1c1/configuration.nix b/nki-x1c1/configuration.nix index df2fece..8c43e02 100644 --- a/nki-x1c1/configuration.nix +++ b/nki-x1c1/configuration.nix @@ -6,8 +6,11 @@ { imports = - [ # Include the results of the hardware scan. + [ + # Include the results of the hardware scan. ./hardware-configuration.nix + # Fonts + ../modules/personal/fonts ]; # Use the systemd-boot EFI boot loader. @@ -21,7 +24,7 @@ ''; networking.hostName = "nki-x1c1"; # Define your hostname. - networking.wireless.iwd.enable = true; # Enables wireless support via iwd. + networking.wireless.iwd.enable = true; # Enables wireless support via iwd. # Set your time zone. # time.timeZone = "Europe/Amsterdam"; @@ -48,9 +51,15 @@ # Enable the Plasma 5 Desktop Environment. - services.xserver.displayManager.sddm.enable = true; - services.xserver.desktopManager.plasma5.enable = true; - + # services.xserver.displayManager.sddm.enable = true; + # services.xserver.desktopManager.plasma5.enable = true; + + environment.loginShellInit = '' + if [ -z $DISPLAY ] && [ "$(tty)" = "/dev/tty1" ]; then + exec sway + fi + ''; + # Configure keymap in X11 # services.xserver.layout = "us";