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:
displayScripts.${display})
session.display;
installDesktops =
installDesktopFiles =
lib.mapAttrsToList
(name: component:
let
scriptName = "${session.name}-${component.name}-script";
# 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;
desktopPackage = pkgs.makeDesktopItem component.desktopConfig;
in
''
install -Dm0644 ${desktopPackage}/share/applications/*.desktop -t $out/share/applications
@ -105,9 +94,9 @@ let
install -Dm0644 "$gnomeSessionPath" "$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;

View File

@ -1,4 +1,4 @@
{ name, config, lib, utils, session, ... }:
{ name, config, pkgs, lib, utils, session, ... }:
let
optionalSystemdUnitOption = type: systemdModuleAttribute:
@ -29,14 +29,22 @@ in
description = lib.mkOption {
type = lib.types.nonEmptyStr;
description = "One-sentence description of the component.";
default = name;
example = "Desktop widgets";
};
script = lib.mkOption {
type = lib.types.lines;
description = ''
Shell script fragment of the component. Take note this will be
wrapped in a script for proper integration with `gnome-session`.
Shell script fragment of the component.
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 = {
name = lib.mkForce config.id;
desktopName = lib.mkDefault "${session.fullName} - ${config.description}";
exec = lib.mkDefault (pkgs.writeShellScript "${session.name}-${config.name}-script" config.script);
noDisplay = lib.mkForce true;
onlyShowIn = session.desktopNames;
@ -213,7 +222,6 @@ in
NixOS-module-generated gnome-session sessions so we're not bothering with
those.
TODO: Is `Type=notify` a good default?
* `Service.Type=` is obviously not included since not all desktop
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

View File

@ -162,6 +162,7 @@ in
customized version of GNOME.
:::
'';
default = lib.mapAttrsToList (_: component: component.id) config.components;
example = [
"org.gnome.Shell"
"org.gnome.SettingsDaemon.A11ySettings"
@ -210,10 +211,6 @@ in
# Append the session argument.
extraArgs = [ "--session=${name}" ];
# 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 (builtins.map (c: "${c}.target") config.requiredComponents);