Cannot run lircd as a service - permission denied creationg PID and socket

I’m trying to auto-start lirc for use with Kodi. I think I figured out the proper Nix way to do this, but I’m getting an unexpected error. First, here’s my config:

  services.lirc.enable = true;
  services.lirc.configs = [
    (builtins.readFile ./files/mce-inteset.conf)
  ];
  services.lirc.options = ''
    [lircd]
    driver = default
    device = /dev/lirc0
    pidfile = /var/run/lircd.pid
    nodaemon = False
    immediate-init = True
  '';

Please check my syntax - I’m not 100% sure I did that correctly, but it seems to configure everything correctly.

Upon reboot I get a new lircd.socket service. However, when trying to use it I get this (via journalctl):

May 26 23:35:30 htpc systemd[1]: Starting LIRC daemon socket...
May 26 23:35:30 htpc systemd[1]: Listening on LIRC daemon socket.
May 26 23:36:29 htpc systemd[1]: lircd.socket: Failed with result 'service-start-limit-hit'

Upon investigating syslog I find this:

2024-05-26T23:51:21.544845-05:00 htpc lircd-0.10.2[2049]: Info: Initial device: /dev/lirc0
2024-05-26T23:51:21.544868-05:00 htpc lircd-0.10.2[2049]: Warning: Cannot access device: /dev/lirc0
<SNIP>
2024-05-26T23:51:21.545042-05:00 htpc lircd[2049]: can't open or create /var/run/lircd.pid: Permission denied

It does that repeatedly, which is probably what’s causing that systemd message.

So… why can’t it create the socket or PID file? I’m guessing the process must be starting up as a non-root user, but I don’t have anything like that defined. Maybe some built-in logic by whatever creates the nix service?

How can I override / fix that?

I worked around this for now by giving my kodi user sudo rights to run lircd and kicking it off via an autostart script on login. Gets the job done so I can start using it, but very interested in any suggestions to do this the “right” way.

maybe @ck3d knows something about this…
i see they have worked on this before

if we don’t hear anything back i think you should create an issue on github and ping the kodi team

Thanks for the mention. Definitely still interested in doing this without my workaround. Just to be clear, though, this is an issue with launching lircd as a service. Kodi is consuming it.

totally

but if you’re not using kodi why are you using lirc? :smile:

sure, i have used lirc for some interesting things unrelated to kodi many years ago, but i would suggest in the context of nixpkgs the kodi ecosystem is very relevant

i strive for an awesome htpc experience on nixos


on that note i will mention that if you want to step your kodi game up to the next level i can’t recommend flirc products enough, specifically the remote and dongle… light years ahead of what i have used in the past

lircd is not allowed to create lircd.pid in /var/run. You should remove this line. The default /var/run/lirc/lircd.pid is working fine.

1 Like

does flirc provide a way to power on a machine? I’m familiar with it, but from what I can tell they’ve never supported that capability. The closest I’ve seen is waking the PC up from sleep.

Thanks! I’m pretty sure there was a reason I had to change that path, but I can’t remember why now. Let me give that a shot and see how it works.

the device registers as a keyboard so if your bios supports power on from keyboard press then you’re good to go