How to set the file extension of a derivation's $out?

I’m aware that the output of a derivation can be a regular file as opposed to a directory, and that some store paths in my Nix store have file extensions like .tgz. What do I have to do in the derivation function arguments to set a custom file extension for my own derivations?

Set name to a filename.

One semi-artificial restriction here is that you can’t name them with an ending of “.drv”

Unless it’s a fixed-output derivation with flat hashing (i.e. hashing the file contents only, not treating it as a NAR), I would always create a directory. Benefits:

  • can always add more files if needed
  • cp ${thing}/${name} bar/ produces bar/${name} without the hash part.