aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: 71b630ee0e80d266e868be646bd9262d7ee70b96 (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
let
  pkgs = import <nixpkgs> { };
  terraform-godaddy = pkgs.buildGoModule rec {
    name = "terraform-godaddy-${version}";
    version = "1.6.4";
    src = pkgs.fetchFromGitHub {
      owner = "n3integration";
      repo = "terraform-godaddy";
      rev = "v${version}";
      sha256 = "00blqsan74s53dk9ab4hxi1kzxi46k57dr65dmbiradfa3yz3852";
    };
    modSha256 = "0p81wqw2n8vraxk20xwg717582ijwq2k7v5j3n13y4cd5bxd8hhz";
    postInstall =
    "mv $out/bin/terraform-godaddy $out/bin/terraform-provider-godaddy";
  };
in rec {
  terraform-godaddy2 = terraform-godaddy;
  utils = import ./utils.nix {
    pkgs = pkgs;
    src = pkgs.nix-gitignore.gitignoreSource [ ] ./.;
    baseName = "vps";
  };
  subtasks = rec {
    formatTerraform = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-format-terraform";
      buildInputs = baseAttrs.buildInputs ++ [ pkgs.terraform ];
      buildPhase = ''
        terraform fmt -check=true -diff=true || {
          echo "Terraform files are unformatted. To fix it, run:"
          echo "  terraform fmt"
          exit 1
        }
        touch $out
      '';
    });
    dockerComposeLint = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-docker-compose-lint";
      buildInputs = baseAttrs.buildInputs ++ [ pkgs.docker-compose ];
      buildPhase = ''
        source .envrc
        # =docker-compose config= doesn't accept files with different names
        cp docker-compose.env.yaml docker-compose.yaml
        docker-compose config &> /dev/null || {
          echo "Invalid docker-compose.yml file."
          exit 1
        }
        touch $out
      '';
    });
    shellEnvironment = utils.baseTask.overrideAttrs (baseAttrs: {
      name = "${baseAttrs.name}-shell-inputs";
      buildInputs = with pkgs; [
        gitMinimal
        git-crypt
        gettext
        terraform-providers.digitalocean
        terraform-godaddy
        terraform-full
        ansible
      ];
      buildPhase = ''
        echo "Can build shell environment buildInputs!"
        echo noop > $out
      '';
    });
  };
  test = utils.test [
    (utils.shellcheck null)
    (utils.fixme null)
    utils.formatNix
    subtasks.formatTerraform
    subtasks.dockerComposeLint
    subtasks.shellEnvironment
  ];
  # Used in .build.yml to run Bash scripts
  shell = pkgs.mkShell rec {
    name = "vps-shell";
    buildInputs = subtasks.shellEnvironment.buildInputs;
  };
}