Add custom XDG mime type

Hi,

Recently I installed drawio using the drawio package, but the applications save some files, e.g. schemes.drawio and what I wanted to do is open the app through the xdg-open command.

The issue is the file’s mime type is text/plain, checked with xdg-mime query filetype, as such I wanted to create a new mime type for it. But I don’t know how to do it in NixOs.

I tried several things:

  1. adding a file to /run/current-system/sw/share/mime/application, but i get denied as there is no write permissions.
  2. use the xdg-mime install but that fails as “No writable system mimetype directory found.”

Do you guys know how to do this ?
Thank you for your time!

2 Likes

I found a way to do it locally with:

Which you can either create manually like in the script, or use home-manager to generate it:

  home.xdg.dataFile."mime/packages/drawio.xml".text = ''
    <?xml version="1.0" encoding="utf-8"?>
    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/vnd.jgraph.mxfile">
      <glob pattern="*.drawio"/>
        <comment>draw.io Diagram</comment>
      <icon name="x-office-document" />
    </mime-type>
    <mime-type type="application/vnd.visio">
      <glob pattern="*.vsdx"/>
        <comment>VSDX Document</comment>
      <icon name="x-office-document" />
    </mime-type>
    </mime-info>
  '';

I don’t know if you should run update-mime-database ~/.local/share/mime if you choose the second method, but if doesn’t work after the rebuild then give that a try.

One thing to note is that when I open a Test.drawio file, the program opens but I get an error:

ENOENT: no such file or directory, open 'file:///home/user/Documents/Test.drawio'

I don’t know if this is just me, but I couldn’t find any issues for this upstream.

1 Like

Thank you, the script worked perfectly. Weirdly enough, I didn’t get the error you were talking about.

Anyway thanks a lot for your answer!

1 Like

Must be something wrong on my end, then. Glad it worked for you, though.

1 Like