Using a custom version of terraform

I need to be able to install a more recent version of terraform using the following package:

How can I use there exposed terraform_1 (that uses a more modern version) via environment.systemPackages ?

I have tried

environment.systemPackages = with pkgs; [
  terraform.terraform_1
];

which gives the error: error: attribute 'terraform_1' missing,

What channel are you on?

I checked both, nixos-22.05 and nixos-unstable, both provide the terraform_1 attribute:

$ nix eval nixpkgs/nixos-22.05#terraform_1.name
"terraform-1.2.3"
$ nix eval nixpkgs/nixos-unstable#terraform_1.name
"terraform-1.2.9"

well i think unstable but questioning that now as I don’t get the same output as your eval commands?

vagrant@carverlinux ~/nixos (master) [1]> nix-channel --list
nixos https://nixos.org/channels/nixos-unstable
vagrant@carverlinux ~/nixos (master)> nix eval nixpkgs/nixos-22.05#terraform_1.name
error: getting status of '/home/vagrant/nixos/nixpkgs/nixos-22.05#terraform_1.name': No such file or directory
vagrant@carverlinux ~/nixos (master) [1]> nix eval nixpkgs/nixos-unstable#terraform_1.name
error: getting status of '/home/vagrant/nixos/nixpkgs/nixos-unstable#terraform_1.name': No such file or directory

What version of nix?

Also what version of nixpkgs exactly? Can you please run nix-instantiate --eval --expr '(import <nixos> {}).lib.version'?

1 Like

ahh interesting it’s:

“21.11.337975.eabc3821918”

better reread the upgrade guide I thought I had upgraded

sudo nix-channel --update should do (unless you use flakes, which I doubt after the output of nix eval above).

Though be careful then… If you used the 2.3 experimental CLI a lot, then the 2.10ish one will be completely different from what you are used to and also push you towards flakes quickly.

Enabling flakes will not disable channels, any you can use a channel based system configuration for the time being.

1 Like

I’ve had the same problem and fixed it using flakes:

First, search for the commit containing the version you want (https://github.com/search?q=repo%3ANixOS%2Fnixpkgs+terraform+"1.1.3"&type=commits)
In my case it was terraform: 1.1.2 -> 1.1.3 · NixOS/nixpkgs@3c0f090 · GitHub

Then register this in a separate registry:

nix registry add nixold github:NixOS/nixpkgs/3c0f090cacf5
c9acca53b3d1b361784853646a5a 

then use nix shell (for example) to use it:

nix shell nixold#terraform

terraform version
Terraform v1.1.3

Hope it helps!

1 Like