I'm trying to write a systemd unit file.

How do I specify the path to an executable? How can I determine what to use?

In this specific case I'm trying to use mkdir.

ExecStartPre = "/bin/mkdir -p %h/.config/example/pending/";

This results in a error when starting the unit file though:

Jan 16 08:46:11 nixos systemd[19577]: example.service: Failed at step EXEC spawning /bin/mkdir: No such file or directory

I suppose I could just use which to find the path to mkdir - but I'm seeing a ${pkgs.nameOfPackage} in other's nix's config - so possibly I should be using this instead?

which mkdir

Generally speaking, ${pkgs.nameOfPackage} is the preferred syntax.

For your specific examplem mkdir is part of the coreutils package; which (pun intended) you can determine with the command readlink $(which mkdir). So your line should read:

ExecStartPre=${pkgs.coreutils}/bin/mkdir BLAH BLAH BLAH

While coreutils is always installed AFIK, a nice benefit of the ${pkgs.nameOfPackage} syntax is that you don't need to install the package nameOfPackage; Nix will pull it in for you.


First you don't need those spaces and double quotes.

ExecStartPre=/run/current-system/sw/bin/mkdir -p %h/.config/example/pending

Secondly, have you tried the command on your system as it is written ? In your shell:

mkdir -p ~/.config/example/pending

Lastly, %h refers to the user's home. But maybe your system is targeting to another place, since the mkdir command isn't in the right place. echo ~ to see your home directory.

  • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say. – GAD3R Jan 16 at 12:57
  • 1
    Yes, but there could be a symlink, in which case the /bin/mkdir could work. – jayooin Jan 16 at 13:01
  • 1
    @GAD3R mkdir is found first in the OP's $PATH in /run/current-system/sw/bin/ but that doesn't tell us much about where systemd should look. – icarus Jan 16 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.