aboutsummaryrefslogblamecommitdiff
path: root/default.nix
blob: 71b630ee0e80d266e868be646bd9262d7ee70b96 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                              
                                                                      
      
                                                                       

                                                                        
    
        
                                         

                              
                                                     
                     
    
                  
                                                                
                                                  
                                                                








                                                                 
                                                                  
                                                     
                                                                     
                     
                     

                                                                           
                                               





                                                 






                                                                 

                         
               

                     
                                                       


                        
    





                              
                             
    
                                          
                            
                       
                                                        

    
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;
  };
}