How do I specify a path to an executable for a systemd unit file on nix?












3















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
/run/current-system/sw/bin/mkdir









share|improve this question





























    3















    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
    /run/current-system/sw/bin/mkdir









    share|improve this question



























      3












      3








      3


      1






      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
      /run/current-system/sw/bin/mkdir









      share|improve this question
















      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
      /run/current-system/sw/bin/mkdir






      systemd environment-variables nixos mkdir nix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      GAD3R

      25.9k1751107




      25.9k1751107










      asked yesterday









      Chris StryczynskiChris Stryczynski

      559417




      559417






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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.






          share|improve this answer































            1














            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.






            share|improve this answer










            New contributor




            jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





















            • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

              – GAD3R
              yesterday






            • 1





              Yes, but there could be a symlink, in which case the /bin/mkdir could work.

              – jayooin
              yesterday






            • 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
              yesterday











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494762%2fhow-do-i-specify-a-path-to-an-executable-for-a-systemd-unit-file-on-nix%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            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.






            share|improve this answer




























              1














              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.






              share|improve this answer


























                1












                1








                1







                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 14 hours ago









                Emmanuel RosaEmmanuel Rosa

                3,0801612




                3,0801612

























                    1














                    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.






                    share|improve this answer










                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





















                    • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                      – GAD3R
                      yesterday






                    • 1





                      Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                      – jayooin
                      yesterday






                    • 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
                      yesterday
















                    1














                    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.






                    share|improve this answer










                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





















                    • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                      – GAD3R
                      yesterday






                    • 1





                      Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                      – jayooin
                      yesterday






                    • 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
                      yesterday














                    1












                    1








                    1







                    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.






                    share|improve this answer










                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.










                    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.







                    share|improve this answer










                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    share|improve this answer



                    share|improve this answer








                    edited yesterday





















                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered yesterday









                    jayooinjayooin

                    654




                    654




                    New contributor




                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    jayooin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.













                    • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                      – GAD3R
                      yesterday






                    • 1





                      Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                      – jayooin
                      yesterday






                    • 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
                      yesterday



















                    • Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                      – GAD3R
                      yesterday






                    • 1





                      Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                      – jayooin
                      yesterday






                    • 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
                      yesterday

















                    Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                    – GAD3R
                    yesterday





                    Welcome , mkdir is under /run/current-system/sw/bin/ as which command say.

                    – GAD3R
                    yesterday




                    1




                    1





                    Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                    – jayooin
                    yesterday





                    Yes, but there could be a symlink, in which case the /bin/mkdir could work.

                    – jayooin
                    yesterday




                    1




                    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
                    yesterday





                    @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
                    yesterday


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494762%2fhow-do-i-specify-a-path-to-an-executable-for-a-systemd-unit-file-on-nix%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Histoire des bourses de valeurs

                    Why is there Russian traffic in my log files?

                    Rename multiple files to decrement number in file name?