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 = {