Looking for documentation on makeTargets within stdenv.mkDerivation

I am maintaining ryzen_monitor_ng.

The upstream repo committed binaries and .o files, so I need to clean them out before building the program.

make clean will remove the .o files, and I just have to manually remove the binary with rm src/ryzen_monitor. After those commands, make all builds the binary properly.

I was advised to use makeTargets in the PR. However, I have since found that makeTargets wasn’t doing anything. I can’t find any documentation on it. I see a number of packages in nixpkgs use makeTarget or makeTargets, but all the relevant uses of makeTarget in mkDerivation either only included targets that would have been built anyway by the first target in the makefile or didn’t need to run because the output was already in the repo.

I understand that makeTarget or makeTargets is being passed as an env var to the builder, but the default builder doesn’t use either variable, only makeFlags.

Am I using makeTarget wrong?

Indeed, it’s not a variable used by stdenv, and won’t do anything special. Demo gist.

Though, looking at stdenv documentation in nixpkgs, there are various *Target variables used by the stdenv phases.

It seems like the comment was mostly suggesting to avoid writing make clean; make explicitly.

Thanks, that confirms my research, and the link was helpful.

It seems like buildFlags = [ "clean" "all"] might be the right way to get the builder to run the appropriate targets.

I am surprised that nixos reviewers are recommending makeTarget though, it is clearly a no-op statement.

In this case, I recommend to use lib.cleanSource

2 Likes

Great, that is an even more elegant solution to my real problem.

1 Like

Turns out nixpkgs won’t build the package if you just do something like:

src = lib.cleanSource (fetchFromGitHub { ....

because nixpkgs doesnt allow “inputs from derivations”. It works for local builds if IFD is enabled.

1 Like