From ce9506a2bc9b10fb4e2e13cd62ca8b05d370669d Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 17 May 2024 10:43:17 +0800 Subject: [PATCH] nixos/programs/gnome-session: add name option for session and components Also updated the usage for `xToUnit` function from systemd-lib NixOS library. --- .../nixos/programs/gnome-session/default.nix | 35 +++++++++---------- .../submodules/component-type.nix | 11 ++++-- .../gnome-session/submodules/session-type.nix | 29 ++++++++------- 3 files changed, 41 insertions(+), 34 deletions(-) diff --git a/modules/nixos/programs/gnome-session/default.nix b/modules/nixos/programs/gnome-session/default.nix index 37d43dc4..6656c100 100644 --- a/modules/nixos/programs/gnome-session/default.nix +++ b/modules/nixos/programs/gnome-session/default.nix @@ -10,7 +10,7 @@ let # The bulk of the work. Pretty much the main purpose of this module. sessionPackages = lib.mapAttrsToList - (name: session: + (_: session: let gnomeSession = '' [GNOME Session] @@ -22,7 +22,7 @@ let [Desktop Entry] Name=@fullName@ Comment=${session.description} - Exec="@out@/libexec/${name}-session" + Exec="@out@/libexec/${session.name}-session" Type=Application DesktopNames=${lib.concatStringsSep ";" session.desktopNames}; ''; @@ -46,14 +46,14 @@ let { wayland = '' ( - DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${name}.desktop" + DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${session.name}.desktop" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" ${hasMoreDisplays "Wayland"} substituteAllInPlace "$DISPLAY_SESSION_FILE" ) ''; x11 = '' ( - DISPLAY_SESSION_FILE="$out/share/xsessions/${name}.desktop" + DISPLAY_SESSION_FILE="$out/share/xsessions/${session.name}.desktop" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" ${hasMoreDisplays "X11"} substituteAllInPlace "$DISPLAY_SESSION_FILE" ) @@ -66,13 +66,10 @@ let session.display; installDesktops = - let - sessionName = name; - in lib.mapAttrsToList (name: component: let - scriptName = "${sessionName}-${name}-script"; + 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). @@ -90,21 +87,21 @@ let '') session.components; in - pkgs.runCommandLocal "${name}-desktop-session-files" + pkgs.runCommandLocal "${session.name}-desktop-session-files" { env = { inherit (session) fullName; }; inherit displaySession gnomeSession sessionScript; passAsFile = [ "displaySession" "gnomeSession" "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" substituteAllInPlace "$SESSION_SCRIPT" - GNOME_SESSION_FILE="$out/share/gnome-session/sessions/${name}.session" + GNOME_SESSION_FILE="$out/share/gnome-session/sessions/${session.name}.session" install -Dm0644 "$gnomeSessionPath" "$GNOME_SESSION_FILE" substituteAllInPlace "$GNOME_SESSION_FILE" @@ -116,26 +113,26 @@ let cfg.sessions; sessionSystemdUnits = lib.concatMapAttrs - (name: session: + (_: session: let inherit (utils.systemdUtils.lib) pathToUnit serviceToUnit targetToUnit timerToUnit socketToUnit; mkSystemdUnits = name: component: { - "${component.id}.service" = serviceToUnit component.id component.serviceUnit; - "${component.id}.target" = targetToUnit component.id component.targetUnit; + "${component.id}.service" = serviceToUnit component.serviceUnit; + "${component.id}.target" = targetToUnit component.targetUnit; } // lib.optionalAttrs (component.socketUnit != null) { - "${component.id}.socket" = socketToUnit component.id component.socketUnit; + "${component.id}.socket" = socketToUnit component.socketUnit; } // lib.optionalAttrs (component.timerUnit != null) { - "${component.id}.timer" = timerToUnit component.id component.timerUnit; + "${component.id}.timer" = timerToUnit component.timerUnit; } // lib.optionalAttrs (component.pathUnit != null) { - "${component.id}.path" = pathToUnit component.id component.pathUnit; + "${component.id}.path" = pathToUnit component.pathUnit; }; componentsUnits = lib.concatMapAttrs mkSystemdUnits session.components; in componentsUnits // { - "gnome-session@${name}.target" = targetToUnit "gnome-session@${name}" session.targetUnit; + "gnome-session@${session.name}.target" = targetToUnit session.targetUnit; } ) cfg.sessions; diff --git a/modules/nixos/programs/gnome-session/submodules/component-type.nix b/modules/nixos/programs/gnome-session/submodules/component-type.nix index 65ac0682..9af0b3b5 100644 --- a/modules/nixos/programs/gnome-session/submodules/component-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/component-type.nix @@ -19,6 +19,13 @@ let in { options = { + name = lib.mkOption { + type = lib.types.nonEmptyStr; + description = "Component name."; + default = name; + example = "desktop-manager"; + }; + description = lib.mkOption { type = lib.types.nonEmptyStr; description = "One-sentence description of the component."; @@ -163,7 +170,7 @@ in The identifier of the component used in generating filenames for its `.desktop` files and as part of systemd unit names. ''; - default = "${session.name}.${name}"; + default = "${session.name}.${config.name}"; defaultText = "\${session-name}.\${name}"; readOnly = true; }; @@ -203,7 +210,7 @@ in * Even if we have a way to limit starting desktop components with `systemd-xdg-autostart-condition`, using `Service.ExecCondition=` would severely limit possible reuse of desktop components with other - NixOS-module-generated sessiond sessions so we're not bothering with + NixOS-module-generated gnome-session sessions so we're not bothering with those. TODO: Is `Type=notify` a good default? diff --git a/modules/nixos/programs/gnome-session/submodules/session-type.nix b/modules/nixos/programs/gnome-session/submodules/session-type.nix index e080ada8..fa4c5e46 100644 --- a/modules/nixos/programs/gnome-session/submodules/session-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/session-type.nix @@ -28,6 +28,22 @@ let in { options = { + name = lib.mkOption { + type = lib.types.nonEmptyStr; + description = '' + The identifier of the desktop environment to be used for the filenames + of related outputs. + + ::: {.note} + While there is no formal specification around naming them, a common + convention is to use kebab-casing of the name (e.g., "mosey-branch" for + "Mosey Branch"). + ::: + ''; + default = name; + example = "mosey-branch"; + }; + fullName = lib.mkOption { type = lib.types.nonEmptyStr; description = "The display name of the desktop environment."; @@ -188,19 +204,6 @@ in } ''; }; - - sessionPackage = lib.mkOption { - type = lib.types.package; - description = '' - The collective package containing everything desktop-related - such as: - - * The display session (`.desktop`) files. - * gnome-session `.session` file. - * The components `.desktop` file. - ''; - readOnly = true; - }; }; config = {