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

2 Answers 2


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, 2019 at 12:57
  • 1
    Yes, but there could be a symlink, in which case the /bin/mkdir could work.
    – jayooin
    Jan 16, 2019 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, 2019 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .