From cf159c437d2e417f4b8d836864938a0f9dd4f7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Wed, 22 May 2024 18:18:09 +0200 Subject: [PATCH 1/4] nixos/{sway,river}: make XWayland support optional --- nixos/modules/programs/wayland/river.nix | 41 +++++---- nixos/modules/programs/wayland/sway.nix | 86 +++++++++++-------- .../programs/wayland/wayland-session.nix | 38 ++++---- 3 files changed, 92 insertions(+), 73 deletions(-) diff --git a/nixos/modules/programs/wayland/river.nix b/nixos/modules/programs/wayland/river.nix index 6f8bafb15506..b83f13e2650e 100644 --- a/nixos/modules/programs/wayland/river.nix +++ b/nixos/modules/programs/wayland/river.nix @@ -1,23 +1,25 @@ -{ - config, - pkgs, - lib, - ... -}: +{ config, lib, pkgs, ... }: + let cfg = config.programs.river; -in { +in +{ options.programs.river = { enable = lib.mkEnableOption "river, a dynamic tiling Wayland compositor"; package = lib.mkPackageOption pkgs "river" { nullable = true; + default = pkgs.river.override { + xwaylandSupport = cfg.xwayland.enable; + }; extraDescription = '' Set to `null` to not add any River package to your path. This should be done if you want to use the Home Manager River module to install River. ''; }; + xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; }; + extraPackages = lib.mkOption { type = with lib.types; listOf package; default = with pkgs; [ @@ -41,19 +43,22 @@ in { }; }; - config = - lib.mkIf cfg.enable (lib.mkMerge [ - { - environment.systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + environment.systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; - # To make a river session available if a display manager like SDDM is enabled: - services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; + # To make a river session available if a display manager like SDDM is enabled: + services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 - xdg.portal.config.river.default = lib.mkDefault [ "wlr" "gtk" ]; - } - (import ./wayland-session.nix { inherit lib pkgs; }) - ]); + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 + xdg.portal.config.river.default = lib.mkDefault [ "wlr" "gtk" ]; + } + + (import ./wayland-session.nix { + inherit lib pkgs; + xwayland = cfg.xwayland.enable; + }) + ]); meta.maintainers = with lib.maintainers; [ GaetanLepage ]; } diff --git a/nixos/modules/programs/wayland/sway.nix b/nixos/modules/programs/wayland/sway.nix index cec634b6b033..b001b74c24a4 100644 --- a/nixos/modules/programs/wayland/sway.nix +++ b/nixos/modules/programs/wayland/sway.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ config, lib, pkgs, ... }: let cfg = config.programs.sway; @@ -31,6 +31,7 @@ let "extraOptions" "withBaseWrapper" "withGtkWrapper" + "enableXWayland" "isNixOS" ]; existedArgs = with lib; @@ -44,9 +45,11 @@ let extraOptions = cfg.extraOptions; withBaseWrapper = cfg.wrapperFeatures.base; withGtkWrapper = cfg.wrapperFeatures.gtk; + enableXWayland = cfg.xwayland.enable; isNixOS = true; }; -in { +in +{ options.programs.sway = { enable = lib.mkEnableOption '' Sway, the i3-compatible tiling Wayland compositor. You can manually launch @@ -63,8 +66,10 @@ in { description = '' Sway package to use. If the package does not contain the override arguments `extraSessionCommands`, `extraOptions`, `withBaseWrapper`, `withGtkWrapper`, - `isNixOS`, then the module options {option}`wrapperFeatures`, - {option}`wrapperFeatures` and {option}`wrapperFeatures` will have no effect. + `enableXWayland` and `isNixOS`, then the module options {option}`wrapperFeatures`, + {option}`extraSessionCommands`, {option}`extraOptions` and {option}`wayland` + will have no effect. + Set to `null` to not add any Sway package to your path. This should be done if you want to use the Home Manager Sway module to install Sway. ''; @@ -114,6 +119,8 @@ in { ''; }; + xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; }; + extraPackages = lib.mkOption { type = with lib.types; listOf package; default = with pkgs; [ @@ -135,46 +142,51 @@ in { for a list of useful software. ''; }; - }; - config = lib.mkIf cfg.enable - (lib.mkMerge [ - { - assertions = [ - { - assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; - message = '' - The extraSessionCommands for Sway will not be run if - wrapperFeatures.base is disabled. - ''; - } - ]; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + assertions = [ + { + assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; + message = '' + The extraSessionCommands for Sway will not be run if + wrapperFeatures.base is disabled. + ''; + } + ]; - environment = { - systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; - # Needed for the default wallpaper: - pathsToLink = lib.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 - ''; - } // lib.optionalAttrs (cfg.package != null) { - "sway/config".source = lib.mkOptionDefault "${cfg.package}/etc/sway/config"; - }; + environment = { + systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; + + # Needed for the default wallpaper: + pathsToLink = lib.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 + ''; + } // lib.optionalAttrs (cfg.package != null) { + "sway/config".source = lib.mkOptionDefault "${cfg.package}/etc/sway/config"; }; + }; - programs.gnupg.agent.pinentryPackage = lib.mkDefault pkgs.pinentry-gnome3; + programs.gnupg.agent.pinentryPackage = lib.mkDefault pkgs.pinentry-gnome3; - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 - xdg.portal.config.sway.default = lib.mkDefault [ "wlr" "gtk" ]; + # To make a Sway session available if a display manager like SDDM is enabled: + services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; - # To make a Sway session available if a display manager like SDDM is enabled: - services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; } - (import ./wayland-session.nix { inherit lib pkgs; }) - ]); + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 + xdg.portal.config.sway.default = lib.mkDefault [ "wlr" "gtk" ]; + } + + (import ./wayland-session.nix { + inherit lib pkgs; + xwayland = cfg.xwayland.enable; + }) + ]); meta.maintainers = with lib.maintainers; [ primeos colemickens ]; } diff --git a/nixos/modules/programs/wayland/wayland-session.nix b/nixos/modules/programs/wayland/wayland-session.nix index 47ee0788e0f3..09a68929e383 100644 --- a/nixos/modules/programs/wayland/wayland-session.nix +++ b/nixos/modules/programs/wayland/wayland-session.nix @@ -1,23 +1,25 @@ -{ lib, pkgs, ... }: { - security = { - polkit.enable = true; - pam.services.swaylock = {}; - }; +{ lib, pkgs, xwayland ? true }: - hardware.opengl.enable = lib.mkDefault true; - fonts.enableDefaultPackages = lib.mkDefault true; +{ + security = { + polkit.enable = true; + pam.services.swaylock = {}; + }; - programs = { - dconf.enable = lib.mkDefault true; - xwayland.enable = lib.mkDefault true; - }; + hardware.opengl.enable = lib.mkDefault true; + fonts.enableDefaultPackages = lib.mkDefault true; - xdg.portal = { - enable = lib.mkDefault true; + programs = { + dconf.enable = lib.mkDefault true; + xwayland.enable = lib.mkDefault xwayland; + }; - extraPortals = [ - # For screen sharing - pkgs.xdg-desktop-portal-wlr - ]; - }; + xdg.portal = { + enable = lib.mkDefault true; + + extraPortals = [ + # For screen sharing + pkgs.xdg-desktop-portal-wlr + ]; + }; } From a4160dfe88eeb857a66340335da60032b3eda2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Wed, 22 May 2024 18:40:25 +0200 Subject: [PATCH 2/4] nixos/hyprland: use generic wayland-session module --- nixos/modules/programs/wayland/hyprland.nix | 49 ++++++++----------- .../programs/wayland/wayland-session.nix | 9 +--- 2 files changed, 22 insertions(+), 36 deletions(-) diff --git a/nixos/modules/programs/wayland/hyprland.nix b/nixos/modules/programs/wayland/hyprland.nix index c963429f2e2a..89e0159779d9 100644 --- a/nixos/modules/programs/wayland/hyprland.nix +++ b/nixos/modules/programs/wayland/hyprland.nix @@ -1,8 +1,5 @@ -{ config -, lib -, pkgs -, ... -}: +{ config, lib, pkgs, ... }: + let cfg = config.programs.hyprland; @@ -53,33 +50,29 @@ in }; }; - config = lib.mkIf cfg.enable { - environment.systemPackages = [ cfg.finalPackage ]; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + environment.systemPackages = [ cfg.finalPackage ]; - fonts.enableDefaultPackages = lib.mkDefault true; - hardware.opengl.enable = lib.mkDefault true; + services.displayManager.sessionPackages = [ cfg.finalPackage ]; - programs = { - dconf.enable = lib.mkDefault true; - xwayland.enable = lib.mkDefault cfg.xwayland.enable; - }; + xdg.portal = { + extraPortals = [ finalPortalPackage ]; + configPackages = lib.mkDefault [ cfg.finalPackage ]; + }; - security.polkit.enable = true; + systemd = lib.mkIf cfg.systemd.setPath.enable { + user.extraConfig = '' + DefaultEnvironment="PATH=$PATH:/run/current-system/sw/bin:/etc/profiles/per-user/%u/bin:/run/wrappers/bin" + ''; + }; + } - services.displayManager.sessionPackages = [ cfg.finalPackage ]; - - xdg.portal = { - enable = lib.mkDefault true; - extraPortals = [ finalPortalPackage ]; - configPackages = lib.mkDefault [ cfg.finalPackage ]; - }; - - systemd = lib.mkIf cfg.systemd.setPath.enable { - user.extraConfig = '' - DefaultEnvironment="PATH=$PATH:/run/current-system/sw/bin:/etc/profiles/per-user/%u/bin:/run/wrappers/bin" - ''; - }; - }; + (import ./wayland-session.nix { + inherit lib pkgs; + xwayland = cfg.xwayland.enable; + }) + ]); imports = [ (lib.mkRemovedOptionModule diff --git a/nixos/modules/programs/wayland/wayland-session.nix b/nixos/modules/programs/wayland/wayland-session.nix index 09a68929e383..e9c12da156ab 100644 --- a/nixos/modules/programs/wayland/wayland-session.nix +++ b/nixos/modules/programs/wayland/wayland-session.nix @@ -14,12 +14,5 @@ xwayland.enable = lib.mkDefault xwayland; }; - xdg.portal = { - enable = lib.mkDefault true; - - extraPortals = [ - # For screen sharing - pkgs.xdg-desktop-portal-wlr - ]; - }; + xdg.portal.wlr.enable = lib.mkDefault true; } From bcbeccfa7d3fff2203ddfd4a2e4b8ba0f1f38584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Wed, 22 May 2024 19:14:29 +0200 Subject: [PATCH 3/4] nixos/{sway,river,hyprland}: cleanup --- nixos/modules/programs/wayland/hyprland.nix | 43 +++++---- nixos/modules/programs/wayland/river.nix | 12 +-- nixos/modules/programs/wayland/sway.nix | 98 +++++++-------------- 3 files changed, 59 insertions(+), 94 deletions(-) diff --git a/nixos/modules/programs/wayland/hyprland.nix b/nixos/modules/programs/wayland/hyprland.nix index 89e0159779d9..7176cfbbc2d2 100644 --- a/nixos/modules/programs/wayland/hyprland.nix +++ b/nixos/modules/programs/wayland/hyprland.nix @@ -2,23 +2,14 @@ let cfg = config.programs.hyprland; - - finalPortalPackage = cfg.portalPackage.override { - hyprland = cfg.finalPackage; - }; in { options.programs.hyprland = { - enable = lib.mkEnableOption null // { - description = '' - Whether to enable Hyprland, the dynamic tiling Wayland compositor that doesn't sacrifice on its looks. - - You can manually launch Hyprland by executing {command}`Hyprland` on a TTY. - - A configuration file will be generated in {file}`~/.config/hypr/hyprland.conf`. - See for more information. - ''; - }; + enable = lib.mkEnableOption '' + Hyprland, the dynamic tiling Wayland compositor that doesn't sacrifice on its looks. + You can manually launch Hyprland by executing {command}`Hyprland` on a TTY. + A configuration file will be generated in {file}`~/.config/hypr/hyprland.conf`. + See for more information''; package = lib.mkPackageOption pkgs "hyprland" { }; @@ -28,8 +19,9 @@ in default = cfg.package.override { enableXWayland = cfg.xwayland.enable; }; - defaultText = lib.literalExpression - "`programs.hyprland.package` with applied configuration"; + defaultText = lib.literalMD '' + `programs.hyprland.package` with applied configuration + ''; description = '' The Hyprland package after applying configuration. ''; @@ -37,7 +29,21 @@ in portalPackage = lib.mkPackageOption pkgs "xdg-desktop-portal-hyprland" { }; - xwayland.enable = lib.mkEnableOption ("XWayland") // { default = true; }; + finalPortalPackage = lib.mkOption { + type = lib.types.package; + readOnly = true; + default = cfg.portalPackage.override { + hyprland = cfg.finalPackage; + }; + defaultText = lib.literalMD '' + `programs.hyprland.portalPackage` with applied configuration + ''; + description = '' + The Hyprland Portal package after applying configuration. + ''; + }; + + xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; }; systemd.setPath.enable = lib.mkEnableOption null // { default = true; @@ -54,10 +60,11 @@ in { environment.systemPackages = [ cfg.finalPackage ]; + # To make a Hyprland session available if a display manager like SDDM is enabled: services.displayManager.sessionPackages = [ cfg.finalPackage ]; xdg.portal = { - extraPortals = [ finalPortalPackage ]; + extraPortals = [ cfg.finalPortalPackage ]; configPackages = lib.mkDefault [ cfg.finalPackage ]; }; diff --git a/nixos/modules/programs/wayland/river.nix b/nixos/modules/programs/wayland/river.nix index b83f13e2650e..ef8fbbd3489b 100644 --- a/nixos/modules/programs/wayland/river.nix +++ b/nixos/modules/programs/wayland/river.nix @@ -22,18 +22,12 @@ in extraPackages = lib.mkOption { type = with lib.types; listOf package; - default = with pkgs; [ - swaylock - foot - dmenu - ]; + default = with pkgs; [ swaylock foot dmenu ]; defaultText = lib.literalExpression '' with pkgs; [ swaylock foot dmenu ]; ''; example = lib.literalExpression '' - with pkgs; [ - termite rofi light - ] + with pkgs; [ termite rofi light ] ''; description = '' Extra packages to be installed system wide. See @@ -48,7 +42,7 @@ in environment.systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; # To make a river session available if a display manager like SDDM is enabled: - services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; + services.displayManager.sessionPackages = lib.optional (cfg.package != null) cfg.package; # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 xdg.portal.config.river.default = lib.mkDefault [ "wlr" "gtk" ]; diff --git a/nixos/modules/programs/wayland/sway.nix b/nixos/modules/programs/wayland/sway.nix index b001b74c24a4..20c4ea648479 100644 --- a/nixos/modules/programs/wayland/sway.nix +++ b/nixos/modules/programs/wayland/sway.nix @@ -3,44 +3,9 @@ let cfg = config.programs.sway; - wrapperOptions = lib.types.submodule { - options = - let - mkWrapperFeature = default: description: lib.mkOption { - type = lib.types.bool; - inherit default; - example = !default; - description = "Whether to make use of the ${description}"; - }; - in { - base = mkWrapperFeature true '' - base wrapper to execute extra session commands and prepend a - dbus-run-session to the sway command. - ''; - gtk = mkWrapperFeature false '' - wrapGAppsHook wrapper to execute sway with required environment - variables for GTK applications. - ''; - }; - }; - genFinalPackage = pkg: let - expectedArgs = lib.naturalSort [ - "extraSessionCommands" - "extraOptions" - "withBaseWrapper" - "withGtkWrapper" - "enableXWayland" - "isNixOS" - ]; - existedArgs = with lib; - naturalSort - (intersectLists expectedArgs (attrNames (functionArgs pkg.override))); - in if existedArgs != expectedArgs then - pkg - else - pkg.override { + args = { extraSessionCommands = cfg.extraSessionCommands; extraOptions = cfg.extraOptions; withBaseWrapper = cfg.wrapperFeatures.base; @@ -48,6 +13,13 @@ let enableXWayland = cfg.xwayland.enable; isNixOS = true; }; + + expectedArgs = with lib; + lib.naturalSort (lib.attrNames args); + existingArgs = with lib; + naturalSort (intersectLists expectedArgs (attrNames (functionArgs pkg.override))); + in + if existingArgs != expectedArgs then pkg else pkg.override args; in { options.programs.sway = { @@ -58,30 +30,28 @@ in and "man 5 sway" for more information''; - package = lib.mkOption { - type = with lib.types; nullOr package; - default = pkgs.sway; - apply = p: if p == null then null else genFinalPackage p; - defaultText = lib.literalExpression "pkgs.sway"; - description = '' - Sway package to use. If the package does not contain the override arguments - `extraSessionCommands`, `extraOptions`, `withBaseWrapper`, `withGtkWrapper`, - `enableXWayland` and `isNixOS`, then the module options {option}`wrapperFeatures`, - {option}`extraSessionCommands`, {option}`extraOptions` and {option}`wayland` - will have no effect. + package = lib.mkPackageOption pkgs "sway" { + nullable = true; + extraDescription = '' + If the package is not overridable with `extraSessionCommands`, `extraOptions`, + `withBaseWrapper`, `withGtkWrapper`, `enableXWayland` and `isNixOS`, + then the module options {option}`wrapperFeatures`, {option}`extraSessionCommands`, + {option}`extraOptions` and {option}`xwayland` will have no effect. - Set to `null` to not add any Sway package to your path. This should be done if - you want to use the Home Manager Sway module to install Sway. + Set to `null` to not add any Sway package to your path. + This should be done if you want to use the Home Manager Sway module to install Sway. ''; + } // { + apply = p: if p == null then null else genFinalPackage p; }; - wrapperFeatures = lib.mkOption { - type = wrapperOptions; - default = { }; - example = { gtk = true; }; - description = '' - Attribute set of features to enable in the wrapper. - ''; + wrapperFeatures = { + base = lib.mkEnableOption '' + the base wrapper to execute extra session commands and prepend a + dbus-run-session to the sway command'' // { default = true; }; + gtk = lib.mkEnableOption '' + the wrapGAppsHook wrapper to execute sway with required environment + variables for GTK applications''; }; extraSessionCommands = lib.mkOption { @@ -123,17 +93,12 @@ in extraPackages = lib.mkOption { type = with lib.types; listOf package; - default = with pkgs; [ - swaylock swayidle foot dmenu wmenu - ]; + default = with pkgs; [ swaylock swayidle foot dmenu wmenu ]; defaultText = lib.literalExpression '' with pkgs; [ swaylock swayidle foot dmenu wmenu ]; ''; example = lib.literalExpression '' - with pkgs; [ - i3status i3status-rust - termite rofi light - ] + with pkgs; [ i3status i3status-rust termite rofi light ] ''; description = '' Extra packages to be installed system wide. See @@ -150,8 +115,7 @@ in { assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base; message = '' - The extraSessionCommands for Sway will not be run if - wrapperFeatures.base is disabled. + The extraSessionCommands for Sway will not be run if wrapperFeatures.base is disabled. ''; } ]; @@ -160,7 +124,7 @@ in systemPackages = lib.optional (cfg.package != null) cfg.package ++ cfg.extraPackages; # Needed for the default wallpaper: - pathsToLink = lib.optionals (cfg.package != null) [ "/share/backgrounds/sway" ]; + pathsToLink = lib.optional (cfg.package != null) "/share/backgrounds/sway"; etc = { "sway/config.d/nixos.conf".source = pkgs.writeText "nixos.conf" '' @@ -176,7 +140,7 @@ in programs.gnupg.agent.pinentryPackage = lib.mkDefault pkgs.pinentry-gnome3; # To make a Sway session available if a display manager like SDDM is enabled: - services.displayManager.sessionPackages = lib.optionals (cfg.package != null) [ cfg.package ]; + services.displayManager.sessionPackages = lib.optional (cfg.package != null) cfg.package; # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050913 xdg.portal.config.sway.default = lib.mkDefault [ "wlr" "gtk" ]; From 95674de399b4c880f16059f8e2ce84e7388842d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlys=20Bras=20de=20fer?= Date: Wed, 22 May 2024 20:01:05 +0200 Subject: [PATCH 4/4] nixos/{river,hyprland}: override package using apply --- nixos/modules/programs/wayland/hyprland.nix | 50 +++++++++------------ nixos/modules/programs/wayland/lib.nix | 12 +++++ nixos/modules/programs/wayland/river.nix | 13 ++++-- nixos/modules/programs/wayland/sway.nix | 28 +++++------- 4 files changed, 53 insertions(+), 50 deletions(-) create mode 100644 nixos/modules/programs/wayland/lib.nix diff --git a/nixos/modules/programs/wayland/hyprland.nix b/nixos/modules/programs/wayland/hyprland.nix index 7176cfbbc2d2..f5ca741f9432 100644 --- a/nixos/modules/programs/wayland/hyprland.nix +++ b/nixos/modules/programs/wayland/hyprland.nix @@ -2,6 +2,8 @@ let cfg = config.programs.hyprland; + + wayland-lib = import ./lib.nix { inherit lib; }; in { options.programs.hyprland = { @@ -11,36 +13,26 @@ in A configuration file will be generated in {file}`~/.config/hypr/hyprland.conf`. See for more information''; - package = lib.mkPackageOption pkgs "hyprland" { }; - - finalPackage = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = cfg.package.override { + package = lib.mkPackageOption pkgs "hyprland" { + extraDescription = '' + If the package is not overridable with `enableXWayland`, then the module option + {option}`xwayland` will have no effect. + ''; + } // { + apply = p: wayland-lib.genFinalPackage p { enableXWayland = cfg.xwayland.enable; }; - defaultText = lib.literalMD '' - `programs.hyprland.package` with applied configuration - ''; - description = '' - The Hyprland package after applying configuration. - ''; }; - portalPackage = lib.mkPackageOption pkgs "xdg-desktop-portal-hyprland" { }; - - finalPortalPackage = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = cfg.portalPackage.override { - hyprland = cfg.finalPackage; + portalPackage = lib.mkPackageOption pkgs "xdg-desktop-portal-hyprland" { + extraDescription = '' + If the package is not overridable with `hyprland`, then the Hyprland package + used by the portal may differ from the one set in the module option {option}`package`. + ''; + } // { + apply = p: wayland-lib.genFinalPackage p { + hyprland = cfg.package; }; - defaultText = lib.literalMD '' - `programs.hyprland.portalPackage` with applied configuration - ''; - description = '' - The Hyprland Portal package after applying configuration. - ''; }; xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; }; @@ -58,14 +50,14 @@ in config = lib.mkIf cfg.enable (lib.mkMerge [ { - environment.systemPackages = [ cfg.finalPackage ]; + environment.systemPackages = [ cfg.package ]; # To make a Hyprland session available if a display manager like SDDM is enabled: - services.displayManager.sessionPackages = [ cfg.finalPackage ]; + services.displayManager.sessionPackages = [ cfg.package ]; xdg.portal = { - extraPortals = [ cfg.finalPortalPackage ]; - configPackages = lib.mkDefault [ cfg.finalPackage ]; + extraPortals = [ cfg.portalPackage ]; + configPackages = lib.mkDefault [ cfg.package ]; }; systemd = lib.mkIf cfg.systemd.setPath.enable { diff --git a/nixos/modules/programs/wayland/lib.nix b/nixos/modules/programs/wayland/lib.nix new file mode 100644 index 000000000000..0f275d3f18c5 --- /dev/null +++ b/nixos/modules/programs/wayland/lib.nix @@ -0,0 +1,12 @@ +{ lib }: + +{ + genFinalPackage = pkg: args: + let + expectedArgs = with lib; + lib.naturalSort (lib.attrNames args); + existingArgs = with lib; + naturalSort (intersectLists expectedArgs (attrNames (functionArgs pkg.override))); + in + if existingArgs != expectedArgs then pkg else pkg.override args; +} diff --git a/nixos/modules/programs/wayland/river.nix b/nixos/modules/programs/wayland/river.nix index ef8fbbd3489b..0980bd28cf82 100644 --- a/nixos/modules/programs/wayland/river.nix +++ b/nixos/modules/programs/wayland/river.nix @@ -2,6 +2,8 @@ let cfg = config.programs.river; + + wayland-lib = import ./lib.nix { inherit lib; }; in { options.programs.river = { @@ -9,13 +11,18 @@ in package = lib.mkPackageOption pkgs "river" { nullable = true; - default = pkgs.river.override { - xwaylandSupport = cfg.xwayland.enable; - }; extraDescription = '' + If the package is not overridable with `xwaylandSupport`, then the module option + {option}`xwayland` will have no effect. + Set to `null` to not add any River package to your path. This should be done if you want to use the Home Manager River module to install River. ''; + } // { + apply = p: if p == null then null else + wayland-lib.genFinalPackage p { + xwaylandSupport = cfg.xwayland.enable; + }; }; xwayland.enable = lib.mkEnableOption "XWayland" // { default = true; }; diff --git a/nixos/modules/programs/wayland/sway.nix b/nixos/modules/programs/wayland/sway.nix index 20c4ea648479..31821a84a5bd 100644 --- a/nixos/modules/programs/wayland/sway.nix +++ b/nixos/modules/programs/wayland/sway.nix @@ -3,23 +3,7 @@ let cfg = config.programs.sway; - genFinalPackage = pkg: - let - args = { - extraSessionCommands = cfg.extraSessionCommands; - extraOptions = cfg.extraOptions; - withBaseWrapper = cfg.wrapperFeatures.base; - withGtkWrapper = cfg.wrapperFeatures.gtk; - enableXWayland = cfg.xwayland.enable; - isNixOS = true; - }; - - expectedArgs = with lib; - lib.naturalSort (lib.attrNames args); - existingArgs = with lib; - naturalSort (intersectLists expectedArgs (attrNames (functionArgs pkg.override))); - in - if existingArgs != expectedArgs then pkg else pkg.override args; + wayland-lib = import ./lib.nix { inherit lib; }; in { options.programs.sway = { @@ -42,7 +26,15 @@ in This should be done if you want to use the Home Manager Sway module to install Sway. ''; } // { - apply = p: if p == null then null else genFinalPackage p; + apply = p: if p == null then null else + wayland-lib.genFinalPackage p { + extraSessionCommands = cfg.extraSessionCommands; + extraOptions = cfg.extraOptions; + withBaseWrapper = cfg.wrapperFeatures.base; + withGtkWrapper = cfg.wrapperFeatures.gtk; + enableXWayland = cfg.xwayland.enable; + isNixOS = true; + }; }; wrapperFeatures = {