From 8939196547b06b055255ed000fb0c26e49913ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Estrella?= <2049686+sestrella@users.noreply.github.com> Date: Wed, 7 Aug 2024 09:42:29 -0500 Subject: [PATCH] feat: Initial support for Terraform 1.9 versions (#83) --- .github/workflows/build.yml | 4 +-- flake.lock | 59 +++++++++++++++++++-------------- flake.nix | 22 ++++++++---- lib/build-terraform.nix | 16 ++++++--- lib/releases.nix | 4 +-- patches/provider-path-1_9.patch | 23 +++++++++++++ versions.json | 15 ++++++++- 7 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 patches/provider-path-1_9.patch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3dd6f24..690d9fc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,10 +52,10 @@ jobs: run: | if grep -q authToken ~/.config/cachix/cachix.dhall; then echo "Cachix token is present" - cachix watch-exec nixpkgs-terraform nix -- flake check + cachix watch-exec nixpkgs-terraform nix -- flake check --max-jobs 2 else echo "Cachix token is not present" - nix flake check + nix flake check --max-jobs 2 fi template: diff --git a/flake.lock b/flake.lock index 252c5df..0de5eba 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "config": { "locked": { "dir": "templates/config", - "lastModified": 1715288913, - "narHash": "sha256-NQhxnFCAUj4x5t878Gpzb6xlRpr1V7bm5AEoqCVaJbk=", + "lastModified": 1719931926, + "narHash": "sha256-B8j9lHX0LqWlZkm8JxZRN6919RQjJEu/1J1SR8pU/ww=", "owner": "stackbuilders", "repo": "nixpkgs-terraform", - "rev": "4f09d5af5c1782414ff27caab6f3abd84e516ded", + "rev": "034287ee462c87dadc14a94d4b53a48ed66c7b3d", "type": "github" }, "original": { @@ -22,11 +22,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1706830856, - "narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=", + "lastModified": 1722555600, + "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f", + "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", "type": "github" }, "original": { @@ -35,7 +35,7 @@ "type": "github" } }, - "nixpkgs": { + "nixpkgs-1_0": { "locked": { "lastModified": 1699291058, "narHash": "sha256-5ggduoaAMPHUy4riL+OrlAZE14Kh7JWX4oLEs22ZqfU=", @@ -46,51 +46,62 @@ }, "original": { "owner": "nixos", - "ref": "nixos-23.05", "repo": "nixpkgs", + "rev": "41de143fda10e33be0f47eab2bfe08a50f234267", "type": "github" } }, - "nixpkgs-lib": { + "nixpkgs-1_6": { "locked": { - "dir": "lib", - "lastModified": 1706550542, - "narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=", - "owner": "NixOS", + "lastModified": 1712757991, + "narHash": "sha256-kR7C7Fqt3JP40h0mzmSZeWI5pk1iwqj4CSeGjnUbVHc=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "97b17f32362e475016f942bbdfda4a4a72a8a652", + "rev": "d6b3ddd253c578a7ab98f8011e59990f21dc3932", "type": "github" }, "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", + "owner": "nixos", "repo": "nixpkgs", + "rev": "d6b3ddd253c578a7ab98f8011e59990f21dc3932", "type": "github" } }, - "nixpkgs-unstable": { + "nixpkgs-1_9": { "locked": { - "lastModified": 1712757991, - "narHash": "sha256-kR7C7Fqt3JP40h0mzmSZeWI5pk1iwqj4CSeGjnUbVHc=", + "lastModified": 1721883900, + "narHash": "sha256-kTpK/TdIkQwtPZe1NjCF6nY0S21A7QiNjXju9rHdcrg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d6b3ddd253c578a7ab98f8011e59990f21dc3932", + "rev": "f5fd8730397b9951d24de58f51a5e9cb327e2a85", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixpkgs-unstable", "repo": "nixpkgs", + "rev": "f5fd8730397b9951d24de58f51a5e9cb327e2a85", "type": "github" } }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1722555339, + "narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + } + }, "root": { "inputs": { "config": "config", "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs", - "nixpkgs-unstable": "nixpkgs-unstable", + "nixpkgs-1_0": "nixpkgs-1_0", + "nixpkgs-1_6": "nixpkgs-1_6", + "nixpkgs-1_9": "nixpkgs-1_9", "systems": "systems" } }, diff --git a/flake.nix b/flake.nix index 5407730..d03fa0b 100644 --- a/flake.nix +++ b/flake.nix @@ -4,8 +4,9 @@ inputs = { config.url = "github:stackbuilders/nixpkgs-terraform?dir=templates/config"; flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; + nixpkgs-1_0.url = "github:nixos/nixpkgs/41de143fda10e33be0f47eab2bfe08a50f234267"; # nixos-23.05 + nixpkgs-1_6.url = "github:nixos/nixpkgs/d6b3ddd253c578a7ab98f8011e59990f21dc3932"; # nixos-24.05 + nixpkgs-1_9.url = "github:nixos/nixpkgs/f5fd8730397b9951d24de58f51a5e9cb327e2a85"; # nixpkgs-unstable systems.url = "github:nix-systems/default"; }; @@ -18,13 +19,20 @@ systems = import inputs.systems; - perSystem = { config, pkgs, pkgs-unstable, system, ... }: + perSystem = { config, pkgs-1_0, pkgs-1_6, pkgs-1_9, system, ... }: let flakeConfig = import inputs.config; in { _module.args = { - pkgs-unstable = import inputs.nixpkgs-unstable { + pkgs-1_0 = import inputs.nixpkgs-1_0 { + inherit system; + }; + pkgs-1_6 = import inputs.nixpkgs-1_6 { + inherit system; + config = flakeConfig.nixpkgs-unstable; + }; + pkgs-1_9 = import inputs.nixpkgs-1_9 { inherit system; config = flakeConfig.nixpkgs-unstable; }; @@ -41,11 +49,11 @@ versionLessThan1_6 = version: builtins.compareVersions version "1.6.0" < 0; in { - releases = pkgs.lib.filterAttrs (version: _: allowUnfree || versionLessThan1_6 version) versions.releases; - latest = pkgs.lib.filterAttrs (_: version: allowUnfree || versionLessThan1_6 version) versions.latest; + releases = pkgs-1_9.lib.filterAttrs (version: _: allowUnfree || versionLessThan1_6 version) versions.releases; + latest = pkgs-1_9.lib.filterAttrs (_: version: allowUnfree || versionLessThan1_6 version) versions.latest; }; releases = import ./lib/releases.nix { - inherit pkgs pkgs-unstable; custom-lib = self.lib; + inherit pkgs-1_0 pkgs-1_6 pkgs-1_9; custom-lib = self.lib; releases = filteredVersions.releases; silenceWarnings = flakeConfig.nixpkgs-terraform.silenceWarnings; }; diff --git a/lib/build-terraform.nix b/lib/build-terraform.nix index dc82a05..730445c 100644 --- a/lib/build-terraform.nix +++ b/lib/build-terraform.nix @@ -1,16 +1,22 @@ -{ pkgs, pkgs-unstable, version, hash, vendorHash, silenceWarnings ? false }: +{ pkgs-1_0, pkgs-1_6, pkgs-1_9, version, hash, vendorHash, silenceWarnings ? false }: # https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license -if builtins.compareVersions version "1.6.0" >= 0 +if builtins.compareVersions version "1.9.0" >= 0 then -# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/applications/networking/cluster/terraform/default.nix - (pkgs.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-unstable.mkTerraform + (pkgs-1_9.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-1_9.mkTerraform + { + inherit version hash vendorHash; + patches = [ ../patches/provider-path-1_9.patch ]; + }) +else if builtins.compareVersions version "1.6.0" >= 0 +then + (pkgs-1_6.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-1_6.mkTerraform { inherit version hash vendorHash; patches = [ ../patches/provider-path-0_15.patch ]; }) else # https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/networking/cluster/terraform/default.nix - (pkgs.mkTerraform { + (pkgs-1_0.mkTerraform { inherit version hash vendorHash; patches = [ ../patches/provider-path-0_15.patch ]; }) diff --git a/lib/releases.nix b/lib/releases.nix index 5f21620..3950a34 100644 --- a/lib/releases.nix +++ b/lib/releases.nix @@ -1,6 +1,6 @@ -{ custom-lib, pkgs, pkgs-unstable, releases, silenceWarnings }: +{ custom-lib, pkgs-1_0, pkgs-1_6, pkgs-1_9, releases, silenceWarnings }: builtins.mapAttrs (version: { hash, vendorHash }: custom-lib.buildTerraform { - inherit pkgs pkgs-unstable version hash vendorHash silenceWarnings; + inherit pkgs-1_0 pkgs-1_6 pkgs-1_9 version hash vendorHash silenceWarnings; }) releases diff --git a/patches/provider-path-1_9.patch b/patches/provider-path-1_9.patch new file mode 100644 index 0000000..b70f466 --- /dev/null +++ b/patches/provider-path-1_9.patch @@ -0,0 +1,23 @@ +diff -Naur terraform.old/internal/command/init.go terraform.new/internal/command/init.go +--- terraform.old/internal/command/init.go ++++ terraform.new/internal/command/init.go +@@ -7,6 +7,7 @@ + "context" + "errors" + "fmt" ++ "os" + "log" + "reflect" + "sort" +@@ -77,6 +78,11 @@ + // -force-copy implies -migrate-state + if c.forceInitCopy { + c.migrateState = true ++ } ++ ++ val, ok := os.LookupEnv("NIX_TERRAFORM_PLUGIN_DIR") ++ if ok { ++ initArgs.PluginPath = append(initArgs.PluginPath, val) + } + + if len(initArgs.PluginPath) > 0 { diff --git a/versions.json b/versions.json index 1a9646c..5a0acde 100644 --- a/versions.json +++ b/versions.json @@ -311,6 +311,18 @@ "1.8.5": { "hash": "sha256-5PzP0LUJPpOQQ8YqwBFyEFcsHF2O1uDD8Yh8wB3uJ8s=", "vendorHash": "sha256-PXA2AWq1IFmnqhhU92S9UaIYTUAAn5lsg3S7h5hBOQE=" + }, + "1.9.0": { + "hash": "sha256-mxnRQkwUcWCYmk4QUbAb5UKs9zXrW0qlvPLkVidaeUs=", + "vendorHash": "sha256-pKez3etNpwPU/pRjIzsVBXRjtqLYjnoYghBqFYYDfPU=" + }, + "1.9.1": { + "hash": "sha256-WqcrjKzaJShEFyHeZD4N9pPG2G2tDicQ4e05rt40o00=", + "vendorHash": "sha256-cPWJtrGad8VsvyjJHQwpfDitsJY/Q0iCtp1MRyzGT+U=" + }, + "1.9.2": { + "hash": "sha256-g1CsDWjwjBVfSNFZ9PRGlPlJOrqXP2eMYk1P+ohtYNU=", + "vendorHash": "sha256-cPWJtrGad8VsvyjJHQwpfDitsJY/Q0iCtp1MRyzGT+U=" } }, "latest": { @@ -322,6 +334,7 @@ "1.5": "1.5.7", "1.6": "1.6.6", "1.7": "1.7.5", - "1.8": "1.8.5" + "1.8": "1.8.5", + "1.9": "1.9.2" } } \ No newline at end of file