Created
December 10, 2025 05:46
-
-
Save maxsei/2986f55ca8025770f4089ab97696d38b to your computer and use it in GitHub Desktop.
flake nix for deploying with terranix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| 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