nixos/programs/gnome-session: add sessions.<name>.settings

This will allow for some flexibility for REALLY OBSCURE custom desktop
sessions but we'll still keep the `requiredComponents` option since it
is so common and most likely what the user will modify anyways.
This commit is contained in:
Gabriel Arazas 2024-06-22 22:30:48 +08:00
parent a808b01f42
commit 90476b0774
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 42 additions and 11 deletions

View File

@ -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 = ''

View File

@ -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;
};
};
}