Escape reserved pipe character

Hi!

I’m trying to adapt the .desktop file for KeePassXC with Home Manager:

    xdg.desktopEntries = {
      "org.keepassxc.KeePassXC" = {
        name = "KeePassXC";
        genericName = "Password Manager";
        exec = "secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passwörter.kdbx";
...

But when I run nixos-rebuild switch, I get the following error:

error: value "secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passw?rter.kdbx" for key "Exec" in group "Desktop Entry" contains a reserved character '|' outside of a quote

So I guess the pipe character (|) is the problem and I need to escape it. But how do I do that? I’m pretty lost here.

Thanks for your help in advance!

Desktop entries expect a program, optionally followed by arguments in the Exec key. It will typically be tokenized and then run by a something like a member of the exec() family functions.

If you want to use features of a shell, you will need to pass the commands to a shell, for example:

exec = ''
  sh -c "secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passwörter.kdbx"
'';

alternately, you can create a shell script (Nix derivation will be interpolated into a string as a path):

exec = "${pkgs.writeShellScript "kp-unlocked" ''
  secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passwörter.kdbx
''}";
4 Likes

Thank you for your ideas. Unfortunately both of them didn’t work for me :confused:

exec = "sh -c 'secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passwörter.kdbx'";

leads to →
error: value "sh -c 'secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passw?rter.kdbx'" for key "Exec" in group "Desktop Entry" contains a reserved character ''' outside of a quote

and

exec = pkgs.writeShellScript "keepassxc-unlocked" ''
          secret-tool lookup password keepassxc | keepassxc --pw-stdin /home/rob/Passwörter.kdbx
        '';

leads to →

error: A definition for option `home-manager.users.rob.xdg.desktopEntries."org.keepassxc.KeePassXC".exec' is not of type `null or string'. Definition values:
       - In `/etc/nixos/configuration.nix': <derivation keepassxc-unlocked>

What am I doing wrong?

Ah, sorry, my bad. Desktop files only support double quotes, and home-manager expects a string, not a derivation. I have updated the examples above to reflect, hopefully, the correct syntax.

1 Like

Thank you very much! The first solution you suggested is working for me :partying_face: