Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,16 @@ use nix

### Terraform

- `terraform-format`: built-in formatter (using [OpenTofu](https://opentofu.org/)'s [`fmt`](https://opentofu.org/docs/cli/commands/fmt/))
- `terraform-validate`: built-in validator (using [OpenTofu](https://opentofu.org/)'s [`validate`](https://opentofu.org/docs/cli/commands/validate/))
- `terraform-format`: built-in formatter (using
[OpenTofu](https://opentofu.org/)'s
[`fmt`](https://opentofu.org/docs/cli/commands/fmt/) or
[Terraform](https://developer.hashicorp.com/terraform)'s
[`fmt`](https://developer.hashicorp.com/terraform/cli/commands/fmt))
- `terraform-validate`: built-in validator (using
[OpenTofu](https://opentofu.org/)'s
[`validate`](https://opentofu.org/docs/cli/commands/validate/)
[Terraform](https://developer.hashicorp.com/terraform)'s
[`validate`](https://developer.hashicorp.com/terraform/cli/commands/validate))
- [tflint](https://github.com/terraform-linters/tflint)

### TOML
Expand Down
20 changes: 18 additions & 2 deletions modules/hooks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4126,8 +4126,24 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm
{
name = "terraform-validate";
description = "Validates terraform configuration files (`.tf`).";
package = tools.terraform-validate;
entry = "${hooks.terraform-validate.package}/bin/terraform-validate";
package = tools.opentofu;
entry =
let
terraform-validate = pkgs.writeScriptBin "terraform-validate" ''
#!/usr/bin/env bash
set -x
for arg in "$@"; do
dirname "$arg"
done \
| sort \
| uniq \
| while read dir; do
${lib.getExe hooks.terraform-validate.package} -chdir="$dir" init
${lib.getExe hooks.terraform-validate.package} -chdir="$dir" validate
done
'';
in
"${terraform-validate}/bin/terraform-validate";
files = "\\.(tf(vars)?|terraform\\.lock\\.hcl)$";
excludes = [ "\\.terraform/.*$" ];
require_serial = true;
Expand Down
14 changes: 0 additions & 14 deletions nix/terraform-validate/default.nix

This file was deleted.

3 changes: 2 additions & 1 deletion nix/tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
, stylua
, tagref
, taplo
, terraform
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to then be exported from the tools. I would double-check that it doesn't break eval for pkgs without unfree when not using the hook.

Copy link
Author

@veselyn veselyn Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example that works with OpenTofu and allowUnfree: false: https://github.com/veselyn/git-hooks.nix/tree/terraform-validate-package-test/test. Also no issues with evaluation with the hook disabled.

, texlive
, # Added in nixpkgs on Dec 2, 2022
topiary ? placeholder "topiary"
Expand Down Expand Up @@ -182,6 +183,7 @@ in
stylua
tagref
taplo
terraform
topiary
treefmt
trufflehog
Expand Down Expand Up @@ -232,7 +234,6 @@ in
cabal2nix-dir = callPackage ./cabal2nix-dir { };
hpack-dir = callPackage ./hpack-dir { };
hunspell = callPackage ./hunspell { };
terraform-validate = callPackage ./terraform-validate { };
tflint = callPackage ./tflint { };
dune-build-opam-files = callPackage ./dune-build-opam-files {
dune = dune_3;
Expand Down