From 0c69a64ff8ef79c177b17b3cb0d98daeb9e0b22d Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 5 Jun 2024 16:28:46 +0800 Subject: [PATCH] nixos/programs/gnome-session: refactor and update module --- .../nixos/programs/gnome-session/default.nix | 21 +++++-------------- .../submodules/component-type.nix | 16 ++++++++++---- .../gnome-session/submodules/session-type.nix | 5 +---- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/modules/nixos/programs/gnome-session/default.nix b/modules/nixos/programs/gnome-session/default.nix index 6656c100..d044b712 100644 --- a/modules/nixos/programs/gnome-session/default.nix +++ b/modules/nixos/programs/gnome-session/default.nix @@ -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; diff --git a/modules/nixos/programs/gnome-session/submodules/component-type.nix b/modules/nixos/programs/gnome-session/submodules/component-type.nix index 9af0b3b5..77b7a5bd 100644 --- a/modules/nixos/programs/gnome-session/submodules/component-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/component-type.nix @@ -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..components..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 diff --git a/modules/nixos/programs/gnome-session/submodules/session-type.nix b/modules/nixos/programs/gnome-session/submodules/session-type.nix index fa4c5e46..63511b71 100644 --- a/modules/nixos/programs/gnome-session/submodules/session-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/session-type.nix @@ -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);