Using multiple versions of Terragrunt on NixOS

NixOS is great, but sometimes it makes common things more difficult. At least at first.

A great tool for switching Terragrunt versions is a program called tgswitch.

tgswitch is great. It will install the versions of Terragrunt that you need. So, you don’t need to install both Terragrunt and tgswitch. Just install tgswitch. It’s in nixpkgs.

The problem with tgswitch on NixOS is that tgswitch does things that NixOS doesn’t like, such as looking for binaries in /usr/bin and trying to write to readonly places.

What’s the command I need to run tgswitch on NixOS?

# definition
tgswitch --bin={absolute path to a writeable directory in your $PATH}/{binary name} {terragrunt version number}

# example
tgswitch --bin=/home/tom/.local/bin/terragrunt 0.37.2

In my example, I have a directory at /home/tom/.local/bin/ that is in my PATH. I am telling tgswitch to put a binary there called terragrunt (you could give it another name, but why would you?), and that this binary should be symlinked to terragrunt 0.37.2.

I hope that helps. Let me know if it did!