nixos/programs/sessiond: add name option for session and components

Also similar change to the gnome-session one, blah blah blah...
This commit is contained in:
Gabriel Arazas 2024-05-17 10:56:46 +08:00
parent ce9506a2bc
commit 93de33e028
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
3 changed files with 42 additions and 20 deletions

View File

@ -4,13 +4,13 @@ let
cfg = config.programs.sessiond; cfg = config.programs.sessiond;
sessionPackages = lib.mapAttrsToList sessionPackages = lib.mapAttrsToList
(name: session: (_: session:
let let
displaySession = '' displaySession = ''
[Desktop Entry] [Desktop Entry]
Name=${session.fullName} Name=${session.fullName}
Comment=${session.description} Comment=${session.description}
Exec="@out@/libexec/${name}-session" Exec="@out@/libexec/${session.name}-session"
Type=Application Type=Application
DesktopNames=${lib.concatStringsSep ";" session.desktopNames}; DesktopNames=${lib.concatStringsSep ";" session.desktopNames};
''; '';
@ -18,21 +18,21 @@ let
sessionScript = '' sessionScript = ''
#!${pkgs.runtimeShell} #!${pkgs.runtimeShell}
${lib.getExe' cfg.package "sessionctl"} run "${name}.target" ${lib.getExe' cfg.package "sessionctl"} run "${session.name}.target"
''; '';
in in
pkgs.runCommandLocal "${name}-desktop-session-files" pkgs.runCommandLocal "${session.name}-desktop-session-files"
{ {
inherit displaySession sessionScript; inherit displaySession sessionScript;
passAsFile = [ "displaySession" "sessionScript" ]; passAsFile = [ "displaySession" "sessionScript" ];
passthru.providedSessions = [ name ]; passthru.providedSessions = [ session.name ];
} }
'' ''
SESSION_SCRIPT="$out/libexec/${name}-session" SESSION_SCRIPT="$out/libexec/${session.name}-session"
install -Dm0755 "$sessionScriptPath" "$SESSION_SCRIPT" install -Dm0755 "$sessionScriptPath" "$SESSION_SCRIPT"
substituteAllInPlace "$SESSION_SCRIPT" substituteAllInPlace "$SESSION_SCRIPT"
DISPLAY_SESSION_FILE="$out/share/xsessions/${name}.desktop" DISPLAY_SESSION_FILE="$out/share/xsessions/${session.name}.desktop"
install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE"
substituteAllInPlace "$DISPLAY_SESSION_FILE" substituteAllInPlace "$DISPLAY_SESSION_FILE"
'' ''
@ -46,22 +46,22 @@ let
pathToUnit serviceToUnit targetToUnit timerToUnit socketToUnit; pathToUnit serviceToUnit targetToUnit timerToUnit socketToUnit;
mkSystemdUnits = name: component: { mkSystemdUnits = name: component: {
"${component.id}.service" = serviceToUnit component.id component.serviceUnit; "${component.id}.service" = serviceToUnit component.serviceUnit;
"${component.id}.target" = targetToUnit component.id component.targetUnit; "${component.id}.target" = targetToUnit component.targetUnit;
} // lib.optionalAttrs (component.socketUnit != null) { } // lib.optionalAttrs (component.socketUnit != null) {
"${component.id}.socket" = socketToUnit component.id component.socketUnit; "${component.id}.socket" = socketToUnit component.socketUnit;
} // lib.optionalAttrs (component.timerUnit != null) { } // lib.optionalAttrs (component.timerUnit != null) {
"${component.id}.timer" = timerToUnit component.id component.timerUnit; "${component.id}.timer" = timerToUnit component.timerUnit;
} // lib.optionalAttrs (component.pathUnit != null) { } // lib.optionalAttrs (component.pathUnit != null) {
"${component.id}.path" = pathToUnit component.id component.pathUnit; "${component.id}.path" = pathToUnit component.pathUnit;
}; };
sessionComponents = sessionComponents =
lib.concatMapAttrs mkSystemdUnits session.components; lib.concatMapAttrs mkSystemdUnits session.components;
in in
sessionComponents // { sessionComponents // {
"${name}.service" = serviceToUnit name session.serviceUnit; "${session.name}.service" = serviceToUnit session.serviceUnit;
"${name}.target" = targetToUnit name session.targetUnit; "${session.name}.target" = targetToUnit session.targetUnit;
} }
) )
cfg.sessions; cfg.sessions;

View File

@ -18,6 +18,13 @@ let
in in
{ {
options = { options = {
name = lib.mkOption {
type = lib.types.nonEmptyStr;
description = "The identifier of the component.";
default = name;
example = "desktop-widgets";
};
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.";
@ -124,7 +131,7 @@ in
The identifier of the component used in generating filenames for its The identifier of the component used in generating filenames for its
`.desktop` files and as part of systemd unit names. `.desktop` files and as part of systemd unit names.
''; '';
default = "${session.name}.${name}"; default = "${session.name}.${config.name}";
defaultText = "\${session-name}.\${name}"; defaultText = "\${session-name}.\${name}";
readOnly = true; readOnly = true;
}; };

View File

@ -29,10 +29,25 @@ let
# This is used both as the configuration format for sessiond.conf and its # This is used both as the configuration format for sessiond.conf and its
# hooks. # hooks.
settingsFormat = pkgs.formats.toml { }; settingsFormat = pkgs.formats.toml { };
sessionSettingsFile = settingsFormat.generate "sessiond-conf-${name}" config.settings; sessionSettingsFile = settingsFormat.generate "sessiond-conf-${config.name}" config.settings;
in in
{ {
options = { options = {
name = lib.mkOption {
type = lib.types.nonEmptyStr;
description = ''
The identifier for the desktop environment.
::: {.note}
While there is no formal standard for naming these, it is recommended
to make the name in kebab-case (for example, "mosey-branch" for "Mosey
branch").
:::
'';
default = name;
example = "mosey-branch";
};
fullName = lib.mkOption { fullName = lib.mkOption {
type = lib.types.nonEmptyStr; type = lib.types.nonEmptyStr;
description = "The display name of the desktop environment."; description = "The display name of the desktop environment.";
@ -202,7 +217,7 @@ in
targetUnit = { targetUnit = {
description = config.description; description = config.description;
requires = [ "${name}.service" ]; requires = [ "${config.name}.service" ];
wants = wants =
let let
componentTargetUnits = componentTargetUnits =
@ -213,9 +228,9 @@ in
serviceUnit = { serviceUnit = {
description = config.description; description = config.description;
partOf = [ "${name}.target" ]; partOf = [ "${config.name}.target" ];
before = [ "${name}.target" ]; before = [ "${config.name}.target" ];
requisite = [ "${name}.target" ]; requisite = [ "${config.name}.target" ];
requires = [ "dbus.socket" ]; requires = [ "dbus.socket" ];
after = [ "dbus.socket" ]; after = [ "dbus.socket" ];