From da5a938a8aa73730f398c9f954539e2fdceb0ff3 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 6 Jan 2024 18:50:03 +0800 Subject: [PATCH] programs/gnome-session: add `requiredComponents` for session This is to make requiring desktop components from other packages easier. --- .../nixos/programs/gnome-session/default.nix | 53 +++++++++++++++---- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/modules/nixos/programs/gnome-session/default.nix b/modules/nixos/programs/gnome-session/default.nix index 9ff2abd7..2a62435a 100644 --- a/modules/nixos/programs/gnome-session/default.nix +++ b/modules/nixos/programs/gnome-session/default.nix @@ -408,6 +408,30 @@ let ]; }; + requiredComponents = lib.mkOption { + type = with lib.types; listOf str; + description = '' + A list of desktop components as part of `RequiredComponents=` for the + gnome-session configuration. + + ::: {.note} + For the most part, this shouldn't require manually configuring it if + you set {option}`.components` as this module already sets + them for you. + + The only time you manually set this if you want to require components + from other desktop such as when creating a customized version of + GNOME. + ::: + ''; + example = [ + "org.gnome.Shell" + "org.gnome.SettingsDaemon.A11ySettings" + "org.gnome.SettingsDaemon.Power" + "org.gnome.SettingsDaemon.Wacom" + ]; + }; + targetUnit = lib.mkOption { type = let @@ -419,10 +443,16 @@ let unitConfig ]; description = '' - systemd target configuration to be generated. This should be - configured if the session is managed by systemd and you want to - control the session further (which is recommended since this module - don't know what components are more important, etc.). + systemd target configuration to be generated for + `gnome-session@.target`. This should be configured if the + session is managed by systemd and you want to control the session + further (which is recommended since this module don't know what + components are more important, etc.). + + By default, the session target will have all of its components from + {option}`.requiredComponents` under `Wants=` directive. It + also assumes all of them have a target unit at + `''${requiredComponent}.target`. :::{.note} This has the same options as {option}`systemd.user.targets.` @@ -432,7 +462,7 @@ let ''; defaultText = '' { - wants = ... # All of the components. + wants = ... # All of the required components as a target unit. } ''; }; @@ -495,21 +525,22 @@ let "gnome-session@${name}.target" = targetToUnit "gnome-session@${name}" config.targetUnit; }; + # By default. set the required components from the given desktop + # components. + requiredComponents = lib.mapAttrsToList (_: component: component.id) config.components; + targetUnit = { overrideStrategy = lib.mkForce "asDropin"; - wants = lib.mkDefault (lib.mapAttrsToList (_: component: "${component.id}.target") config.components); + wants = lib.mkDefault (builtins.map (c: "${c}.target") config.requiredComponents); }; + # The bulk of the work. Pretty much the main purpose of this module. sessionPackage = let - requiredComponents = lib.mapAttrsToList - (_: component: component.id) - config.components; - gnomeSession = '' [GNOME Session] Name=${config.fullName} session - RequiredComponents=${lib.concatStringsSep ";" requiredComponents}; + RequiredComponents=${lib.concatStringsSep ";" config.requiredComponents}; ''; displaySession = ''