We’re using an older version of Terraform than what’s present in nixpkgs-unstable, and I’ve been struggling to get an overlay with the version we want working in my non-flake shell. Using some of the typical methods like overrideAttrs
(example discussion) is not working and it seems like it has to do with a conflict in vendored modules. I believe this discussion highlights the same problem I’m running into (and links to a similar issue on GitHub):
It turns out that
overrideAttrs
andbuildGoModule
aren’t aware of each other, so the-go-modules
derivation there isn’t recomputed when I change the source.
After struggling with the above, I finally stumbled onto a much simpler method using mkTerraform
(definition, github issue):
{ pkgs ? import <nixpkgs> {}}:
with pkgs; mkShell {
name = "my-shell";
nativeBuildInputs = let
# https://github.com/NixOS/nixpkgs/blob/8530bee77a1db9ca592bf04acf16ca26df48b738/pkgs/applications/networking/cluster/terraform/default.nix#L171-L174
terraform_1_3_6 = mkTerraform {
version = "1.3.6";
hash = "sha256-aETsvcHoHSwqWCAdn9JPJLcX1Wi1umUghSjkq37OYDU=";
vendorHash = "sha256-fviukVGBkbxFs2fJpEp/tFMymXex7NRQdcGIIA9W88k=";
};
in
[
terraform_1_3_6
];
}
I have a few questions after all this:
- Is there a better way to get a specific version of Terraform in a shell?
- If you wanted to include terraform plugins in the build, how would you do that? I’ve seen examples of a
terraform.withPlugins( p: [ p.aws ... ])
helper, but I couldn’t seem to get that to work with my customterraform_1_3_6
. - In a flake-based world, how would you pull in specific versions of packages?
- Would it make sense to create an independent flake that packages the specific version of Terraform that you want?
- I’ve seen examples of adding multiple inputs that pin nix “channels” containing the package versions you want, but that seems like it could get hairy if you wanted to pin distinct versions of several different packages.