How to package a kodi addon that writes new files in its directory?

Hi all, and hi @aanderse :wink:

I’m trying to package the home assistant kodi addon (HAKA), but since it tries to write files to the nix store at runtime, it raises a read-only filesystem error.

You can find the commit I was trying to submit as PR in my repository.

I used the command

NIX_PATH=nixpkgs=${PWD} nix-shell --pure -p "kodi.withPackages (kp: with kp; [home-assistant])"

and then run kodi from the shell.

The addon gets detected fine, and kodi asks to enable it.
I can configure it with my home assistant url and token without any problem.
When I launch it I got the following error

error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
    - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
    Error Type: <class 'OSError'>
    Error Contents: [Errno 30] Read-only file system: '/nix/store/v26056qcd4js4bddpkcbrp5fhfzcsysx-kodi-21.0-env/share/kodi/addons/script.program.homeassistant/hakaFavourites.yaml'
    Traceback (most recent call last):
    File "/nix/store/v26056qcd4js4bddpkcbrp5fhfzcsysx-kodi-21.0-env/share/kodi/addons/script.program.homeassistant/addon.py", line 391, in <module>
        open(fileHakaFavourites, 'w').close()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    OSError: [Errno 30] Read-only file system: '/nix/store/v26056qcd4js4bddpkcbrp5fhfzcsysx-kodi-21.0-env/share/kodi/addons/script.program.homeassistant/hakaFavourites.yaml'
    -->End of Python script error report<--

error <general>: GetDirectory - Error getting plugin://script.program.homeassistant/
error <general>: CGUIMediaWindow::GetDirectory(plugin://script.program.homeassistant/) failed

I’ve filed a bug report to solve this at the addon level (user files should be in the $HOME/.kodi/addon_data folder instead of alongside the addon installation files), but in the meantime, is there a way to make this work?

Or is it just a problem with nix-shell?

Thanks in advance for any help, much appreciated as always! :wink:

in your case the solution you proposed is pretty straight forward and i highly recommend you submit a PR to the project to resolve this


as an aside i’ll warn you specifically about many kodi skin addons… most of them intertwine dynamically (runtime) generated resources with static ones in a way that makes them impossible to package for a distribution package manager :sweat:

this is the only remaining obstacle between me and a fully declarative htpc setup! :sob:


thanks for your work lately :heart:

1 Like

A potentially workable hack if you know where there data is going to be written is to make a symlink in the store to some writeable directory elsewhere. As long as you can make sure that before the add on starts this directory is created (s.t. that the symlink becomes non-dangling) you can probably make this work. See this discussion in adventures in trying to make this work for another piece of software trying to write to the store:

PR submitted; however I’m not entirely sure to add this plugin to nixpkgs for various reason:

  • the developer admitted the addon is not actively maintained
  • the developer doesn’t even use it anymore
  • the code quality is very low, I started to do some refactoring, but…
  • …since I have to use my smartphone to control kodi (via kore), I just use the home assistant companion app in it, that lets me see my custom dashboards.

kodi addons often don’t require updates for years on end, so i wouldn’t call that a deal breaker

if that was a requirement we wouldn’t have packaged over 95% of the existing kodi addons… :melting_face:

purchase one of these and these to dramatically increase the quality of your life :laughing:

i don’t work for that company or anything but they’ve made my htpc dreams come true so i’m happy to give shout outs to them any time the opportunity arises - truly a game changer in the htpc world

1 Like

Let’s say that is the combination of the two things that is a blocker: some things are already broken, and the code is a mess, so a simple fix for the maintainer becomes days of refactoring for a “code nazi”/ borderline OCD like me :sweat_smile:

I would rather invest the time to make the web browser addon a reality and just load home asisstant web page with that :wink:

Oh, the good old days of DIY IR receivers on the serial port of a Pentium III are long gone!

Is there a mind controlled remote also? That would be my ideal kind of remote :rofl:

Jokes aside, it is indeed a really nice product!

1 Like