From e3350bd17d42edf1b18bfe06b44b7920bb1adc91 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Tue, 25 Jun 2024 22:41:17 +0800 Subject: [PATCH] nixos/programs/gnome-session: fix session settings format and submodule module argument passing --- .../nixos/programs/gnome-session/default.nix | 36 ++++++++++++++----- .../gnome-session/submodules/session-type.nix | 17 ++++----- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/modules/nixos/programs/gnome-session/default.nix b/modules/nixos/programs/gnome-session/default.nix index 8c387130..2afdbd94 100644 --- a/modules/nixos/programs/gnome-session/default.nix +++ b/modules/nixos/programs/gnome-session/default.nix @@ -8,15 +8,33 @@ let cfg = config.programs.gnome-session; + # The gnome-session config files uses one from GLib. See the following link + # at for details about the + # keyfile formatting and possibly the Desktop Entry specification at + # . glibKeyfileFormat = pkgs.formats.ini { 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 - 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 - k: v: - if lib.isList v then lib.concatStringsSep ";" v - else "${k}=${mkValueString v}"; + attrsOf (attrsOf valueType); }; # The bulk of the work. Pretty much the main purpose of this module. @@ -25,13 +43,14 @@ let let gnomeSession = glibKeyfileFormat.generate "session-${session.name}" session.settings; + # For now, we set this as a displaySession = '' [Desktop Entry] - Name=@fullName@ + Name=${session.fullName} Comment=${session.description} Exec="@out@/libexec/${session.name}-session" Type=Application - DesktopNames=${lib.concatStringsSep ";" session.desktopNames}; + DesktopNames=${lib.concatStringsSep ";" session.desktopNames} ''; sessionScript = '' @@ -76,6 +95,7 @@ let DISPLAY_SESSION_FILE="$out/share/wayland-sessions/${session.name}.desktop" install -Dm0644 "$displaySessionPath" "$DISPLAY_SESSION_FILE" + substituteAllInPlace "$DISPLAY_SESSION_FILE" ${lib.concatStringsSep "\n" installDesktopFiles} '' @@ -122,7 +142,7 @@ in sessions = lib.mkOption { type = with lib.types; attrsOf (submoduleWith { - specialArgs = { inherit utils glibKeyfileFormat; }; + specialArgs = { inherit utils glibKeyfileFormat pkgs; }; 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 564bb488..f87c5198 100644 --- a/modules/nixos/programs/gnome-session/submodules/session-type.nix +++ b/modules/nixos/programs/gnome-session/submodules/session-type.nix @@ -1,7 +1,6 @@ -{ name, config, lib, utils, glibKeyfileFormat, ... }: +{ name, config, pkgs, lib, utils, glibKeyfileFormat, ... }: let - # For an updated list, see `menu/menu-spec.xml` from # https://gitlab.freedesktop.org/xdg/xdg-specs. validDesktopNames = [ @@ -92,7 +91,7 @@ in components = lib.mkOption { type = with lib.types; attrsOf (submoduleWith { specialArgs = { - inherit utils; + inherit utils pkgs; session = { inherit (config) fullName desktopNames description; inherit name; @@ -147,11 +146,13 @@ in ''; example = lib.literalExpression '' { - # A helper script to check if the session is runnable. - IsRunnableHelper = "''${lib.getExe' pkgs.niri "niri"} --validate config"; + "GNOME Session" = { + # 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"; + # A fallback session in case it failed. + FallbackSession = "gnome"; + }; } ''; }; @@ -227,7 +228,7 @@ in }; settings."GNOME Session" = { - Name = "${config.fullName} session"; + Name = lib.mkDefault "${config.fullName} session"; RequiredComponents = config.requiredComponents; }; };