Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot produce backslash (\) in configuration key #163

Open
PhilippWoelfel opened this issue May 5, 2024 · 8 comments
Open

Cannot produce backslash (\) in configuration key #163

PhilippWoelfel opened this issue May 5, 2024 · 8 comments

Comments

@PhilippWoelfel
Copy link

PhilippWoelfel commented May 5, 2024

There is no obvious way of creating a single backslash in the configuration key of a kde configuration file anymore. This was possible until recently but is now broken - probably since #156 (@quentinmit)

For example, syncthingtray uses backslashes in its configuration. E.g., the file syncthingtray.ini has entries like so:

[tray]
connection\1\label=localhost
...

Previously, this could be created with

programs.plasma.configFile."syncthingtray.ini".tray."connections\\1\\label".value = "localhost";

Now this is not possible anymore. For example:

  • a single backslash removes the backslash, i.e., ...\1... produces ...1....
  • two backslashes create two backslashes, i.e., ...\\1... produces ...\\1....

There is no obvious way of creating a single backslash.

@quentinmit
Copy link
Contributor

quentinmit commented May 7, 2024

The syncthingtray.ini you pasted there is an invalid KDE config file. Keys are escaped, so if you want a literal backslash in the key the config file needs to contain \\. See https://github.com/KDE/kconfig/blob/44f98ff5cb9008436ba5ba385cae03bbd0ab33e6/src/core/kconfigini.cpp#L940 - KDE's config parser will say "Invalid escape sequence" if it parses your file.

It sounds like maybe this isn't a KDE config file, but just happens to have a similar-ish syntax? I don't think programs.plasma.configFile should be trying to support this; you can use xdg.configFile to write an arbitrary file in ~/.config, probably with lib.generators.toINI to generate the contents.

If you want to test this, use kreadconfig5:

kreadconfig5 --file syncthingtray.ini --group tray --key 'connection\1\label'

I think you'll find that it correctly reads the key with a config file generated by the current plasma-manager, and spits out a bunch of "Invalid escape sequence" errors when it tries to read your sample config file.

@PhilippWoelfel
Copy link
Author

Ok, I understand. I guess, this strictly limits the scope to KDE config files, and excludes applications. Maybe a somewhat wider scope would be nice, so that users don't have to implement functionality that already exists in this project, specifically for only updating keys without overwriting the entire file.

From a user perspective (ignoring the effort it would take to implement), maybe it would be useful to allow the creation of any key values in the config file, possibly with warnings if the result does not match the KDE config file specification. Or is it perhaps the case (and/or the goal) that anything a user can create must be a valid KDE configuration file?

@quentinmit
Copy link
Contributor

Ok, I understand. I guess, this strictly limits the scope to KDE config files, and excludes applications. Maybe a somewhat wider scope would be nice, so that users don't have to implement functionality that already exists in this project, specifically for only updating keys without overwriting the entire file.

There are plenty of applications that use KDE config files and are supported by this module. It just sounds like syncthingtray isn't one of them.

From a user perspective (ignoring the effort it would take to implement), maybe it would be useful to allow the creation of any key values in the config file, possibly with warnings if the result does not match the KDE config file specification. Or is it perhaps the case (and/or the goal) that anything a user can create must be a valid KDE configuration file?

There are tons of different config file formats; it's just a coincidence that the KDE config file format is similar to the standard INI format. If you wanted "to allow the creation of any key values", you would need to support YAML config files, and TOML config files, and sqlite databases, and all the application-specific formats too. This module is designed to support only one config file format, kconfig. I don't think it makes sense to build a generic "mutate this config file in an arbitrary way" feature into plasma-manager.

@PhilippWoelfel
Copy link
Author

Ok, I thought there might be a reasonable superset of the currently allowed syntax, but perhaps there isn't.
Related to this: changing power settings (e.g., suspend-to-ram) creates entries in powerdevilrc like so:

[AC][SuspendAndShutdown]
AutoSuspendAction=0

Is this valid KDE config file syntax, and if so, can it be produced with programs.plasma.configFile somehow?

@quentinmit
Copy link
Contributor

Yes, that's valid KDE config file syntax (and invalid INI syntax). I believe under the current plasma-manager syntax it's

programs.plasma.configFile.powerdevilrc."AC/SuspendAndShutdown".AutoSuspendAction = 0;

@magnouvean
Copy link
Collaborator

We could maybe add an option down the line preventing plasma-style escapes for individual keys (which could be enabled manually), though it won't be an immediate priority unless someone makes a pr.

@quentinmit
Copy link
Contributor

We could maybe add an option down the line preventing plasma-style escapes for individual keys (which could be enabled manually), though it won't be an immediate priority unless someone makes a pr.

The problem is not writing individual keys, the problem is that the resulting (or perhaps starting) file is already not a valid KDE config file, so you can't parse it correctly to add in the new keys. This would cause problems even if the invalid key is not even mentioned in the Nix config.

@magnouvean
Copy link
Collaborator

I guess if we would add such an option that it would be toggled manually for non-kde config-files. Configuring non-kde config-files is somewhat out of scope of this project though (though I will admit I use plasma-manager for a couple non-kde programs as well). Home-manager is the more natural choice for such functionality, but may not work on files which need to be mutable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants