summaryrefslogtreecommitdiff
path: root/terranix/default.nix
blob: aa499a33e1d0123cf2f77d2ebacb5d47020c3e19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{inputs, ...}: {
  perSystem = {
    lib,
    pkgs,
    system,
    self',
    opentofu',
    ...
  }: let
    terranixConfig = inputs.terranix.lib.terranixConfiguration {
      inherit system;
      modules = [
        ./cloudflare
        ./tailscale
        ./cloud.nix
        ./vars.nix
        ./versions.nix
      ];
    };
  in {
    _module.args.opentofu' = pkgs.opentofu.withPlugins (plugins:
      with plugins; [
        cloudflare
        tailscale
      ]);

    apps.gen-terranix = {
      type = "app";

      program = pkgs.writeShellApplication {
        name = "gen-tf";

        text = ''
          config_file="config.tf.json"
          [ -e "$config_file" ] && rm -f "$config_file"
          cp ${terranixConfig} "$config_file"
        '';
      };
    };

    devShells.terranix = pkgs.mkShell {
      shellHook = ''
        ${self'.apps.gen-terranix.program}
      '';

      packages = [pkgs.just opentofu'];
    };
  };
}