Nix program in a systemd unit (not on NixOS) gives error

I have a simple systemd unit on an Almalinux system (where Nix was installed using the determinate systemd installer):

[Unit]
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=1
User=myuser

ExecStart=/my/path/to/executable

When I run /my/path/to/executable with myuser, that works fine. However, when I start the systemd unit, it tells me:

Failed at step EXEC spawning /my/path/to/executable: Permission denied

The first line of the executable is:

#! /nix/store/q1c2flcykgr4wwg5a6h450hxbk4ch589-bash-5.2-p15/bin/bash -e

When I change the unit to be:

ExecStart=bash /my/path/to/executable

It works fine. What could be the cause here?

Is it marked executable?

chmod a+x /my/path/to/executable
2 Likes

If it isn’t the file permission then it smells a lot like an SELinux issue - which should log something to /var/log/audit/audit.log IIRC.

(sestatus must say enforcing, otherwise SELinux is deactivated and this is not the issue).