Escaping [ ] and \ in an attribute set

Hello,
I am trying to configure my KDE in home-manager.
Running flakes on 24.11.

I am having this clause to configure KDEs Klipper (clipboard tool)

  qt.kde.settings = {
    plasmashellrc = {
      "Action_0" = {
        Automatic = true;
        Description = "send link to phone";
        "Number of commands" = 1;
        Regexp = "https://.*";
      };
      "Action_0/Command_0" = {
        Commandline[$e] = "kdeconnect-handler %s\s";
        Description = "send link to kdeconnect";
        Enabled = true;
        Icon = "kdeconnect";
        Output = 0;
      };
    };
  };

But I am running into two problems with this line: Commandline[$e] = “kdeconnect-handler %s\s”;

the ][ brackets need to be escaped or quoted.
If I quote them I will get the hex ascii translation of their code.
I can’t manage to help it with escape chars like ‘’ or \

And there is the \s in the end, that I can’t get along with as well.

Some docs are to be found here: qt.kde.settings - MyNixOS

As I am writing I’ve just figured that I might need to build a working kwriteconfig command with those brackets first and apply the result to nix…
But I didnt get the kwriteconfig command off my hands… dunno where I would find that
edit:/ its in kdePackages.kconfig

I keep you posted, maybe someone has a solution in the meantime :confused:
thanks!

Whatever the problem is, it’s not the Nix language.

nix-repl> nix-repl> builtins.attrNames { "Commandline[$e]" = null; }
[ "Commandline[$e]" ]

So it’s something about how these attrsets are being used / processed.

1 Like

you are absolutely right.
Its KDEs fault, since the native way runs into the same problem.

kwriteconfig6 --file ~/.config/plasmashellrc --group “Action_0/Command_0” --key “Commandline[$e]” kdeconnect-handler" "%s;

thank you!

I guess i got this working…
previously i just found my changes doing:

  • git on .config/
  • do the change on the GUI
  • git diff to check what the GUI did
  • tried to apply those changes to my Nix…

so long story short, I was able to get around the ][ brackets and this slight mod works for me:

plasmashellrc = {
  "Action_0" = {
    Automatic = true;
    Description = "send link to phone";
    "Number of commands" = 1;
    Regexp = "https://.*";
  };
  "Action_0/Command_0" = {
    Commandline = "kdeconnect-handler %s"; # [$e] and \s removed - still works. dunno why GUI wants that
    Description = "send link to kdeconnect";
    Enabled = true;
    Icon = "kdeconnect";
    Output = 0;
  };