nixos/programs/gnome-session: fix session settings format and submodule module argument passing

This commit is contained in:
Gabriel Arazas 2024-06-25 22:41:17 +08:00
parent 56c05bad48
commit e3350bd17d
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
2 changed files with 37 additions and 16 deletions

View File

@ -8,15 +8,33 @@
let let
cfg = config.programs.gnome-session; cfg = config.programs.gnome-session;
# The gnome-session config files uses one from GLib. See the following link
# at <https://docs.gtk.org/glib/struct.KeyFile.html> for details about the
# keyfile formatting and possibly the Desktop Entry specification at
# <https://freedesktop.org/wiki/Specifications/desktop-entry-spec>.
glibKeyfileFormat = pkgs.formats.ini { glibKeyfileFormat = pkgs.formats.ini {
listsAsDuplicateKeys = false; listsAsDuplicateKeys = false;
mkKeyValue = mkKeyValue = lib.generators.mkKeyValueDefault {
mkValueString = v:
if lib.isList v then
lib.concatStringsSep ";" v
else
lib.generators.mkValueStringDefault { } v;
} "=";
} // {
type = with lib.types;
let let
mkValueString = lib.generators.mkKeyValueDefault { }; valueType = oneOf [
bool
float
int
str
(listOf valueType)
] // {
description = "GLib keyfile atom (null, bool, int, float, string, or a list of the previous atoms)";
};
in in
k: v: attrsOf (attrsOf valueType);
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. # The bulk of the work. Pretty much the main purpose of this module.
@ -25,13 +43,14 @@ let
let let
gnomeSession = glibKeyfileFormat.generate "session-${session.name}" session.settings; gnomeSession = glibKeyfileFormat.generate "session-${session.name}" session.settings;
# For now, we set this as a
displaySession = '' displaySession = ''
[Desktop Entry] [Desktop Entry]
Name=@fullName@ Name=${session.fullName}
Comment=${session.description} Comment=${session.description}
Exec="@out@/libexec/${session.name}-session" Exec="@out@/libexec/${session.name}-session"
Type=Application Type=Application
DesktopNames=${lib.concatStringsSep ";" session.desktopNames}; DesktopNames=${lib.concatStringsSep ";" session.desktopNames}
''; '';
sessionScript = '' sessionScript = ''
@ -76,6 +95,7 @@ let
DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${session.name}.desktop" DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${session.name}.desktop"
install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE"
substituteAllInPlace "$DISPLAY_SESSION_FILE"
${lib.concatStringsSep "\n" installDesktopFiles} ${lib.concatStringsSep "\n" installDesktopFiles}
'' ''
@ -122,7 +142,7 @@ in
sessions = lib.mkOption { sessions = lib.mkOption {
type = with lib.types; attrsOf (submoduleWith { type = with lib.types; attrsOf (submoduleWith {
specialArgs = { inherit utils glibKeyfileFormat; }; specialArgs = { inherit utils glibKeyfileFormat pkgs; };
modules = [ ./submodules/session-type.nix ]; modules = [ ./submodules/session-type.nix ];
}); });
description = '' description = ''

View File

@ -1,7 +1,6 @@
{ name, config, lib, utils, glibKeyfileFormat, ... }: { name, config, pkgs, lib, utils, glibKeyfileFormat, ... }:
let let
# For an updated list, see `menu/menu-spec.xml` from # For an updated list, see `menu/menu-spec.xml` from
# https://gitlab.freedesktop.org/xdg/xdg-specs. # https://gitlab.freedesktop.org/xdg/xdg-specs.
validDesktopNames = [ validDesktopNames = [
@ -92,7 +91,7 @@ in
components = lib.mkOption { components = lib.mkOption {
type = with lib.types; attrsOf (submoduleWith { type = with lib.types; attrsOf (submoduleWith {
specialArgs = { specialArgs = {
inherit utils; inherit utils pkgs;
session = { session = {
inherit (config) fullName desktopNames description; inherit (config) fullName desktopNames description;
inherit name; inherit name;
@ -147,11 +146,13 @@ in
''; '';
example = lib.literalExpression '' example = lib.literalExpression ''
{ {
"GNOME Session" = {
# A helper script to check if the session is runnable. # A helper script to check if the session is runnable.
IsRunnableHelper = "''${lib.getExe' pkgs.niri "niri"} --validate config"; IsRunnableHelper = "''${lib.getExe' pkgs.niri "niri"} --validate config";
# A fallback session in case it failed. # A fallback session in case it failed.
FallbackSession = "gnome"; FallbackSession = "gnome";
};
} }
''; '';
}; };
@ -227,7 +228,7 @@ in
}; };
settings."GNOME Session" = { settings."GNOME Session" = {
Name = "${config.fullName} session"; Name = lib.mkDefault "${config.fullName} session";
RequiredComponents = config.requiredComponents; RequiredComponents = config.requiredComponents;
}; };
}; };