From 8ffe5ce23fa1548304a3fa25f2bd0e89837f5a0b Mon Sep 17 00:00:00 2001 From: Minijackson Date: Sun, 18 Apr 2021 16:58:23 +0200 Subject: revamp with nix flakes + desktop config --- usecases/desktop/default.nix | 11 ++ usecases/desktop/graphical.nix | 73 ++++++++ usecases/desktop/graphical/alacritty.nix | 49 ++++++ usecases/desktop/graphical/mpv.nix | 16 ++ usecases/desktop/graphical/rofi.nix | 102 +++++++++++ usecases/desktop/graphical/sway.nix | 263 ++++++++++++++++++++++++++++ usecases/desktop/graphical/waybar.nix | 288 +++++++++++++++++++++++++++++++ usecases/desktop/graphical/zathura.nix | 55 ++++++ usecases/desktop/pipewire.nix | 44 +++++ 9 files changed, 901 insertions(+) create mode 100644 usecases/desktop/default.nix create mode 100644 usecases/desktop/graphical.nix create mode 100644 usecases/desktop/graphical/alacritty.nix create mode 100644 usecases/desktop/graphical/mpv.nix create mode 100644 usecases/desktop/graphical/rofi.nix create mode 100644 usecases/desktop/graphical/sway.nix create mode 100644 usecases/desktop/graphical/waybar.nix create mode 100644 usecases/desktop/graphical/zathura.nix create mode 100644 usecases/desktop/pipewire.nix (limited to 'usecases/desktop') diff --git a/usecases/desktop/default.nix b/usecases/desktop/default.nix new file mode 100644 index 0000000..8b6687a --- /dev/null +++ b/usecases/desktop/default.nix @@ -0,0 +1,11 @@ +# A reasonable set of defaults for desktop + +inputs: + +{ ... }: + +{ + imports = [ + (import ./graphical.nix inputs) + ]; +} diff --git a/usecases/desktop/graphical.nix b/usecases/desktop/graphical.nix new file mode 100644 index 0000000..29b2db6 --- /dev/null +++ b/usecases/desktop/graphical.nix @@ -0,0 +1,73 @@ +inputs: + +{ pkgs, ... }: + +{ + imports = [ + (import ./pipewire.nix inputs) + + (import ./graphical/alacritty.nix inputs) + (import ./graphical/mpv.nix inputs) + (import ./graphical/rofi.nix inputs) + (import ./graphical/sway.nix inputs) + (import ./graphical/waybar.nix inputs) + (import ./graphical/zathura.nix inputs) + ]; + + fonts = { + enableDefaultFonts = true; + fonts = with pkgs; [ + fira + fira-mono + dejavu_fonts + freefont_ttf + liberation_ttf + noto-fonts-cjk + #fira-mono-italic + lmodern + # Symbols + unifont + siji + font-awesome_5 + #joypixels + # Collections + league-of-moveable-type + ]; + + fontconfig = { + #ultimate.enable = true; + + defaultFonts = { + serif = [ "DejaVu Serif" ]; + sansSerif = [ "DejaVu Sans" ]; + monospace = [ "Fira Mono" ]; + #emoji = [ "JoyPixels" ]; + }; + }; + }; + + hardware.opengl.enable = true; + programs.dconf.enable = true; + + xdg = { + sounds.enable = true; + portal = { + enable = true; + extraPortals = with pkgs; [ + xdg-desktop-portal-gtk + ]; + gtkUsePortal = true; + }; + }; + + # For KDEConnect + networking.firewall.allowedTCPPortRanges = [{ from = 1714; to = 1764; }]; + networking.firewall.allowedUDPPortRanges = [{ from = 1714; to = 1764; }]; + + home-manager.users.minijackson = { + services.kdeconnect = { + enable = true; + indicator = true; + }; + }; +} diff --git a/usecases/desktop/graphical/alacritty.nix b/usecases/desktop/graphical/alacritty.nix new file mode 100644 index 0000000..3e5795b --- /dev/null +++ b/usecases/desktop/graphical/alacritty.nix @@ -0,0 +1,49 @@ +inputs: + +{ config, ... }: + +{ + home-manager.users.minijackson.programs.alacritty = { + enable = true; + settings = { + window = { + padding.x = 2; + padding.y = 2; + }; + + font = { + size = 8.0; + italic.style = "Regular Italic"; + }; + + colors = with config.theme.colors; { + primary.background = softBackground; + primary.foreground = foreground; + + normal = { + black = background; + # TODO: bright white is same + #white = "0xa89984"; + white = foreground; + red = neutralRed; + green = neutralGreen; + yellow = neutralYellow; + blue = neutralBlue; + magenta = neutralMagenta; + cyan = neutralCyan; + }; + + bright = { + black = dimForeground; + white = foreground; + red = brightRed; + green = brightGreen; + yellow = brightYellow; + blue = brightBlue; + magenta = brightMagenta; + cyan = brightCyan; + }; + }; + }; + }; +} diff --git a/usecases/desktop/graphical/mpv.nix b/usecases/desktop/graphical/mpv.nix new file mode 100644 index 0000000..381b893 --- /dev/null +++ b/usecases/desktop/graphical/mpv.nix @@ -0,0 +1,16 @@ +inputs: + +{ pkgs, ... }: + +{ + home-manager.users.minijackson.programs.mpv = { + enable = true; + config = { + hwdec = "auto"; + profile = "gpu-hq"; + }; + # TODO: for 21.05 + #defaultProfiles = [ "gpu-hq" ]; + scripts = with pkgs.mpvScripts; [ mpris sponsorblock ]; + }; +} diff --git a/usecases/desktop/graphical/rofi.nix b/usecases/desktop/graphical/rofi.nix new file mode 100644 index 0000000..0013f5c --- /dev/null +++ b/usecases/desktop/graphical/rofi.nix @@ -0,0 +1,102 @@ +inputs: + +{ config, ... }: + +{ + home-manager.users.minijackson.programs.rofi = { + enable = true; + + # TODO: there is a better way + theme = with config.theme.colors; builtins.toFile "theme.rasi" '' + * { + dominant: ${dominant}; + + foreground: ${foreground}; + dim-foreground: ${dimForeground}; + + text-color: @foreground; + border-color: @dim-foreground; + + background-color: ${background}; + light-background: ${lightBackground}; + } + + #window { + padding: 8px; + + border: 1px solid; + background-color: @background; + } + + #mainbox { + border: 0; + padding: 0; + } + + #inputbar { + spacing: 0; + padding: 5px; + border: 0 0 1px 0; + margin: 0 0 8px 0; + children: [ prompt, textbox-prompt-sep, entry ]; + } + + #prompt { + background-color: @background; + text-color: @dim-foreground; + } + + textbox-prompt-sep { + expand: false; + str: ":"; + text-color: @dim-foreground; + margin: 0 8px 0 0; + } + + #message { + spacing: 0; + padding: 5px; + border: 0 0 1px 0; + margin: 0 0 8px 0; + } + + #listview { + spacing: 0; + } + + #element { + border: 0; + padding: 5px; + + background-color: @background; + } + + #element.selected.normal { + background-color: @dominant; + } + + #element.urgent { + background-color: ${fadedRed}; + } + + #element.selected.urgent { + background-color: ${neutralRed}; + } + + #element.active { + background-color: ${dimForeground}; + text-color: ${background}; + } + + #element.selected.active { + background-color: ${foreground}; + text-color: ${background}; + } + + #scrollbar { + width: 4px; + handle-width: 8px; + } + ''; + }; +} diff --git a/usecases/desktop/graphical/sway.nix b/usecases/desktop/graphical/sway.nix new file mode 100644 index 0000000..6c5b2ed --- /dev/null +++ b/usecases/desktop/graphical/sway.nix @@ -0,0 +1,263 @@ +inputs: + +{ config, lib, pkgs, system, ... }: +let + globalConfig = config; +in +{ + home-manager.users.minijackson = { config, ... }: { + wayland.windowManager.sway = { + enable = true; + + extraSessionCommands = '' + # https://github.com/emersion/xdg-desktop-portal-wlr/issues/20 + export XDG_CURRENT_DESKTOP=sway + # https://github.com/emersion/xdg-desktop-portal-wlr/pull/11 + export XDG_SESSION_TYPE=wayland + + export SDL_VIDEODRIVER=wayland + + export QT_QPA_PLATFORM=wayland + export QT_WAYLAND_DISABLE_WINDOWDECORATION=1 + ''; + + # Implemented below in startup, due to global import-environment failing + # when not specifying variables. + # + # TODO: make PR + #systemdIntegration = true; + wrapperFeatures.gtk = true; + + config = { + # Using waybar + bars = [ ]; + + bindkeysToCode = true; + + colors = with globalConfig.theme.colors; { + focused = { + border = lightBackground; + background = lightBackground; + text = foreground; + indicator = dominant; + childBorder = dominant; + }; + + focusedInactive = { + border = background; + background = background; + text = dimForeground; + indicator = dominant; + childBorder = background; + }; + + unfocused = { + border = background; + background = background; + text = dimForeground; + indicator = dominant; + childBorder = background; + }; + + urgent = { + border = brightRed; + background = brightRed; + text = foreground; + indicator = brightRed; + childBorder = brightRed; + }; + + placeholder = { + border = background0; + background = background0; + text = foreground; + indicator = background0; + childBorder = background0; + }; + }; + + floating.criteria = [ + { title = "Steam - News"; } + ]; + + input = { + "1:1:AT_Translated_Set_2_keyboard" = { + xkb_layout = "fr"; + xkb_variant = "oss"; + xkb_options = "compose:caps"; + xkb_numlock = "enabled"; + }; + + "1452:514:Alps_Electric_M2452" = { + xkb_layout = "fr"; + xkb_variant = "oss"; + xkb_options = "compose:caps,lv3:rwin_switch"; + xkb_numlock = "enabled"; + }; + + "7764:8240:TypeMatrix.com_USB_Keyboard" = { + xkb_layout = "dvorak"; + xkb_options = "eurosign:e,compose:caps"; + }; + + + "1133:49948:Logitech_USB_Keyboard" = { + xkb_layout = "fr"; + xkb_variant = "oss"; + xkb_options = "eurosign:e,compose:caps"; + xkb_numlock = "enabled"; + }; + + "1102:4639:DELL0817:00_044E:121F_Mouse" = { + scroll_method = "on_button_down"; + scroll_button = "button2"; + }; + }; + + keybindings = + let + modifier = config.wayland.windowManager.sway.config.modifier; + in + lib.mkOptionDefault { + "${modifier}+ampersand" = "workspace 1"; + "${modifier}+eacute" = "workspace 2"; + "${modifier}+quotedbl" = "workspace 3"; + "${modifier}+apostrophe" = "workspace 4"; + "${modifier}+parenleft" = "workspace 5"; + "${modifier}+minus" = "workspace 6"; + "${modifier}+egrave" = "workspace 7"; + "${modifier}+underscore" = "workspace 8"; + "${modifier}+ccedilla" = "workspace 9"; + "${modifier}+agrave" = "workspace 10"; + + "${modifier}+Shift+ampersand" = "move container to workspace 1"; + "${modifier}+Shift+eacute" = "move container to workspace 2"; + "${modifier}+Shift+quotedbl" = "move container to workspace 3"; + "${modifier}+Shift+apostrophe" = "move container to workspace 4"; + "${modifier}+Shift+parenleft" = "move container to workspace 5"; + "${modifier}+Shift+minus" = "move container to workspace 6"; + "${modifier}+Shift+egrave" = "move container to workspace 7"; + "${modifier}+Shift+underscore" = "move container to workspace 8"; + "${modifier}+Shift+ccedilla" = "move container to workspace 9"; + "${modifier}+Shift+agrave" = "move container to workspace 10"; + + "${modifier}+m" = "exec ${pkgs.swaylock}/bin/swaylock"; + }; + + menu = '' + ${pkgs.rofi}/bin/rofi -show drun -terminal ${pkgs.alacritty}/bin/alacritty + ''; + + modifier = "Mod4"; + + output."*".bg = + "${../../../res/wallpapers/wallpaper-1920x1080-kernel-card-black.png} fill"; + + startup = [ + { command = "${pkgs.mako}/bin/mako"; always = true; } + { + command = "systemctl --user import-environment ${ + builtins.toString (lib.unique config.xsession.importedVariables) + }; systemctl --user start sway-session.target"; + } + ]; + + terminal = "${pkgs.alacritty}/bin/alacritty"; + + window = { + border = 2; + hideEdgeBorders = "smart"; + titlebar = true; + }; + }; + }; + + # TODO: 21.05 + /* + services.wlsunset = { + enable = true; + latitude = "48.864716"; + longitude = "2.349014"; + # Reduce blue light anyways + temperature = { + day = 4000; + night = 2500; + }; + systemdTarget = "sway-session.target"; + }; + */ + + # TODO: upstream a PR to beautify this + xdg.configFile."swaylock/config".text = with globalConfig.theme.colors; '' + ignore-empty-password + image=${../../../res/wallpapers/wallpaper-1920x1080-install-gentoo.png} + + font=monospace + + inside-color=${lib.removePrefix "#" dominant}dd + inside-clear-color=${lib.removePrefix "#" neutralOrange}dd + inside-ver-color=${lib.removePrefix "#" neutralOrange}dd + inside-wrong-color=${lib.removePrefix "#" neutralRed}dd + + key-hl-color=${lib.removePrefix "#" brightGreen}ee + bs-hl-color=${lib.removePrefix "#" neutralRed}ee + + line-color=${lib.removePrefix "#" background}ee + line-clear-color=${lib.removePrefix "#" background}ee + line-ver-color=${lib.removePrefix "#" background}ee + line-wrong-color=${lib.removePrefix "#" background}ee + + ring-color=${lib.removePrefix "#" dominant}ee + ring-clear-color=${lib.removePrefix "#" brightOrange}ee + ring-ver-color=${lib.removePrefix "#" brightOrange}ee + ring-wrong-color=${lib.removePrefix "#" brightRed}ee + + separator-color=${lib.removePrefix "#" background}ee + + text-color=${lib.removePrefix "#" background}ff + text-clear-color=${lib.removePrefix "#" background}ff + text-ver-color=${lib.removePrefix "#" background}ff + text-wrong-color=${lib.removePrefix "#" background}ff + + indicator-radius=75 + indicator-thickness=10 + ''; + + xsession.importedVariables = [ + "DBUS_SESSION_BUS_ADDRESS" + "DISPLAY" + "SSH_AUTH_SOCK" + "XAUTHORITY" + "XDG_DATA_DIRS" + "XDG_RUNTIME_DIR" + "XDG_SESSION_ID" + + "WAYLAND_DISPLAY" + "SWAYSOCK" + "I3SOCK" + + "XDG_CURRENT_DESKTOP" + "XDG_SESSION_TYPE" + ]; + + systemd.user.targets.sway-session = { + Unit = { + Description = "sway compositor session"; + Documentation = [ "man:systemd.special(7)" ]; + BindsTo = [ "graphical-session.target" ]; + Wants = [ "graphical-session-pre.target" ]; + After = [ "graphical-session-pre.target" ]; + }; + }; + }; + + environment.systemPackages = with pkgs; [ qt5.qtwayland ]; + + # TODO: in 21.05 + #programs.xwayland.enable = true; + security.pam.services.swaylock = { }; + + xdg.portal.extraPortals = with pkgs; [ + unstable.xdg-desktop-portal-wlr + ]; +} diff --git a/usecases/desktop/graphical/waybar.nix b/usecases/desktop/graphical/waybar.nix new file mode 100644 index 0000000..dca43a2 --- /dev/null +++ b/usecases/desktop/graphical/waybar.nix @@ -0,0 +1,288 @@ +inputs: + +{ config, lib, pkgs, ... }: + +{ + home-manager.users.minijackson = { + programs.waybar = { + enable = true; + + settings = [{ + layer = "top"; + position = "bottom"; + height = 25; + + modules-left = [ "sway/workspaces" "sway/mode" ]; + modules-center = [ "mpd" ]; + modules-right = [ + "idle_inhibitor" + "pulseaudio" + "network#eth" + "network#wlan" + "cpu" + "memory" + "temperature" + "backlight" + "battery" + "clock" + "tray" + ]; + + modules = { + mpd = { + format = "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) "; + format-stopped = "{consumeIcon}{randomIcon}{repeatIcon}{singleIcon}Stopped "; + format-disconnected = "Disconnected "; + + on-click-middle = "${pkgs.alacritty}/bin/alacritty --command ncmpcpp"; + + consume-icons = { + on = " "; + }; + + random-icons = { + on = " "; + }; + + repeat-icons = { + on = " "; + }; + + single-icons = { + on = "1 "; + }; + + state-icons = { + playing = ""; + paused = ""; + }; + }; + + idle_inhibitor = { + format = "{icon}"; + format-icons = { + activated = ""; + deactivated = ""; + }; + }; + + clock = { + tooltip-format = "{:%Y-%m-%d | %H:%M}"; + format-alt = "{:%Y-%m-%d}"; + }; + + cpu = { format = "{usage}% "; }; + + memory = { format = "{}% "; }; + + battery = { + states = { good = 90; }; + format = "{capacity}% {icon}"; + format-icons = [ + "" + "" + "" + "" + "" + ]; + }; + + "network#eth" = { + interface = "enp*"; + format-ethernet = "{ipaddr}/{cidr} "; + format-disconnected = "Disconnected "; + }; + + "network#wlan" = { + interface = "wlp*"; + format-wifi = "{essid} ({signalStrength}%) "; + format-disconnected = "Disconnected "; + tooltip = true; + tooltip-format-wifi = "{ipaddr}/{cidr}"; + }; + + temperature = { + hwmon-path = "/sys/class/hwmon/hwmon0/temp1_input"; + format = "{temperatureC} °C "; + }; + + backlight = { + format = "{percent}% {icon}"; + format-icons = [ "" "" ]; + }; + + pulseaudio = { + format = "{volume}% {icon}"; + format-bluetooth = "{volume}% {icon}"; + format-muted = ""; + format-icons = { + headphones = ""; + handsfree = ""; + headset = ""; + phone = ""; + portable = ""; + car = ""; + default = [ "" "" ]; + }; + on-click = "pavucontrol"; + }; + }; + }]; + + style = with config.theme.colors; '' + * { + border: none; + border-radius: 0; + font-family: mono; + font-size: 11px; + min-height: 0; + } + + window#waybar { + background: ${background}; + border-bottom: 3px solid ${lightBackground}; + color: ${foreground}; + } + + /* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */ + #workspaces button { + padding: 0 5px; + background: transparent; + color: ${foreground}; + border-bottom: 3px solid transparent; + } + + #workspaces button.focused { + background: ${dominant}; + border-bottom: 3px solid ${foreground}; + } + + #mode { + background: ${lightBackground}; + border-bottom: 3px solid ${foreground}; + } + + #clock, #battery, #cpu, #memory, #temperature, #backlight, #network, #pulseaudio, #custom-mpd, #mpd, #tray, #mode, #idle_inhibitor { + padding: 0 10px; + margin: 0 5px; + } + + #clock { + background-color: ${neutralMagenta}; + color: ${background}; + } + + #battery { + background-color: ${neutralYellow}; + color: ${background}; + } + + /* + #battery.charging { + color: ${foreground}; + background-color: #26A65B; + } + */ + + @keyframes blink { + to { + background-color: ${foreground}; + color: ${background}; + } + } + + #battery.critical:not(.charging) { + background: ${fadedRed}; + color: ${foreground}; + animation-name: blink; + animation-duration: 0.5s; + animation-timing-function: linear; + animation-iteration-count: infinite; + animation-direction: alternate; + } + + #cpu { + background: ${neutralOrange}; + color: ${background}; + } + + #memory { + background: ${brightBlue}; + color: ${background}; + } + + #backlight { + background: ${background6}; + color: ${background}; + } + + #network { + background: ${neutralGreen}; + color: ${background}; + } + + #network.disconnected { + background: ${lightBackground}; + color: ${foreground}; + } + + #pulseaudio { + background: ${neutralCyan}; + color: ${background}; + } + + #pulseaudio.muted { + background: ${foreground}; + } + + #temperature { + background: ${brightCyan}; + color: ${background}; + } + + #temperature.critical { + background: ${fadedRed}; + color: ${foreground}; + } + + #tray { + background-color: #2980b9; + } + + #idle_inhibitor { + background-color: ${lightBackground}; + } + + #custom-mpd { + background-color: ${dominant}; + } + + #mpd { + background: ${dominant}; + } + + #mpd.disconnected { + background: ${lightBackground}; + color: ${foreground}; + } + + #mpd.stopped { + background: ${foreground}; + color: ${background}; + } + + #mpd.paused { + background: ${dimDominant}; + } + ''; + + systemd.enable = true; + }; + + # Fix https://github.com/nix-community/home-manager/pull/1628 + systemd.user.services.waybar.Unit = { + Requisite = lib.mkForce []; + After = lib.mkForce []; + }; + }; +} diff --git a/usecases/desktop/graphical/zathura.nix b/usecases/desktop/graphical/zathura.nix new file mode 100644 index 0000000..d1832d8 --- /dev/null +++ b/usecases/desktop/graphical/zathura.nix @@ -0,0 +1,55 @@ +inputs: + +{ config, ... }: + +{ + home-manager.users.minijackson.programs.zathura = { + enable = true; + + options = with config.theme.colors; { + guioptions = ""; + adjust-open = "width"; + + smooth-scroll = true; + scroll-step = 100; + #scroll-full-overlap = 0.05; + + selection-clipboard = "clipboard"; + + default-bg = softBackground; + default-fg = foreground; + + notification-error-bg = neutralRed; + notification-error-fg = foreground; + + notification-warning-bg = background; + notification-warning-fg = brightRed; + + highlight-color = fadedYellow; + highlight-active-color = brightYellow; + + inputbar-bg = background; + inputbar-fg = dominant; + + completion-bg = background; + completion-fg = neutralBlue; + + completion-highlight-bg = dominant; + completion-highlight-fg = background; + + notification-bg = dominant; + notification-fg = background; + + index-bg = background; + index-fg = foreground; + + index-active-bg = dominant; + index-active-fg = background; + + recolor-lightcolor = background; + recolor-darkcolor = foreground; + recolor-keephue = true; + recolor = true; + }; + }; +} diff --git a/usecases/desktop/pipewire.nix b/usecases/desktop/pipewire.nix new file mode 100644 index 0000000..e742ba9 --- /dev/null +++ b/usecases/desktop/pipewire.nix @@ -0,0 +1,44 @@ +inputs: + +{ pkgs, ... }: + +{ + imports = [ + (inputs.nixpkgs-unstable.outPath + "/nixos/modules/services/desktops/pipewire/pipewire.nix") + (inputs.nixpkgs-unstable.outPath + "/nixos/modules/services/desktops/pipewire/pipewire-media-session.nix") + ]; + + disabledModules = [ "services/desktops/pipewire.nix" ]; + + services.pipewire = { + enable = true; + package = pkgs.unstable.pipewire; + + alsa.enable = true; + jack.enable = true; + pulse.enable = true; + + config = { + pipewire-pulse = { + "context.modules" = [ + { name = "libpipewire-module-rtkit"; flags = [ "ifexists" "nofail" ]; } + { name = "libpipewire-module-protocol-native"; } + { name = "libpipewire-module-client-node"; } + { name = "libpipewire-module-adapter"; } + { name = "libpipewire-module-metadata"; } + { + name = "libpipewire-module-protocol-pulse"; + args = { + # TODO: set it in MPD? + "server.address" = [ "unix:native" "tcp:127.0.0.1:4713" ]; + }; + } + ]; + }; + }; + + media-session.package = pkgs.unstable.pipewire.mediaSession; + }; + + security.rtkit.enable = true; +} -- cgit v1.2.3