1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 03:30:45 +00:00

nixos/{river,hyprland}: override package using apply

This commit is contained in:
Maëlys Bras de fer 2024-05-22 20:01:05 +02:00
parent bcbeccfa7d
commit 95674de399
4 changed files with 53 additions and 50 deletions

View file

@ -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 <https://wiki.hyprland.org> 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 {

View file

@ -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;
}

View file

@ -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; };

View file

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