Openocd - path arguments - how to?

Hi folks… Im new to nix, but find it cool, so i am trying to get me main machine ‘nix-ed’ and getting there i think, but i can’t realy get how i would do this …

this is from a Makefile
"
flash: build/MCU_mini_02.elf
~/tools/openocd/src/openocd
-s ~/tools/openocd/tcl/
-f ~/tools/openocd/tcl/board/st_nucleo_f4.cfg
-c “program build/MCU_mini_02.elf verify reset exit”
"

how do i ref these path arguments ,.
i can find the file here
‘/nix/store/xrqlql9sq6gxbiw2g41k46jsq0fk5jwl-openocd-0.11.0/share/openocd/scripts/board/st_nucleo_f4.cfg’ - but there are more needed…
and i don’t want to ref this in the Makefile

any hints ??
thanks…
/Finn

It looks to me as if the Makefile assumes a locally built openocd in ~/tools/openocd since the path to the binary still references the src folder. So there is going to be some modifications to the Makefile needed if you want to use the openocd coming from Nixpkgs. That being said, it’s usually not a good idea to put paths to /nix/store/... into the Makefile since these tend to change and will require updating. There is usually two ways you can go at this:

  1. You could install openocd into your system (adding it to environment.systemPackages). This will make the files available under /run/current-system/sw/share/openocd which could be put into the Makefile. I would not recommend this, though, because it requires everyone to install openocd into their system in case you want to share this project with others. However, it is possible and might work for you.

  2. You can create a devshell for your project. This is like a virtual environment that defines the whole build environment for the project and can be delivered with the project source code. The upside of this is that when sharing the project (maybe even on different machines of your own), you always have the whole development environment shared with it. There is a bit of (unfortunately not very good) documentation here: Development environment with nix-shell - NixOS Wiki to get you started. What you would do in your case is adding openocd to nativeBuildInputs. I would then recommend to add a line akin to OPENOCD_PATH="${pkgs.openocd}" to your mkShell definition which creates an environment variable OPENOCD_PATH that contains the /nix/store/... path for the OpenOCD package. In your Makefile, you can then reference this environment variable.
    This is also a good way to Make your project compatible with non-NixOS environments (if this is relevant for you). I usually check inside the Makefile if the OPENOCD_PATH is already defined and if not, I set it to some default value that works on “normal” Linux distributions.

I’d recommend to have a look into devShells, they are tremendously useful.

Thanks a lot… got it to work… very nice…

/Finn