Setting up IRC bot service for Twitch on NixOS system

I’m trying to get an IRC bot working as a system service on NixOS but running into connection issues.

Here’s my current setup in /etc/nixos/configuration.nix:

services.lambdabot.enable = true;
services.lambdabot.script = "
rc /var/lib/lambdabot/.lambdabot/config.rc
irc-connect twitch irc.chat.twitch.tv 6667 StreamBot ChatHelper:_Always_Ready
admin + twitch:StreamUser
join twitch:#mychannel";

And in /var/lib/lambdabot/.lambdabot/config.rc:

irc-password oauth:abc123notarealtoken456def

After running these commands:

nixos-rebuild switch
chown lambdabot /var/lib/lambdabot/.lambdabot/config.rc
systemctl restart lambdabot

The process shows up in system monitor but the bot never joins the channel. When I start it manually from command line it works perfectly and responds to all commands. Has anyone successfully configured this as a proper system service? What am I missing in the service configuration?

It seems like the systemd service may lack the same network access that exists in your user session. I’ve faced a similar issue when configuring my Twitch bot on NixOS, where the service appeared to operate but experienced silent failures during network operations. To remedy this, you should add after = [ "network-online.target" ]; and wants = [ "network-online.target" ]; within your systemd service configuration. You can do this by modifying your configuration.nix with systemd.services.lambdabot.after = [ "network-online.target" ];. Additionally, confirm that your firewall settings are not obstructing outbound connections; the NixOS firewall can impose restrictions. Monitoring the journal logs using journalctl -u lambdabot -f will provide insights into connection attempts and any errors that may arise.

Had a similar headache with lambdabot service on NixOS a few months back. The issue was usually permissions and environment variables not being set properly for the systemd service. Check your systemctl status lambdabot output for any authentication errors first. Also verify that the lambdabot user can actually read the config file - the chown command you ran might not be enough if the directory permissions are wrong. Try setting the full directory path ownership recursively with chown -R lambdabot:lambdabot /var/lib/lambdabot. Another thing that caught me was that Twitch OAuth tokens expire, so make sure yours is still valid. The fact that manual execution works suggests the service environment is missing something the interactive shell provides.

Your lambdabot configuration looks mostly correct but there’s likely an issue with how the service handles the OAuth token format. When running as a systemd service, lambdabot sometimes has trouble parsing the oauth: prefix in the config file. Try moving the OAuth token directly into the main configuration instead of the separate config.rc file. You can add services.lambdabot.password = \"oauth:yourtokenhere\"; to your configuration.nix and remove the separate config file entirely. Also double check that your token has the correct scopes - Twitch requires chat:read and chat:edit permissions for basic bot functionality. The systemd environment strips many variables that might be available in your user session, so keeping everything in the main NixOS config tends to be more reliable than external files.

check if the systemd service is using the right working directory - nixos lambdabot service might be starting from a diferent path than when you run it manually. also twitch requires ssl nowadays so try changing port from 6667 to 6697 and add ssl connection parameter. had same issue last year and switching to secure connection fixed it completly