From db7e26ae8ee7f7441bd81a3cf59262e657560a27 Mon Sep 17 00:00:00 2001 From: Florian Nowarre Date: Tue, 29 Apr 2025 13:26:08 +0200 Subject: [PATCH] docs: update nix files --- default.nix | 39 ---------------------------- flake.lock | 27 +++++++++++++++++++ flake.nix | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 39 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index c8dc2b4..0000000 --- a/default.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ pkgs ? import { }, system ? builtins.currentSystem }: - -let - # fake opentofu as terraform so that tools like terraform-docs pre-commit hook (which doesn't have tofu support) - # fall back to tofu - tofu_terraform = - pkgs.stdenv.mkDerivation { - name = "tofu-terraform"; - phases = [ "installPhase" ]; - installPhase = '' - mkdir -p $out/bin - echo '#!/usr/bin/env sh' > $out/bin/terraform - echo 'tofu $@' > $out/bin/terraform - chmod +x $out/bin/terraform - ''; - }; - -in - -pkgs.mkShell { - NIX_SHELL = "terraform-meshplatform-modules"; - shellHook = '' - echo starting terraform-meshplatform-modules shell - terraform -v - tofu -v - terraform-docs -v - pre-commit --version - ''; - - buildInputs = [ - pkgs.pre-commit - pkgs.opentofu - pkgs.tflint - pkgs.terraform-docs - - # fake tofu as terraform - tofu_terraform - ]; -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..d14b9e9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1735563628, + "narHash": "sha256-OnSAY7XDSx7CtDoqNh8jwVwh4xNL/2HaJxGjryLWzX8=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b134951a4c9f3c995fd7be05f3243f8ecd65d798", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f7cccaa --- /dev/null +++ b/flake.nix @@ -0,0 +1,75 @@ +{ + description = "Flake for terraform-gcp-meshplatform"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05"; + }; + + outputs = { self, nixpkgs }: + + let + # These tools are pre-installed in github actions, so we can save the time for installing them. + github_actions_preinstalled = pkgs: + with pkgs; + [ + awscli2 + (azure-cli.withExtensions [ azure-cli.extensions.account ]) + nodejs + ]; + + # core packages required in CI and not preinstalled in github actions + core_packages = pkgs: + let + tofu_terraform = + pkgs.stdenv.mkDerivation { + name = "tofu-terraform"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + echo '#!/usr/bin/env sh' > $out/bin/terraform + echo 'tofu "$@"' >> $out/bin/terraform + chmod +x $out/bin/terraform + ''; + }; + in + with pkgs; + [ + opentofu + terragrunt + tflint + tfupdate + terraform-docs + tofu_terraform + pre-commit + ]; + + importNixpkgs = system: import nixpkgs { inherit system; }; + + defaultShellForSystem = system: + let + pkgs = importNixpkgs system; + in { + default = pkgs.mkShell { + name = "terraform-gcp-meshplatform"; + packages = (github_actions_preinstalled pkgs) ++ (core_packages pkgs); + }; + }; + + in { + devShells = { + aarch64-darwin = defaultShellForSystem "aarch64-darwin"; + x86_64-darwin = defaultShellForSystem "x86_64-darwin"; + x86_64-linux = defaultShellForSystem "x86_64-linux" // { + github_actions = + let + pkgs = importNixpkgs "x86_64-linux"; + in + pkgs.mkShell { + name = "terraform-gcp-meshplatform"; + packages = (core_packages pkgs); + }; + }; + }; + }; +} +