Skip to content

Commit

Permalink
Merge pull request #1003 from stackbuilders/add-nixpkgs-terraform
Browse files Browse the repository at this point in the history
feat: Add support languages.terraform.version
  • Loading branch information
domenkozar authored Mar 22, 2024
2 parents 984707a + de53655 commit f09752a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/terraform/.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -ex
terraform --version | grep "1.7.4"
8 changes: 8 additions & 0 deletions examples/terraform/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ pkgs, ... }:

{
languages.terraform = {
enable = true;
version = "1.7.4";
};
}
4 changes: 4 additions & 0 deletions examples/terraform/devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
allowUnfree: true
inputs:
nixpkgs-terraform:
url: github:stackbuilders/nixpkgs-terraform
20 changes: 20 additions & 0 deletions src/modules/languages/terraform.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

let
cfg = config.languages.terraform;

nixpkgs-terraform = config.lib.getInput {
name = "nixpkgs-terraform";
url = "github:stackbuilders/nixpkgs-terraform";
attribute = "languages.terraform.version";
};
in
{
options.languages.terraform = {
Expand All @@ -13,9 +19,23 @@ in
defaultText = lib.literalExpression "pkgs.terraform";
description = "The Terraform package to use.";
};

version = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The Terraform version to use.
This automatically sets the `languages.terraform.package` using [nixpkgs-terraform](https://github.com/stackbuilders/nixpkgs-terraform).
'';
example = "1.5.0 or 1.6.2";
};
};

config = lib.mkIf cfg.enable {
languages.terraform.package = lib.mkMerge [
(lib.mkIf (cfg.version != null) (nixpkgs-terraform.packages.${pkgs.stdenv.system}.${cfg.version} or (throw "Unsupported Terraform version, update the nixpkgs-terraform input or go to https://github.com/stackbuilders/nixpkgs-terraform/blob/main/versions.json for the full list of supported versions.")))
];

packages = with pkgs; [
cfg.package
terraform-ls
Expand Down

0 comments on commit f09752a

Please sign in to comment.