From 39daf147ad08f9cf2699b0247a8039d818a8e424 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 22 Jun 2024 14:15:25 +0200 Subject: [PATCH] Add various system-wide wayland settings --- .../graphical/wms/hyprland/default.nix | 13 +++++++ system/roles/workstation/default.nix | 1 + system/roles/workstation/display/default.nix | 5 +++ .../workstation/display/wayland/default.nix | 8 ++++ .../workstation/display/wayland/services.nix | 29 +++++++++++++++ .../display/wayland/wms/default.nix | 5 +++ .../display/wayland/wms/hyprland/default.nix | 30 +++++++++++++++ .../display/wayland/xdg-portals.nix | 37 +++++++++++++++++++ .../workstation/display/wayland/xwayland.nix | 13 +++++++ 9 files changed, 141 insertions(+) create mode 100644 system/roles/workstation/display/default.nix create mode 100644 system/roles/workstation/display/wayland/default.nix create mode 100644 system/roles/workstation/display/wayland/services.nix create mode 100644 system/roles/workstation/display/wayland/wms/default.nix create mode 100644 system/roles/workstation/display/wayland/wms/hyprland/default.nix create mode 100644 system/roles/workstation/display/wayland/xdg-portals.nix create mode 100644 system/roles/workstation/display/wayland/xwayland.nix diff --git a/home/programs/graphical/wms/hyprland/default.nix b/home/programs/graphical/wms/hyprland/default.nix index c9026cf..3c6f834 100644 --- a/home/programs/graphical/wms/hyprland/default.nix +++ b/home/programs/graphical/wms/hyprland/default.nix @@ -8,6 +8,10 @@ hyprPkgs = (import ./packages {inherit pkgs;}); + # TODO: Switch to flake + hyprlandPkg = pkgs.hyprland; + xdgDesktopPortalHyprlandPkg = pkgs.xdg-desktop-portal-hyprland; + cfg = osConfig.myOptions.home-manager.wms.hyprland; in { imports = [ @@ -30,10 +34,19 @@ in { wayland.windowManager.hyprland = { enable = true; xwayland.enable = true; + package = hyprlandPkg; systemd = { enable = true; variables = ["--all"]; }; }; + + xdg.portal = { + enable = true; + configPackages = [hyprlandPkg]; + extraPortals = [ + xdgDesktopPortalHyprlandPkg + ]; + }; }; } diff --git a/system/roles/workstation/default.nix b/system/roles/workstation/default.nix index 1c83f82..537612d 100644 --- a/system/roles/workstation/default.nix +++ b/system/roles/workstation/default.nix @@ -4,5 +4,6 @@ ./programs ./fonts.nix ./runners.nix + ./display ]; } diff --git a/system/roles/workstation/display/default.nix b/system/roles/workstation/display/default.nix new file mode 100644 index 0000000..638bb65 --- /dev/null +++ b/system/roles/workstation/display/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./wayland + ]; +} diff --git a/system/roles/workstation/display/wayland/default.nix b/system/roles/workstation/display/wayland/default.nix new file mode 100644 index 0000000..a7be6a5 --- /dev/null +++ b/system/roles/workstation/display/wayland/default.nix @@ -0,0 +1,8 @@ +{ + imports = [ + ./wms + ./xdg-portals.nix + ./xwayland.nix + ./services.nix + ]; +} diff --git a/system/roles/workstation/display/wayland/services.nix b/system/roles/workstation/display/wayland/services.nix new file mode 100644 index 0000000..0cf06e4 --- /dev/null +++ b/system/roles/workstation/display/wayland/services.nix @@ -0,0 +1,29 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib) mkIf getExe; + + cfgEnabled = config.myOptions.home-manager.wms.isWayland; +in { + config = mkIf cfgEnabled { + systemd.services = { + # Seat management daemon + # (Takes care of mediating access to shared devices (graphics, input), without requiring + # applications like Wayland compositors being granted root privileges) + seatd = { + enable = true; + description = "Seat management daemon"; + script = "${getExe pkgs.seatd} -g wheel"; + serviceConfig = { + Type = "simple"; + Restart = "always"; + RestartSec = "1"; + }; + wantedBy = ["multi-user.target"]; + }; + }; + }; +} diff --git a/system/roles/workstation/display/wayland/wms/default.nix b/system/roles/workstation/display/wayland/wms/default.nix new file mode 100644 index 0000000..3fbd598 --- /dev/null +++ b/system/roles/workstation/display/wayland/wms/default.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./hyprland + ]; +} diff --git a/system/roles/workstation/display/wayland/wms/hyprland/default.nix b/system/roles/workstation/display/wayland/wms/hyprland/default.nix new file mode 100644 index 0000000..4c190dd --- /dev/null +++ b/system/roles/workstation/display/wayland/wms/hyprland/default.nix @@ -0,0 +1,30 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (lib) mkIf; + + cfgEnabled = config.myOptions.home-manager.wms.hyprland.enable; + + # TODO: Switch to flake + hyprlandPkg = pkgs.hyprland; + xdgDesktopPortalHyprlandPkg = pkgs.xdg-desktop-portal-hyprland; +in { + config = mkIf cfgEnabled { + services.displayManager.sessionPackages = [hyprlandPkg]; + + xdg.portal = { + enable = true; + configPackages = [hyprlandPkg]; + extraPortals = [xdgDesktopPortalHyprlandPkg]; + }; + + programs.hyprland = { + enable = true; + package = hyprlandPkg; + portalPackage = xdgDesktopPortalHyprlandPkg; + }; + }; +} diff --git a/system/roles/workstation/display/wayland/xdg-portals.nix b/system/roles/workstation/display/wayland/xdg-portals.nix new file mode 100644 index 0000000..864b220 --- /dev/null +++ b/system/roles/workstation/display/wayland/xdg-portals.nix @@ -0,0 +1,37 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib) mkIf; + + cfgEnabled = config.myOptions.home-manager.wms.isWayland; + cfgHyprlandEnabled = config.myOptions.home-manager.wms.hyprland.enable; +in { + config = mkIf cfgEnabled { + xdg.portal = { + enable = true; + + extraPortals = with pkgs; [ + xdg-desktop-portal-gtk + ]; + + # Specify which portals should be used by the individual interfaces + # see: + config.common = let + # Note: this assumes a wlroots based compositor if it's not hyprland + # which may not always actually be the case, however, I can't be bothered to handle + # everything here and I don't plan on moving WMs any time soon. + portal = if cfgHyprlandEnabled then "hyprland" else "wlr"; + in { + # Use this portal for every interface, unless a specific override is present + default = ["gtk"]; + + # Fix flameshot on hyprland / wlroots compositors + "org.freedesktop.impl.portal.Screencast" = [portal]; + "org.freedesktop.impl.portal.Screenshot" = [portal]; + }; + }; + }; +} diff --git a/system/roles/workstation/display/wayland/xwayland.nix b/system/roles/workstation/display/wayland/xwayland.nix new file mode 100644 index 0000000..c70d8d0 --- /dev/null +++ b/system/roles/workstation/display/wayland/xwayland.nix @@ -0,0 +1,13 @@ +{ + config, + lib, + ... +}: let + inherit (lib) mkIf; + + cfgEnabled = config.myOptions.home-manager.wms.isWayland; +in { + config = mkIf cfgEnabled { + programs.xwayland.enable = true; + }; +}