{
  config,
  lib,
  pkgs,
  ...
}:

let
  alias_tf = pkgs.writeShellScriptBin "tf" ''
    exec ${pkgs.terraform}/bin/terraform "''${@}"
  '';
in
{
  imports = [ ];

  options.me = {
    terraform.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      example = true;
      description = "Whether we want to install terraform.";
    };
  };

  config = lib.mkIf config.me.terraform.enable (
    lib.mkMerge [
      {
        environment.systemPackages = with pkgs; [
          terraform
          alias_tf
        ];

        allowedUnfree = [
          "terraform"
        ];

        environment.persistence."/persist" = lib.mkIf (config.me.mountPersistence) {
          hideMounts = true;
          users.talexander = {
            directories = [
              {
                directory = ".terraform.d";
                user = "talexander";
                group = "talexander";
                mode = "0755";
              }
            ];
          };
        };
      }
      (lib.mkIf config.me.kubernetes.enable {
        environment.systemPackages = with pkgs; [
          tfk8s # Converts k8s yaml manifests to terraform kubernetes_manifest.
          k2tf # Converts k8s yaml manifests to terraform real types.
        ];
      })
    ]
  );
}
