nixos/programs/gnome-session: refactor and update module

This commit is contained in:
Gabriel Arazas 2024-06-05 16:28:46 +08:00
parent 999401f3ce
commit 0c69a64ff8
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
3 changed files with 18 additions and 24 deletions

View File

@ -60,27 +60,16 @@ let
''; '';
}; };
installDesktopSessions = builtins.map installDesktopSessionFiles = builtins.map
(display: (display:
displayScripts.${display}) displayScripts.${display})
session.display; session.display;
installDesktops = installDesktopFiles =
lib.mapAttrsToList lib.mapAttrsToList
(name: component: (name: component:
let let
scriptName = "${session.name}-${component.name}-script"; desktopPackage = pkgs.makeDesktopItem component.desktopConfig;
# There's already a lot of bad bad things in this world, we
# don't to add more of it here (only a fraction of it, though).
scriptPackage = pkgs.writeShellApplication {
name = scriptName;
text = component.script;
};
script = "${scriptPackage}/bin/${scriptName}";
desktopConfig = lib.mergeAttrs component.desktopConfig { exec = script; };
desktopPackage = pkgs.makeDesktopItem desktopConfig;
in in
'' ''
install -Dm0644 ${desktopPackage}/share/applications/*.desktop -t $out/share/applications install -Dm0644 ${desktopPackage}/share/applications/*.desktop -t $out/share/applications
@ -105,9 +94,9 @@ let
install -Dm0644 "$gnomeSessionPath" "$GNOME_SESSION_FILE" install -Dm0644 "$gnomeSessionPath" "$GNOME_SESSION_FILE"
substituteAllInPlace "$GNOME_SESSION_FILE" substituteAllInPlace "$GNOME_SESSION_FILE"
${lib.concatStringsSep "\n" installDesktopSessions} ${lib.concatStringsSep "\n" installDesktopSessionFiles}
${lib.concatStringsSep "\n" installDesktops} ${lib.concatStringsSep "\n" installDesktopFiles}
'' ''
) )
cfg.sessions; cfg.sessions;

View File

@ -1,4 +1,4 @@
{ name, config, lib, utils, session, ... }: { name, config, pkgs, lib, utils, session, ... }:
let let
optionalSystemdUnitOption = type: systemdModuleAttribute: optionalSystemdUnitOption = type: systemdModuleAttribute:
@ -29,14 +29,22 @@ in
description = lib.mkOption { description = lib.mkOption {
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
description = "One-sentence description of the component."; description = "One-sentence description of the component.";
default = name;
example = "Desktop widgets"; example = "Desktop widgets";
}; };
script = lib.mkOption { script = lib.mkOption {
type = lib.types.lines; type = lib.types.lines;
description = '' description = ''
Shell script fragment of the component. Take note this will be Shell script fragment of the component.
wrapped in a script for proper integration with `gnome-session`.
The way it is handled is different per startup methods.
* This will be wrapped in a script for proper integration with the
legacy non-systemd session management.
* For systemd-managed sessions, it will be part of
{option}`programs.gnome-session.sessions.<sessions>.components.<name>.serviceUnit.script`.
''; '';
}; };
@ -182,6 +190,7 @@ in
desktopConfig = { desktopConfig = {
name = lib.mkForce config.id; name = lib.mkForce config.id;
desktopName = lib.mkDefault "${session.fullName} - ${config.description}"; desktopName = lib.mkDefault "${session.fullName} - ${config.description}";
exec = lib.mkDefault (pkgs.writeShellScript "${session.name}-${config.name}-script" config.script);
noDisplay = lib.mkForce true; noDisplay = lib.mkForce true;
onlyShowIn = session.desktopNames; onlyShowIn = session.desktopNames;
@ -213,7 +222,6 @@ in
NixOS-module-generated gnome-session sessions so we're not bothering with NixOS-module-generated gnome-session sessions so we're not bothering with
those. those.
TODO: Is `Type=notify` a good default?
* `Service.Type=` is obviously not included since not all desktop * `Service.Type=` is obviously not included since not all desktop
components are the same either. Some of them could be a D-Bus service, components are the same either. Some of them could be a D-Bus service,
some of them are oneshots, etc. Though, it might be better to have this some of them are oneshots, etc. Though, it might be better to have this

View File

@ -162,6 +162,7 @@ in
customized version of GNOME. customized version of GNOME.
::: :::
''; '';
default = lib.mapAttrsToList (_: component: component.id) config.components;
example = [ example = [
"org.gnome.Shell" "org.gnome.Shell"
"org.gnome.SettingsDaemon.A11ySettings" "org.gnome.SettingsDaemon.A11ySettings"
@ -210,10 +211,6 @@ in
# Append the session argument. # Append the session argument.
extraArgs = [ "--session=${name}" ]; extraArgs = [ "--session=${name}" ];
# By default. set the required components from the given desktop
# components.
requiredComponents = lib.mapAttrsToList (_: component: component.id) config.components;
targetUnit = { targetUnit = {
overrideStrategy = lib.mkForce "asDropin"; overrideStrategy = lib.mkForce "asDropin";
wants = lib.mkDefault (builtins.map (c: "${c}.target") config.requiredComponents); wants = lib.mkDefault (builtins.map (c: "${c}.target") config.requiredComponents);