From d8c04a227c15b49d66e80a283e32d210263832b7 Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 1 Nov 2022 16:28:52 +0100 Subject: [PATCH] Use polybar override and added tailscale --- home/modules/desktop/i3.nix | 12 +- home/modules/desktop/polybar.nix | 205 ++++++++++++++++++++++++++++++- system/modules/default.nix | 1 + system/modules/tailscale.nix | 16 +++ system/profiles/common.nix | 3 + 5 files changed, 232 insertions(+), 5 deletions(-) create mode 100644 system/modules/tailscale.nix diff --git a/home/modules/desktop/i3.nix b/home/modules/desktop/i3.nix index c31d428..218bebd 100644 --- a/home/modules/desktop/i3.nix +++ b/home/modules/desktop/i3.nix @@ -55,6 +55,8 @@ in { focus.followMouse = false; + bars = [ ]; + keybindings = { "${mod}+q" = "kill"; @@ -96,6 +98,10 @@ in { # focus the parent container "${mod}+a" = "focus parent"; + # Reload config + restart i3 + "${mod}+Shift+c" = "reload"; + "${mod}+Shift+r" = "restart"; + # - Workspaces ------------------------- "${mod}+1" = "workspace 1"; "${mod}+2" = "workspace 2"; @@ -106,7 +112,7 @@ in { "${mod}+7" = "workspace 7"; "${mod}+8" = "workspace 8"; "${mod}+9" = "workspace 9"; - "${mod}+0" = "workspace 0"; + "${mod}+0" = "workspace 10"; "${mod}+Shift+1" = "move container to workspace 1; workspace 1"; "${mod}+Shift+2" = "move container to workspace 2; workspace 2"; @@ -117,7 +123,7 @@ in { "${mod}+Shift+7" = "move container to workspace 7; workspace 7"; "${mod}+Shift+8" = "move container to workspace 8; workspace 8"; "${mod}+Shift+9" = "move container to workspace 9; workspace 9"; - "${mod}+Shift+0" = "move container to workspace 0; workspace 0"; + "${mod}+Shift+0" = "move container to workspace 10; workspace 10"; } // (if cfg.terminal.enable then { @@ -127,7 +133,7 @@ in { "${mod}+space" = "exec ${cfg.launcher.command}"; } else {}) // (if cfg.browser.enable then { - "Control+Alt+3" = "exec ${cfg.browser.command}"; + "${mod}+Control+3" = "exec ${cfg.browser.command}"; } else {}); }; }; diff --git a/home/modules/desktop/polybar.nix b/home/modules/desktop/polybar.nix index 5a9b7b3..81ff7f0 100644 --- a/home/modules/desktop/polybar.nix +++ b/home/modules/desktop/polybar.nix @@ -10,12 +10,213 @@ in { config = lib.mkIf cfg.enable { - # - Configuration ---------------------------- services.polybar = { enable = true; - + + package = pkgs.polybar.override { + i3Support = true; + pulseSupport = true; + }; + + config = { + + # - Colors ------------------------------- + + "colors" = { + "background" = "#222"; + "background-alt" = "#444"; + "foreground" = "#dfdfdf"; + "foreground-alt" = "#555"; + "primary" = "#ffb52a"; + "secondary" = "#e60053"; + "alert" = "#bd2c40"; + }; + + # - Mainbar ------------------------------ + + "bar/mainbar-i3" = { + "monitor" = "\${env:MONITOR}"; + "monitor-strict" = "false"; + "bottom" = "false"; + "fixed-center" = "true"; + "width" = "100%"; + "height" = "30"; + + "background" = "\${colors.background}"; + "foreground" = "\${colors.foreground}"; + + "radius" = "0.0"; + "line-size" = "2"; + "line-color" = "#000000"; + "border-color" = "#000000"; + + "padding-left" = "1"; + "padding-right" = "1"; + + "module-margin-left" = "0"; + "module-margin-right" = "0"; + + "font-0" = "\"Iosevka:style=Regular:size=15;2\""; + "font-1" = "\"Iosevka:size=16;3\""; + "font-2" = "\"Iosevka:style=Regular:pixelsize=10;1\""; + "font-3" = "\"Iosevka:style=Solid:pixelsize=10;1\""; + "font-4" = "\"Iosevka:pixelsize=10;1\""; + + "modules-left" = "i3"; + "modules-center" = "date"; + "modules-right" = "wifi pulseaudio battery"; + + "separator" = "\" : \""; + + "tray-position" = "left"; + "tray-detached" = "false"; + "tray-maxsize" = "20"; + "tray-background" = "\${colors.background}"; + "tray-offset-x" = "0"; + "tray-offset-y" = "0"; + "tray-padding" = "4"; + "tray-scale" = "1.0"; + + "enable-ipc" = "true"; + + "click-left" = ""; + "click-middle" = ""; + "click-right" = ""; + "scroll-up" = "i3wm-wsnext"; + "scroll-down" = "i3wm-wsprev"; + "double-click-left" = ""; + "double-click-middle" = ""; + "double-click-right" = ""; + + "cursor-click" = ""; + "cursor-scroll" = ""; + }; + + # - Module: i3 --------------------------- + + "module/i3" = { + "type" = "internal/i3"; + "format" = " "; + "index-sort" = "true"; + "wrapping-scroll" = "false"; + + "label-mode-padding" = "2"; + "label-mode-foreground" = "#000"; + "label-mode-background" = "\${colors.primary}"; + + "label-focused" = "%index%"; + "label-focused-background" = "\${colors.background-alt}"; + "label-focused-underline" = "\${colors.secondary}"; + "label-focused-padding" = "2"; + + "label-unfocused" = "%index%"; + "label-unfocused-padding" = "2"; + + "label-visible" = "%index%"; + "label-visible-background" = "\${self.label-focused-background}"; + "label-visible-underline" = "\${colors.primary}"; + "label-visible-padding" = "\${self.label-focused-padding}"; + + "label-urgent" = "%index%"; + "label-urgent-background" = "\${colors.alert}"; + "label-urgent-padding" = "2"; + }; + + # - Module: date ------------------------- + + "module/date" = { + "type" = "internal/date"; + "interval" = "1"; + + "date" = "%A, %d %B %Y"; + "time" = "%H:%M:%S"; + + "time-alt" = "%H:%M:%S %Z (%z)"; + "date-alt" = "%Y-%m-%d"; + + "format-prefix" = ""; + "format-prefix-foreground" = "\${colors.foreground-alt}"; + "format-underline" = ""; + + "label" = "%date% · %time%"; + }; + + # - Module: pulseaudio ------------------- + + "module/pulseaudio" = { + "type" = "internal/pulseaudio"; + + "format-volume" = " "; + "label-volume" = "VOL %percentage%%"; + "label-volume-foreground" = "\${colors.foreground-alt}"; + + "label-muted" = "muted"; + "label-muted-foreground" = "#666"; + + "bar-volume-width" = "10"; + "bar-volume-foreground-0" = "#55aa55"; + "bar-volume-foreground-1" = "#55aa55"; + "bar-volume-foreground-2" = "#55aa55"; + "bar-volume-foreground-3" = "#55aa55"; + "bar-volume-foreground-4" = "#55aa55"; + "bar-volume-foreground-5" = "#f5a70a"; + "bar-volume-foreground-6" = "#ff5555"; + "bar-volume-gradient" = "false"; + "bar-volume-indicator" = "|"; + "bar-volume-indicator-font" = "0"; + "bar-volume-fill" = "-"; + "bar-volume-fill-font" = "0"; + "bar-volume-empty" = "-"; + "bar-volume-empty-font" = "0"; + "bar-volume-empty-foreground" = "\${colors.foreground-alt}"; + }; + + # - Module: battery ---------------------- + + "module/battery" = { + "type" = "internal/battery"; + "battery" = "BAT0"; + "adapter" = "AC"; + "full-at" = "98"; + + "format-charging-prefix" = "\"▴\""; + "format-charging" = ""; + "format-charging-foreground" = "#55aa55"; + "format-charging-underline" = ""; + + "format-discharging-prefix" = "\"▾\""; + "format-discharging" = ""; + "format-discharging-foreground" = "#f5a70a"; + "format-discharging-underline" = ""; + + "format-full" = "FULL BATTERY"; + "format-full-foreground" = "#55aa55"; + "format-full-underline" = "\${self.format-charging-underline}"; + + "ramp-capacity-0" = ""; + "ramp-capacity-1" = ""; + "ramp-capacity-2" = ""; + "ramp-capacity-foreground" = "\${colors.foreground-alt}"; + }; + }; + + script = '' + #!/usr/bin/env bash + + # Terminate already running bar instances + killall -q polybar + + # Wait until the processes have been shut down + while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done + + for m in $(polybar --list-monitors | cut -d":" -f1); do + WIRELESS=$(ls /sys/class/net/ | grep ^wl | awk 'NR==1{print $1}') MONITOR=$m polybar --reload mainbar-i3 & + done + + echo "Bars launched..." + ''; }; }; } diff --git a/system/modules/default.nix b/system/modules/default.nix index 3e96128..3ea9db1 100644 --- a/system/modules/default.nix +++ b/system/modules/default.nix @@ -2,6 +2,7 @@ { imports = [ + ./tailscale.nix ./user.nix ]; } diff --git a/system/modules/tailscale.nix b/system/modules/tailscale.nix new file mode 100644 index 0000000..edac49f --- /dev/null +++ b/system/modules/tailscale.nix @@ -0,0 +1,16 @@ +{ config, lib, pkgs, self, ... }: + +let + cfg = config.samfelag.modules.tailscale; +in +{ + options.samfelag.modules.tailscale = { + enable = lib.mkEnableOption "tailscale"; + }; + + config = lib.mkIf cfg.enable { + services.tailscale = { + enable = true; + }; + }; +} diff --git a/system/profiles/common.nix b/system/profiles/common.nix index fd0fac8..888f468 100644 --- a/system/profiles/common.nix +++ b/system/profiles/common.nix @@ -34,12 +34,15 @@ curl git pciutils + psmisc vim ]; # - Other -------------------------------------- networking.networkmanager.enable = true; + networking.firewall.checkReversePath = "loose"; # See https://github.com/tailscale/tailscale/issues/4432 + samfelag.modules.tailscale.enable = true; system.stateVersion = "22.05";