From 6a171bfd84ee9b3df83f6eb76dab042219978439 Mon Sep 17 00:00:00 2001 From: Pasquale Date: Wed, 15 Dec 2021 18:31:13 +0100 Subject: [PATCH] kconfig: add module --- modules/misc/qt/kconfig.nix | 73 +++++++++++++++++++++++++++++++++++++ modules/modules.nix | 1 + 2 files changed, 74 insertions(+) create mode 100644 modules/misc/qt/kconfig.nix diff --git a/modules/misc/qt/kconfig.nix b/modules/misc/qt/kconfig.nix new file mode 100644 index 000000000..22139f5cf --- /dev/null +++ b/modules/misc/qt/kconfig.nix @@ -0,0 +1,73 @@ +{ config, pkgs, lib, ... }: + +let + + cfg = config.qt.kde.settings; +in { + options.qt.kde.settings = lib.mkOption { + type = with lib.types; + let + valueType = + nullOr (oneOf [ bool int float str path (attrsOf valueType) ]) // { + description = "KDE option value"; + }; + in attrsOf valueType; + default = { }; + example = { + powermanagementprofilesrc.AC.HandleButtonEvents.lidAction = 32; + }; + description = '' + A set of values to be modified by {command}`kwriteconfig5`. + + The example value would cause the following command to run in the + activation script: + + ``` shell + kwriteconfig5 --file $XDG_CONFIG_HOME/powermanagementprofilesrc \ + --group AC \ + --group HandleButtonEvents \ + --group lidAction \ + --key lidAction \ + 32 + ``` + + Note, `null` values will delete the corresponding entry instead of + inserting any value. + ''; + }; + + config = lib.mkIf (cfg != { }) { + home.activation.kconfig = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + ${let + inherit (config.xdg) configHome; + toValue = v: + let t = builtins.typeOf v; + in if v == null then + "--delete" + else if t == "bool" then + "--type bool ${builtins.toJSON v}" + else + toString v; + toLine = file: path: value: + if builtins.isAttrs value then + lib.mapAttrsToList + (group: value: toLine file (path ++ [ group ]) value) value + else + "run test -f '${configHome}/${file}' && run ${pkgs.libsForQt5.kconfig}/bin/kwriteconfig5 --file '${configHome}/${file}' ${ + lib.concatMapStringsSep " " (x: "--group ${x}") + (lib.lists.init path) + } --key '${lib.lists.last path}' ${toValue value}"; + lines = lib.flatten + (lib.mapAttrsToList (file: attrs: toLine file [ ] attrs) cfg); + in builtins.concatStringsSep "\n" lines} + + # TODO: some way to only call the dbus calls needed + run ${pkgs.libsForQt5.qttools.bin}/bin/qdbus org.kde.KWin /KWin reconfigure || echo "KWin reconfigure failed" + # the actual values are https://github.com/KDE/plasma-workspace/blob/c97dddf20df5702eb429b37a8c10b2c2d8199d4e/kcms/kcms-common_p.h#L13 + for changeType in {0..10}; do + # even if one of those calls fails the others keep running + run ${pkgs.dbus}/bin/dbus-send /KGlobalSettings org.kde.KGlobalSettings.notifyChange int32:$changeType int32:0 || echo "KGlobalSettings.notifyChange $changeType failed" + done + ''; + }; +} diff --git a/modules/modules.nix b/modules/modules.nix index 96b2bec56..154f2bd9c 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -34,6 +34,7 @@ let ./misc/numlock.nix ./misc/pam.nix ./misc/qt.nix + ./misc/qt/kconfig.nix ./misc/specialisation.nix ./misc/submodule-support.nix ./misc/tmpfiles.nix