diff --git a/modules/nixos/programs/gnome-session/default.nix b/modules/nixos/programs/gnome-session/default.nix index 84b55851..8c387130 100644 --- a/modules/nixos/programs/gnome-session/default.nix +++ b/modules/nixos/programs/gnome-session/default.nix @@ -8,15 +8,22 @@ let cfg = config.programs.gnome-session; + glibKeyfileFormat = pkgs.formats.ini { + listsAsDuplicateKeys = false; + mkKeyValue = + let + mkValueString = lib.generators.mkKeyValueDefault { }; + in + k: v: + if lib.isList v then lib.concatStringsSep ";" v + else "${k}=${mkValueString v}"; + }; + # The bulk of the work. Pretty much the main purpose of this module. sessionPackages = lib.mapAttrsToList (_: session: let - gnomeSession = '' - [GNOME Session] - Name=${session.fullName} session - RequiredComponents=${lib.concatStringsSep ";" session.requiredComponents}; - ''; + gnomeSession = glibKeyfileFormat.generate "session-${session.name}" session.settings; displaySession = '' [Desktop Entry] @@ -50,13 +57,13 @@ let '') session.components; in - pkgs.runCommandLocal "${session.name}-desktop-session-files" + pkgs.runCommand "${session.name}-desktop-session-files" { env = { inherit (session) fullName; }; inherit displaySession gnomeSession sessionScript; - passAsFile = [ "displaySession" "gnomeSession" "sessionScript" ]; + passAsFile = [ "displaySession" "sessionScript" ]; passthru.providedSessions = [ session.name ]; } '' @@ -65,8 +72,7 @@ let substituteAllInPlace "$SESSION_SCRIPT" GNOME_SESSION_FILE="$out/share/gnome-session/sessions/${session.name}.session" - install -Dm0644 "$gnomeSessionPath" "$GNOME_SESSION_FILE" - substituteAllInPlace "$GNOME_SESSION_FILE" + install -Dm0644 "$gnomeSession" "$GNOME_SESSION_FILE" DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${session.name}.desktop" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" @@ -116,7 +122,7 @@ in sessions = lib.mkOption { type = with lib.types; attrsOf (submoduleWith { - specialArgs = { inherit utils; }; + specialArgs = { inherit utils glibKeyfileFormat; }; modules = [ ./submodules/session-type.nix ]; }); description = '' diff --git a/modules/nixos/programs/gnome-session/submodules/session-type.nix b/modules/nixos/programs/gnome-session/submodules/session-type.nix index 0afa6a65..564bb488 100644 --- a/modules/nixos/programs/gnome-session/submodules/session-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/session-type.nix @@ -1,6 +1,7 @@ -{ name, config, lib, utils, ... }: +{ name, config, lib, utils, glibKeyfileFormat, ... }: let + # For an updated list, see `menu/menu-spec.xml` from # https://gitlab.freedesktop.org/xdg/xdg-specs. validDesktopNames = [ @@ -136,6 +137,25 @@ in ]; }; + settings = lib.mkOption { + type = glibKeyfileFormat.type; + description = '' + Settings to be included to the gnome-session keyfile of the session. + + Generally, you won't need to set this since the module will set the + common settings such as the `RequiredComponents=` key. + ''; + example = lib.literalExpression '' + { + # A helper script to check if the session is runnable. + IsRunnableHelper = "''${lib.getExe' pkgs.niri "niri"} --validate config"; + + # A fallback session in case it failed. + FallbackSession = "gnome"; + } + ''; + }; + requiredComponents = lib.mkOption { type = with lib.types; listOf str; description = '' @@ -205,5 +225,10 @@ in overrideStrategy = lib.mkForce "asDropin"; wants = lib.mkDefault (builtins.map (c: "${c}.target") config.requiredComponents); }; + + settings."GNOME Session" = { + Name = "${config.fullName} session"; + RequiredComponents = config.requiredComponents; + }; }; }