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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
matrix:
runner:
- { system: aarch64-darwin, os: macos-latest }
- { system: x86_64-darwin, os: macos-15-intel }
- { system: x86_64-linux, os: ubuntu-latest }
fail-fast: false
needs: [check]
Expand Down Expand Up @@ -66,6 +65,7 @@ jobs:
# - devenv
- nixpkgs-terraform-providers-bin
- terranix
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v7
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ nixConfig = {
Currently, the binary cache supports the following systems:

- aarch64-darwin
- x86_64-darwin
- x86_64-linux

> [!WARNING]
> `x86_64-darwin` is no longer supported because nixpkgs 26.11 dropped it.
Comment on lines +85 to +86

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion (non-blocking): Move the breaking changes where users will see them

This warning sits under the binary cache section, but x86_64-darwin packages are gone entirely, not just uncached. Could we move it next to the allowUnfree note at the top, point Intel Mac users to v5.24.0 (the last release that provides it), and add a line that withPlugins on Terraform >= 1.9 now needs fully qualified names such as p.hashicorp_aws?


## Quick Start (without a flake)

You can use `nix shell` or `nix run` to quickly access Terraform without creating
Expand Down
24 changes: 4 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
nixpkgs-24_05.url = "github:nixos/nixpkgs/nixos-24.05-small";
# INFO: Channel used for building versions from 1.9 onwards
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";

@sestrella sestrella Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@CristhianMotoche I would recommend leaving this input or changing it to one that drops x86_64-darwin support. That way, consumers could customize the systems from their flakes:

inputs = {
  systems.url = "github:nix-systems/default-darwin";
  nixpkgs-terraform = {
    url = "github:stackbuilders/nixpkgs-terraform";
    inputs.systems.follows = "systems";
  };
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1. nix-systems/default already dropped x86_64-darwin; our lock is just pinned to 2023. Keeping the input and running nix flake update systems gives the same three systems without breaking overrides. Note that default-darwin still includes x86_64-darwin.

};

outputs =
{ self
, nixpkgs
, systems
, ...
}@inputs:
let
forAllSystems = nixpkgs.lib.genAttrs (import systems);
# INFO: x86_64-darwin is not supported since nixpkgs 26.11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@CristhianMotoche I strongly suggest releasing this as a major change. If I recall correctly, the release process is automated on this project via semantic-release; therefore, adding the words BREAKING CHANGE: to the commit message should bump the major version.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed. The last two commits already have BREAKING CHANGE: footers, so this releases as a major as long as they stay in the squash commit message when merging.

forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];

terraformVersions = builtins.fromJSON (builtins.readFile ./versions.json);

Expand Down
9 changes: 8 additions & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@
inherit system;
config.allowUnfree = false;
};

# nixpkgs-unstable no longer provides mkTerraform, so use a vendored copy
mkTerraform =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question (non-blocking): Did you consider pinning nixos-26.05 for >= 1.9?

Like the existing 23.05 and 24.05 pins: at its current head it ships Go 1.26.10, still has mkTerraform, keeps the short provider names, and still evaluates for x86_64-darwin, so this could have landed as a plain fix: without vendoring. The catch is that 26.05 leaves support at the end of December, so we'd be back here in about two months. I'm fine with going straight to unstable; I just want to make sure it was a deliberate choice.

if builtins.compareVersions version "1.9.0" >= 0 then
(pkgs.callPackage ./terraform.nix { }).mkTerraform
else
pkgs.mkTerraform;
in

pkgs.lib.warnIf (builtins.compareVersions version "1.6.0" >= 0)
"allowUnfree is enabled to build version ${version}"
pkgs.mkTerraform
mkTerraform
{
inherit version hash vendorHash;
patches =
Expand Down
195 changes: 195 additions & 0 deletions lib/terraform.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Vendored from nixpkgs (pkgs/applications/networking/cluster/terraform/default.nix)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

praise: The source note makes the vendored copy easy to verify

I diffed this against nixpkgs at d276d665, and the only differences are the removed terraform_1, plugin test and plugins binding, plus their now-unused inputs.

# at d276d665e1c8414e4908c130d648f9bb122e3776, before `mkTerraform` was removed
# upstream in NixOS/nixpkgs@88b583f9e2.
Comment on lines +1 to +3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion (non-blocking): Keep the nixpkgs MIT notice on the vendored file

Since this file is copied from nixpkgs, its license notice should travel with it. Both projects are MIT, so it's only about carrying the notice.

Suggested change
# Vendored from nixpkgs (pkgs/applications/networking/cluster/terraform/default.nix)
# at d276d665e1c8414e4908c130d648f9bb122e3776, before `mkTerraform` was removed
# upstream in NixOS/nixpkgs@88b583f9e2.
# Vendored from nixpkgs (pkgs/applications/networking/cluster/terraform/default.nix)
# at d276d665e1c8414e4908c130d648f9bb122e3776, before `mkTerraform` was removed
# upstream in NixOS/nixpkgs@88b583f9e2.
# Copyright (c) 2003-2026 Eelco Dolstra and the Nixpkgs/NixOS contributors, MIT License.

{ stdenv
, lib
, buildGoModule
, fetchFromGitHub
, makeWrapper
, coreutils
, runtimeShell
, installShellFiles
,
}:

let
generic =
{ version
, hash
, vendorHash ? null
, ...
}@attrs:
let
attrs' = removeAttrs attrs [
"version"
"hash"
"vendorHash"
];
in
buildGoModule (
{
pname = "terraform";
inherit version vendorHash;

src = fetchFromGitHub {
owner = "hashicorp";
repo = "terraform";
rev = "v${version}";
inherit hash;
};

# Set CGO_ENABLED based on platform:
# - Linux: CGO_ENABLED=0 for static linking (avoids LTO plugin issues)
# - Darwin: CGO_ENABLED=1 to avoid DNS resolution issues
# See: https://github.com/hashicorp/terraform/blob/main/BUILDING.md
env.CGO_ENABLED = if stdenv.hostPlatform.isDarwin then "1" else "0";

ldflags = [
"-s"
"-w"
"-X 'github.com/hashicorp/terraform/version.dev=no'"
];

postPatch = ''
# Between go 1.23 and 1.24 the following GODEBUG setting was removed, and a new
# similar one was added.
# https://github.com/golang/go/issues/72111
# The setting is configured upstream due to the following timeouts caused by
# the TLS handshake using post-quantum crypto with servers that don't support it
# https://tldr.fail/
substituteInPlace go.mod \
--replace-quiet 'godebug tlskyber=0' 'godebug tlsmlkem=0'
'';
postConfigure = ''
# speakeasy hardcodes /bin/stty https://github.com/bgentry/speakeasy/issues/22
substituteInPlace vendor/github.com/bgentry/speakeasy/speakeasy_unix.go \
--replace-fail "/bin/stty" "${coreutils}/bin/stty"
'';

nativeBuildInputs = [ installShellFiles ];

postInstall = ''
# https://github.com/posener/complete/blob/9a4745ac49b29530e07dc2581745a218b646b7a3/cmd/install/bash.go#L8
installShellCompletion --bash --name terraform <(echo complete -C terraform terraform)
'';

preCheck = ''
export HOME=$TMPDIR
export TF_SKIP_REMOTE_TESTS=1
'';

subPackages = [ "." ];

meta = {
description = "Tool for building, changing, and versioning infrastructure";
homepage = "https://www.terraform.io/";
changelog = "https://github.com/hashicorp/terraform/blob/v${version}/CHANGELOG.md";
license = lib.licenses.bsl11;
maintainers = with lib.maintainers; [
Chili-Man
kalbasit
timstott
zimbatm
zowoq
techknowlogick
qjoly
];
mainProgram = "terraform";
};
}
// attrs'
);

pluggable =
terraform:
let
withPlugins =
plugins:
let
actualPlugins = plugins terraform.plugins;

# Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
wrapperInputs = lib.unique (
lib.flatten (lib.catAttrs "propagatedBuildInputs" (builtins.filter (x: x != null) actualPlugins))
);

passthru = {
withPlugins = newplugins: withPlugins (x: newplugins x ++ actualPlugins);
full = withPlugins (p: lib.filter lib.isDerivation (lib.attrValues p.actualProviders));

# Expose wrappers around the override* functions of the terraform
# derivation.
#
# Note that this does not behave as anyone would expect if plugins
# are specified. The overrides are not on the user-visible wrapper
# derivation but instead on the function application that eventually
# generates the wrapper. This means:
#
# 1. When using overrideAttrs, only `passthru` attributes will
# become visible on the wrapper derivation. Other overrides that
# modify the derivation *may* still have an effect, but it can be
# difficult to follow.
#
# 2. Other overrides may work if they modify the terraform
# derivation, or they may have no effect, depending on what
# exactly is being changed.
#
# 3. Specifying overrides on the wrapper is unsupported.
#
# See nixpkgs#158620 for details.
overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins;
overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins;
override = x: (pluggable (terraform.override x)).withPlugins plugins;
};
in
# Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
# of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
if actualPlugins == [ ] then
terraform.overrideAttrs
(orig: {
passthru = orig.passthru // passthru;
})
else
lib.appendToName "with-plugins" (
stdenv.mkDerivation {
inherit (terraform) meta pname version;
nativeBuildInputs = [ makeWrapper ];

# Expose the passthru set with the override functions
# defined above, as well as any passthru values already
# set on `terraform` at this point (relevant in case a
# user overrides attributes).
passthru = terraform.passthru // passthru;

buildCommand = ''
# Create wrappers for terraform plugins because Terraform only
# walks inside of a tree of files.
for providerDir in ${toString actualPlugins}
do
for file in $(find $providerDir/libexec/terraform-providers -type f)
do
relFile=''${file#$providerDir/}
mkdir -p $out/$(dirname $relFile)
cat <<WRAPPER > $out/$relFile
#!${runtimeShell}
exec "$file" "$@"
WRAPPER
chmod +x $out/$relFile
done
done

# Create a wrapper for terraform to point it to the plugins dir.
mkdir -p $out/bin/
makeWrapper "${terraform}/bin/terraform" "$out/bin/terraform" \
--set NIX_TERRAFORM_PLUGIN_DIR $out/libexec/terraform-providers \
--prefix PATH : "${lib.makeBinPath wrapperInputs}"
'';
}
);
in
withPlugins (_: [ ]);
in
{
# Constructor for other terraform versions
mkTerraform = attrs: pluggable (generic attrs);
}
4 changes: 2 additions & 2 deletions templates/nixpkgs-terraform-providers-bin/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
default = pkgs.mkShell {
buildInputs = [
(terraform.withPlugins (p: [
p.null
p.random
p.hashicorp_null
p.hashicorp_random
terraform-providers-bin.providers.hashicorp.nomad
]))
];
Expand Down
Loading