From c7bd5289d67278ac6b82614deaef94940f89de96 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Mon, 15 May 2023 13:45:09 +0200 Subject: [PATCH] nixos/programs: factor out wayland-session common options --- nixos/modules/module-list.nix | 5 +- nixos/modules/programs/{ => wayland}/sway.nix | 62 +++++++++---------- .../modules/programs/{ => wayland}/waybar.nix | 0 .../programs/wayland/wayland-session.nix | 26 ++++++++ 4 files changed, 57 insertions(+), 36 deletions(-) rename nixos/modules/programs/{ => wayland}/sway.nix (71%) rename nixos/modules/programs/{ => wayland}/waybar.nix (100%) create mode 100644 nixos/modules/programs/wayland/wayland-session.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ff06a72ff9dd..2a34c01b999a 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -241,7 +241,6 @@ ./programs/starship.nix ./programs/steam.nix ./programs/streamdeck-ui.nix - ./programs/sway.nix ./programs/sysdig.nix ./programs/system-config-printer.nix ./programs/systemtap.nix @@ -256,7 +255,8 @@ ./programs/usbtop.nix ./programs/vim.nix ./programs/wavemon.nix - ./programs/waybar.nix + ./programs/wayland/sway.nix + ./programs/wayland/waybar.nix ./programs/weylus.nix ./programs/wireshark.nix ./programs/xastir.nix @@ -1308,7 +1308,6 @@ ./services/x11/window-managers/default.nix ./services/x11/window-managers/fluxbox.nix ./services/x11/window-managers/icewm.nix - ./services/x11/window-managers/bspwm.nix ./services/x11/window-managers/katriawm.nix ./services/x11/window-managers/metacity.nix ./services/x11/window-managers/nimdow.nix diff --git a/nixos/modules/programs/sway.nix b/nixos/modules/programs/wayland/sway.nix similarity index 71% rename from nixos/modules/programs/sway.nix rename to nixos/modules/programs/wayland/sway.nix index 3b2e69bd37c3..897166058c52 100644 --- a/nixos/modules/programs/sway.nix +++ b/nixos/modules/programs/wayland/sway.nix @@ -123,41 +123,37 @@ in { }; - config = mkIf cfg.enable { - assertions = [ + config = mkIf cfg.enable + (mkMerge [ { - assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; - message = '' - The extraSessionCommands for Sway will not be run if - wrapperFeatures.base is disabled. - ''; + assertions = [ + { + assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; + message = '' + The extraSessionCommands for Sway will not be run if + wrapperFeatures.base is disabled. + ''; + } + ]; + environment = { + systemPackages = optional (cfg.package != null) cfg.package ++ cfg.extraPackages; + # Needed for the default wallpaper: + pathsToLink = optionals (cfg.package != null) [ "/share/backgrounds/sway" ]; + etc = { + "sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" '' + # Import the most important environment variables into the D-Bus and systemd + # user environments (e.g. required for screen sharing and Pinentry prompts): + exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP + ''; + } // optionalAttrs (cfg.package != null) { + "sway/config".source = mkOptionDefault "${cfg.package}/etc/sway/config"; + }; + }; + # To make a Sway session available if a display manager like SDDM is enabled: + services.xserver.displayManager.sessionPackages = optionals (cfg.package != null) [ cfg.package ]; } - ]; - environment = { - systemPackages = optional (cfg.package != null) cfg.package ++ cfg.extraPackages; - # Needed for the default wallpaper: - pathsToLink = optionals (cfg.package != null) [ "/share/backgrounds/sway" ]; - etc = { - "sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" '' - # Import the most important environment variables into the D-Bus and systemd - # user environments (e.g. required for screen sharing and Pinentry prompts): - exec dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP - ''; - } // optionalAttrs (cfg.package != null) { - "sway/config".source = mkOptionDefault "${cfg.package}/etc/sway/config"; - }; - }; - security.polkit.enable = true; - security.pam.services.swaylock = {}; - hardware.opengl.enable = mkDefault true; - fonts.enableDefaultFonts = mkDefault true; - programs.dconf.enable = mkDefault true; - # To make a Sway session available if a display manager like SDDM is enabled: - services.xserver.displayManager.sessionPackages = optionals (cfg.package != null) [ cfg.package ]; - programs.xwayland.enable = mkDefault true; - # For screen sharing (this option only has an effect with xdg.portal.enable): - xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-wlr ]; - }; + (import ./wayland-session.nix { inherit lib; }) + ]); meta.maintainers = with lib.maintainers; [ primeos colemickens ]; } diff --git a/nixos/modules/programs/waybar.nix b/nixos/modules/programs/wayland/waybar.nix similarity index 100% rename from nixos/modules/programs/waybar.nix rename to nixos/modules/programs/wayland/waybar.nix diff --git a/nixos/modules/programs/wayland/wayland-session.nix b/nixos/modules/programs/wayland/wayland-session.nix new file mode 100644 index 000000000000..d58eb39b79a4 --- /dev/null +++ b/nixos/modules/programs/wayland/wayland-session.nix @@ -0,0 +1,26 @@ +{ lib, ... }: with lib; { + + security = { + polkit.enable = true; + pam.services.swaylock = {}; + }; + + hardware.opengl.enable = mkDefault true; + + fonts.enableDefaultFonts = mkDefault true; + + programs = { + dconf.enable = mkDefault true; + xwayland.enable = mkDefault true; + }; + + + xdg.portal = { + enable = mkDefault true; + + extraPortals = [ + # For screen sharing + pkgs.xdg-desktop-portal-wlr + ]; + }; +}