Skip to content

Commit

Permalink
feat: Add template for terranix (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-izval authored Mar 7, 2024
1 parent efba3eb commit ac7e620
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
needs: [build]
strategy:
matrix:
template: [default, devenv]
template: [default, devenv, terranix]
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ outputs = { self, flake-utils, nixpkgs-terraform, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.6.3";
terraform = nixpkgs-terraform.packages.${system}."X.Y.Z";
in
{
devShells.default = pkgs.mkShell {
buildInputs = [ terraform ];
};
});
```
where `X.Y.Z` is one of the supported versions in the `versions.json` file.

#### As an overlay

Expand All @@ -98,10 +99,11 @@ outputs = { self, flake-utils, nixpkgs-terraform, nixpkgs }:
in
{
devShells.default = pkgs.mkShell {
buildInputs = [ pkgs.terraform-versions."1.6.3" ];
buildInputs = [ pkgs.terraform-versions."X.Y.Z" ];
};
});
```
where `X.Y.Z` is one of the supported versions in the `versions.json` file.

Start a new [nix-shell] with Terraform in scope by running the following
command:
Expand All @@ -122,6 +124,7 @@ 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.
- [terranix](templates/terranix) - Using nixpkgs-terraform with terranix.

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

Expand Down
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
description = "Using nixpkgs-terraform with devenv";
path = ./templates/devenv;
};
terranix = {
description = "Using nixpkgs-terraform with terranix";
path = ./templates/terranix;
};
};

lib = import ./lib;
Expand Down
30 changes: 18 additions & 12 deletions templates/default/flake.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-terraform.url = "github:stackbuilders/nixpkgs-terraform";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
};

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

outputs = { self, flake-utils, nixpkgs-terraform, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.2";
in
{
devShells.default = pkgs.mkShell {
buildInputs = [ terraform ];
};
});
outputs = { self, nixpkgs-terraform, nixpkgs, systems }:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.4";
in
{
default = pkgs.mkShell {
buildInputs = [ terraform ];
};
});
};
}
42 changes: 24 additions & 18 deletions templates/devenv/flake.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
{
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";
systems.url = "github:nix-systems/default";
};

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.7.2";
in
{
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
languages.terraform.enable = true;
languages.terraform.package = terraform;
})
];
};
});
outputs = inputs@{ self, devenv, nixpkgs-terraform, nixpkgs, systems }:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.4";
in
{
default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
languages.terraform.enable = true;
languages.terraform.package = terraform;
})
];
};
});
};
}
17 changes: 17 additions & 0 deletions templates/terranix/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Example config.nix from https://terranix.org/documentation/getting-started.html,
# Make sure to update it with your own resources before applying.
{ ... }:
{
resource.hcloud_server.nginx = {
name = "terranix.nginx";
image = "debian-10";
server_type = "cx11";
backups = false;
};
resource.hcloud_server.test = {
name = "terranix.test";
image = "debian-9";
server_type = "cx11";
backups = true;
};
}
37 changes: 37 additions & 0 deletions templates/terranix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
inputs = {
nixpkgs-terraform.url = "github:stackbuilders/nixpkgs-terraform";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
terranix.url = "github:terranix/terranix";
};

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

outputs = { self, nixpkgs-terraform, nixpkgs, systems, terranix }:
let
forEachSystem = nixpkgs.lib.genAttrs (import systems);
in
{
packages = forEachSystem (system: {
default = terranix.lib.terranixConfiguration {
inherit system;
modules = [ ./config.nix ];
};
});
devShells = forEachSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.4";
in
{
default = pkgs.mkShell {
buildInputs = [ terraform pkgs.terranix];
};
});
};
}

0 comments on commit ac7e620

Please sign in to comment.