How do I create `.thumbnailer` files?

Hi

I’m trying to move to NixOS, but I have some issues with image previewing.

I want to add previews for .kra and .psd files in the file manager. On other distros I’d simply add the corresponding kra.thumbnailer file in /usr/share/thumbnailers/ but trying to do so in /run/current-system/sw/thumbnailers is not possible because it’s read-only.

What is the correct way to do it?

Is it done from the *.nix config files? I’m using home-manager.

You can just put them in ~/.local/share/thumbnailers

You might need to restart your file manager for them to take effect.

Thank you very much. I put it in that directory but it doesn’t seem to work.

Is this code correct? (I grabbed it from here):

[Thumbnailer Entry]
TryExec=unzip
Exec=sh -c "unzip -p \"%i\" preview.png > %o"
MimeType=application/x-krita;

I installed unzip and tested the script which seems to work fine by itself.

1 Like

Found a related issue here. You need to remove the quotes around the %i to make it work:

[Thumbnailer Entry]
TryExec=unzip
Exec=env sh -c "unzip -p %i preview.png > %o"
MimeType=application/x-krita;

I just tried this on my system and it works.

Also, instead of manually creating the file, you can let the system do it for you by using writeTextFile like the OP did in the github issue.

If you only want to create it for your user and not system-wide, you can use home-manager instead:

  home.file = {
    ".local/share/thumbnailers/kra.thumbnailer".text = ''
      [Thumbnailer Entry]
      TryExec=unzip
      Exec=sh -c "${pkgs.unzip}/bin/unzip -p %i preview.png > %o"
      MimeType=application/x-krita;
    '';
  };

Great, I used the home-manager script. But it’s not fully functional: when I search .kra in Nautilus, the previews appear normally, but not when I browse to a directory. Any idea on why that may be happening?

Weird. It fully works for me, both when searching and when browsing in Nautilus.

Can you post some screenshots? Also, I’m on NixOS-unstable, what version are you running?

Maybe your file manager is not trying to create a thumbnail because it already failed before you added the thumbnailer.

You could try removing the thumbnail cache, I think it’s at $HOME/.cache/thumbnail? I’m in the middle of nowhere right now and can’t check.

I created this wiki page before, if anyone could review it, I’d be grateful.

1 Like

Aha! That fixed it. Cool, everything works now, thanks! I wish I had found that wiki entry before.

Thanks @eljamm for your kind help : ) I’m on stable for now. But I might move to unstable soon. I need to get everything working first, though. Slowly getting there.

1 Like

Wish I’d found this sooner too :sweat_smile:. It nicely and clearly explains everything. Well done!

You definitely should take your time getting everything working first. I just thought it had something to do with an old version or something, that’s why I wanted to know. Glad that wasn’t the case, though.

Anyways, welcome to NixOS and I wish you the best :grin:

1 Like