Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created December 10, 2025 05:46
Show Gist options
  • Select an option

  • Save maxsei/2986f55ca8025770f4089ab97696d38b to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/2986f55ca8025770f4089ab97696d38b to your computer and use it in GitHub Desktop.
flake nix for deploying with terranix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
terranix.url = "github:terranix/terranix";
terranix.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
terranix,
flake-utils,
sops-nix,
...
}@inputs:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs { inherit system; };
lib = nixpkgs.lib;
terraformConfiguration = terranix.lib.terranixConfiguration {
inherit system;
modules = [ ./config.nix ];
};
in
{
apps = {
apply = {
type = "app";
program = pkgs.writeShellApplication {
name = "apply";
runtimeInputs = [ pkgs.opentofu ];
text = ''
set -eu -o pipefail
opentofu init "$(dirname ${terraformConfiguration})"
opentofu apply "$(dirname ${terraformConfiguration})"
'';
};
};
destroy = {
type = "app";
program = pkgs.writeShellApplication {
name = "destroy";
runtimeInputs = [ pkgs.opentofu ];
text = ''
set -eu -o pipefail
opentofu init "$(dirname ${terraformConfiguration})"
opentofu destroy "$(dirname ${terraformConfiguration})"
'';
};
};
};
defaultApp = self.apps.${system}.apply;
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment