Edit configuration.nix using Kate

Hi! newbie #65536 here, I want to use Kate to edit my NixOS config, but I’m unable to do so because ktexteditor seems to be “incomplete”?

Normally in other distros it’d ask for my password when saving the file if it doesn’t have permissions to do so. That does not happen here though, a really generic error pops up and prints the following into the terminal (after enabling some QDebug flags)

kf.auth: Encountered error while checking action status, error code: PolkitQt1::Authority::E_CheckFailed "GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Action org.kde.ktexteditor.katetextbuffer.savefile is not registered"

Which it’s true! There’s no org.kde.ktexteditor.katetextbuffer.policy inside of /run/current-system/sw/share/polkit-1/actions/ (which I think it’s the correct place), and I think that’s supposed to be included with the ktexteditor package (based on the file list from the arch repos)

I already have polkit enabled, sooo… am I missing something? Thanks! :smiley:

PS: I know about sudoedit, but that doesn’t seem to save the file until I close Kate, which I sometimes forget to do + it’s kinda annoying :stuck_out_tongue:

I don’t use kde / ktexteditor, but I was bored so I had a look. If you build the derivation you get the following:

nix-repl> :b pkgs.libsForQt5.ktexteditor

This derivation produced the following outputs:
  bin -> /nix/store/j37kd4y776g52bsx3ppfjiflz5ia68rh-ktexteditor-5.107.0-bin
  dev -> /nix/store/44pv25yizzzad458f0m61lcca6y22652-ktexteditor-5.107.0-dev
  out -> /nix/store/dinvy8fk9h1lpcknpvlkvxbwr74vsyqz-ktexteditor-5.107.0

If you look at the bin derivation you’ll find

❯ ls /nix/store/j37kd4y776g52bsx3ppfjiflz5ia68rh-ktexteditor-5.107.0-bin/share/polkit-1/actions/org.kde.ktexteditor.katetextbuffer.policy
/nix/store/j37kd4y776g52bsx3ppfjiflz5ia68rh-ktexteditor-5.107.0-bin/share/polkit-1/actions/org.kde.ktexteditor.katetextbuffer.policy

If you enable polkit these are automatically linked. See: https://github.com/NixOS/nixpkgs/blob/66bda599f409f9834c6fd6abc602e452a5c16b61/nixos/modules/security/polkit.nix#L73

So I am assuming that you 1. must install the .bin package and 2. you must enable polkit (security.polkit.enable = true;), and if both of these things have happened then auth hand off will work. That said I haven’t tried any of this because I don’t run any of that. Hopefully if this doesn’t get it working for you it at least points you in the right direction.

3 Likes

Yes! That worked! It took me a while to realize that I was adding the package to my user instead of environment.systemPackages :p, but when I did it correctly it worked without even rebooting

Thank you!! :smile:

1 Like

I’m encountering the same problem. I’ve added kdePackages.ktexteditor (which I think is the kde6 location of the package?) and kate to my environment.systemPackages and I’ve set security.polkit.enable = true; but this did not solve the problem.
I’ve only installed NixOS for the first time 2 days ago so I could very well be missing something easy, what am I missing?

The same command that @bme ran now produces

This derivation produced the following outputs:
  debug -> /nix/store/xlc8x36p0897ilqvgn54jh81qpggg8gl-ktexteditor-6.0.0-debug
  dev -> /nix/store/fqa4r091c6lfkyrmrkjs6bhwzbn9wm44-ktexteditor-6.0.0-dev
  out -> /nix/store/w7q7gj9flrci1skgpfcyqf470kx358rc-ktexteditor-6.0.0

With the out package containing the necessary file

It seems to be working for me, maybe you’re still using the Qt5 version of Kate, the Qt6 version seems to be available only under kdePackages.kate, not sure why they didn’t replace the old one

That was exactly what was happening. Replacing kate with kdePackages.kate fixed the problem. Thank you so much for your help!

For any future readers, the exact changes needed for plasma 6 are:

security.polkit.enable = true;
environment.systemPackages = with pkgs; [
   kdePackages.ktexteditor
   kdePackages.kate
  ];
1 Like

As a newcomer I didn’t understand the solution as posted by @bme so to any future readers with plasma 5, you need this in your configuration.nix:

security.polkit.enable = true;
environment.systemPackages = with pkgs; [
	libsForQt5.ktexteditor
	kate
  ];