From 057bf5e2b332056f0124e8a8b38c8efdd59a74d6 Mon Sep 17 00:00:00 2001 From: jpnauta Date: Tue, 16 Jul 2024 19:08:43 -0600 Subject: [PATCH] Add nix support --- .github/workflows/build.yml | 8 ++++++++ README.md | 14 ++++++++++++++ default.nix | 17 +++++++++++++++++ nix-test.sh | 4 ++++ 4 files changed, 43 insertions(+) create mode 100644 default.nix create mode 100644 nix-test.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8aaac4..47a04d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,6 +30,14 @@ jobs: - name: Run tests run: go test + - name: Set up Nix + uses: cachix/install-nix-action@v27 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - name: Build Nix Package + run: bash nix-test.sh + - name: Run GoReleaser if: startsWith(github.ref, 'refs/tags/') uses: goreleaser/goreleaser-action@v4 diff --git a/README.md b/README.md index 2d16fab..f863ba0 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,17 @@ Finally, follow the instructions to generate your first generated file. ``` tf-generator generate ``` + +### Nix Usage + +To use this library with [nix](https://nixos.org/), import the repository as an overlay. + +``` +let + tf-generator-overlay = import (builtins.fetchTarball https://github.com/jpnauta/tf-generator/archive/development.tar.gz); + pkgs = import { overlays = [ tf-generator-overlay ]; }; +in +pkgs.mkShellNoCC { + buildInputs = with pkgs; [ tf-generator ]; +} +``` diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..6cb97b4 --- /dev/null +++ b/default.nix @@ -0,0 +1,17 @@ +final: prev: +{ + tf-generator = prev.buildGoModule { + name = "tf-generator"; + + src = ./.; + + vendorHash = "sha256-TIDg83EHqgzL9QOOsgGPm6f50qvnFbZPHwVo6pBaPQQ="; + + meta = { + description = "Simple generator for Terraform/OpenTofu"; + homepage = "https://github.com/jpnauta/tf-generator"; + license = prev.lib.licenses.mit; + maintainers = with prev.lib.maintainers; [ jpnauta ]; + }; + }; +} \ No newline at end of file diff --git a/nix-test.sh b/nix-test.sh new file mode 100644 index 0000000..f4d59bf --- /dev/null +++ b/nix-test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -e + +nix-build -E 'let tf-generator-overlay = import ./.; pkgs = import { overlays = [ tf-generator-overlay ]; }; in pkgs.mkShellNoCC { buildInputs = with pkgs; [ tf-generator ]; }' --dry-run