Skip to content

Instantly share code, notes, and snippets.

@mitchellh
Created May 12, 2020 23:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mitchellh/9c50ec6082e2478c0fd6fa2e3d81c5f5 to your computer and use it in GitHub Desktop.
{ pkgs ? import <nixpkgs> {} }:
with pkgs; let
# A function that helps us make derivations to grab binary HashiCorp packages
mkHashicorpPackage = { name
, version
, sha256
, system ? builtins.currentSystem
, pname ? "${name}-bin"
}: let
# Mapping of Nix systems to the GOOS/GOARCH pairs.
systemMap = {
x86_64-linux = "linux_amd64";
i686-linux = "linux_386";
x86_64-darwin = "darwin_amd64";
i686-darwin = "darwin_386";
aarch64-linux = "linux_arm64";
};
# Get our system
goSystem = systemMap.${system} or (throw "unsupported system: ${system}");
# url for downloading composed of all the other stuff we built up.
url = "https://releases.hashicorp.com/${name}/${version}/${name}_${version}_${goSystem}.zip";
in stdenv.mkDerivation {
inherit pname version;
src = fetchurl { inherit url sha256; };
# Our source is right where the unzip happens, not in a "src/" directory (default)
sourceRoot = ".";
# Stripping breaks darwin Go binaries
dontStrip = lib.strings.hasPrefix "darwin" goSystem;
nativeBuildInputs = [ unzip ];
installPhase = ''
mkdir -p $out/bin
mv ${name} $out/bin
'';
};
gomplate = pkgs.stdenv.mkDerivation rec {
pname = "gomplate";
version = "3.5.0";
src = fetchurl {
url = "https://github.com/hairyhenderson/gomplate/releases/download/v${version}/gomplate_darwin-amd64";
sha256 = "0sszj8bvmlgllgzwc323wkqi5cn4cqaclf08c1gfj5k8mc04y591";
};
# The binaries are not archived
dontUnpack = true;
# Our source is right where the unzip happens, not in a "src/" directory (default)
sourceRoot = ".";
# Stripping breaks darwin Go binaries
dontStrip = true;
installPhase = ''
mkdir -p $out/bin
cp ${src} $out/bin/gomplate
chmod +x $out/bin/gomplate
'';
};
terraform = mkHashicorpPackage {
name = "terraform";
version = "0.12.24";
sha256 = "0krvs64j00ys23hyv9smz2dx1ksa60405mwmivl36p72ll020j3j";
};
nomad = mkHashicorpPackage {
name = "nomad";
version = "0.11.1";
sha256 = "0z51k1c1f02jp1x8836vxf7dqdn7prbm196wnz27c87d8jx61pxr";
};
vault = mkHashicorpPackage {
name = "vault";
version = "1.4.1";
sha256 = "031n3sq2rwid22q4ra11is6zhypnsjhqa3qqj2qapz2rcb4hrjaf";
};
dependencies = [
coreutils
jq
gomplate
nomad
terraform
vault
pkgs.mysql
pkgs.postgresql
];
in stdenv.mkDerivation {
name = "cloud-sre";
shellHook = lib.strings.concatStringsSep "\n" (map
(n: "export PATH=${n}/bin:$PATH")
dependencies);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment