Diagnosing Common NixOS Systemd Service Failures: A Practical Guide
When a NixOS service refuses to start, the journal often points to ExecStart errors, permission issues, missing environment variables, or incorrect ServiceType settings. This guide walks through a step‑by‑step diagnostic flow, from status checks to declarative fixes, and tells you when to seek help.
01 Sept 2025, 02:44 UTC

Recognizable Symptom
A NixOS service that never starts and shows failed in systemctl status is a frequent pain point. Typical journal entries look like:
systemd[1]: Failed to start myservice.
systemd[1]: ExecStart=/run/current-system/sw/bin/myservice: No such file or directory
or:
systemd[1]: myservice.service: Failed with result 'exit-code'.
systemd[1]: myservice.service: Main process exited, code=exited, status=1
These lines hint at a mis‑configured unit file, missing binary, permission issue, or missing environment variable.
Cause & Diagnostic Table
| Potential Cause | Diagnostic Indicator |
|---|---|
Missing or incorrect ExecStart | Journal shows “No such file or directory” or non‑zero exit code. |
| File system permissions too restrictive | Journal logs “Permission denied” or “Operation not permitted”. |
| Required environment variables unset | Service crashes with a “undefined variable” error or similar stack trace. |
Wrong ServiceType for daemon | systemd reports “service dead” immediately after start. |
| RuntimeDir or socket missing / mis‑owned | Start fails with “No such file or directory” or “Permission denied” on socket paths. |
Ordered Checks & Fixes
- Verify service status and logs
# systemctl status myservice.service # journalctl -u myservice.serviceLook for the exact error message that matches one of the table entries.
- Validate unit syntax and attributes
# systemd-analyze verify /etc/systemd/system/myservice.serviceAny syntax error or unsupported option will be reported here.
- Check ExecStart path and permissions
# ls -l /run/current-system/sw/bin/myserviceEnsure the binary exists and is readable/executable by the service’s user. On NixOS, binaries live under the current system store; avoid manual permission changes – instead, set
runAsorserviceConfig.Userinconfiguration.nix. - Confirm required environment variables
# systemctl show -p Environment myservice.serviceIf a variable is missing, add it to the unit file or to
configuration.nix:services.myservice = { enable = true; environment = { MY_VAR = "value"; }; };After editing
configuration.nix, rebuild:# nixos-rebuild switch - Adjust ServiceType for forking daemons
Many daemons start a child and exit immediately. If
ServiceType=simpleis used, systemd will think the service died. Change toforkingornotifyas appropriate.ExecStart=/run/current-system/sw/bin/mydaemon ServiceType=forking - Verify RuntimeDir and socket ownership
# ls -ld /var/run/myservice # stat -c "%U %G" /var/run/myserviceRuntime directories should be owned by the service user. If missing, create and set ownership:
# mkdir -p /var/run/myservice # chown myservice:myservice /var/run/myserviceAgain, prefer declarative creation via
services.myservice.runtimeDir = "/var/run/myservice";inconfiguration.nix. - Re‑enable and restart the service
# systemctl daemon-reload # systemctl restart myservice.service # systemctl status myservice.serviceCheck that the status is now
active (running)and that no errors appear in the journal.
Escalation Criteria
- If the service still fails after all checks, verify that the binary itself is functional outside systemd: run it manually as the service user.
- Check for SELinux or AppArmor denials that may appear in
/var/log/audit/audit.logor/var/log/kern.log. - Consult the service’s upstream documentation for any additional runtime requirements (e.g., network sockets, external APIs).
- If the issue persists, consider opening an issue on the NixOS GitHub or seeking help in the NixOS IRC/Matrix channels with the exact error logs.
Practical Verification Checklist
# systemctl status myservice.service | grep -E 'active|failed'
# journalctl -u myservice.service --since '10 minutes ago'
# systemd-analyze verify /etc/systemd/system/myservice.service
# nixos-rebuild test # to see if changes would apply
Use nixos-rebuild test to preview the effect of configuration.nix changes without rebooting.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.