Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test flake templates #5

Merged
merged 12 commits into from
Nov 17, 2023
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ concurrency:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -25,3 +26,30 @@ jobs:
run: nix flake check --impure
env:
NIXPKGS_ALLOW_UNFREE: 1

templates:
strategy:
matrix:
template: [default, devenv]
fail-fast: true
runs-on: ubuntu-latest
timeout-minutes: 2
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v6
- name: Replace inputs on templates
run: sed -i 's/github:stackbuilders\/nixpkgs-terraform/github:stackbuilders\/nixpkgs-terraform\/${{ github.sha }}/g' templates/*/flake.nix
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

- name: Create a temporary directory
run: echo "tmpdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"
id: mktemp
- name: Scaffold a new project
run: nix flake init -t ${{ github.workspace }}#${{ matrix.template }}
working-directory: ${{ steps.mktemp.outputs.tmpdir }}
- name: Run smoke test
run: nix develop --accept-flake-config --impure -c terraform --version
env:
NIXPKGS_ALLOW_UNFREE: 1
working-directory: ${{ steps.mktemp.outputs.tmpdir }}
38 changes: 29 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ This flake provides a set of Terraform versions in the form of:
nixpkgs-terraform.packages.${system}.${version}
```

Terraform versions >= 1.5.0 are kept up to date via a weekly scheduled [CI
Terraform versions `>= 1.5.0` are kept up to date via a weekly scheduled [CI
workflow](.github/workflows/update.yml).

The current project structure as well as some components of the CI workflow are
heavily inspired by the following projects:

- [nixpkgs-python](https://github.com/cachix/nixpkgs-python)
- [nixpkgs-ruby](https://github.com/bobvanderlinden/nixpkgs-ruby)

## Install

The quickest way to get started with an empty project is to scaffold a new
Expand All @@ -45,7 +39,7 @@ inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
```

**Binary Cache**
### Binary Cache

It is highly recommended to set up the
[nixpkgs-terraform](https://nixpkgs-terraform.cachix.org) binary cache to
Expand Down Expand Up @@ -90,9 +84,35 @@ env NIXPKGS_ALLOW_UNFREE=1 nix develop --impure

**Note:** Due to Hashicorp’s most recent [license
change](https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license),
the `NIXPKGS_ALLOW_UNFREE` flag is required for Terraform versions >= 1.6.0,
the `NIXPKGS_ALLOW_UNFREE` flag is required for Terraform versions `>= 1.6.0`,
`nix develop` should work out of the box for older versions.

### Templates

This flake provides the following templates:

- [default](templates/default) - Simple nix-shell with Terraform installed via
nixpkgs-terraform.
- [devenv](templates/devenv) - Using nixpkgs-terraform with devenv.

Run the following command to scaffold a new project using a template:

```sh
nix flake init -t github:stackbuilders/nixpkgs-terraform#<template>
```

**Note:** Replace `<template>` with one of the templates listed above.

## Inspired By

The current project structure as well as some components of the CI workflow are
heavily inspired by the following projects:

- [nixpkgs-python](https://github.com/cachix/nixpkgs-python) - All Python
versions, kept up-to-date on hourly basis using Nix.
- [nixpkgs-ruby](https://github.com/bobvanderlinden/nixpkgs-ruby) - A Nix
repository with all Ruby versions being kept up-to-date automatically.

## License

MIT, see [the LICENSE file](LICENSE).
Expand Down
12 changes: 9 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@
inherit version hash vendorHash;
patches = [ "${nixpkgs}/pkgs/applications/networking/cluster/terraform/provider-path-0_15.patch" ];
};
templates.default = {
description = "Simple nix-shell with Terraform installed via nixpkgs-terraform";
path = ./templates/default;
templates = {
default = {
description = "Simple nix-shell with Terraform installed via nixpkgs-terraform";
path = ./templates/default;
};
devenv = {
description = "Using nixpkgs-terraform with devenv";
path = ./templates/devenv;
};
};
};
}
31 changes: 31 additions & 0 deletions templates/devenv/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
inputs = {
devenv.url = "github:cachix/devenv";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-terraform.url = "github:stackbuilders/nixpkgs-terraform";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

nixConfig = {
extra-substituters = "https://nixpkgs-terraform.cachix.org";
extra-trusted-public-keys = "nixpkgs-terraform.cachix.org-1:8Sit092rIdAVENA3ZVeH9hzSiqI/jng6JiCrQ1Dmusw=";
};

outputs = inputs@{ self, devenv, flake-utils, nixpkgs-terraform, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.6.3";
in
{
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
languages.terraform.enable = true;
languages.terraform.package = terraform;
})
];
};
});
}