Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nix function for creating a derivation (package) that installs binaries from releases.hashicorp.com
self: super: {
consul-bin = self.callPackage ./hashicorp-generic.nix {
name = "consul";
version = "1.7.3";
sha256 = "0k03n7h5h8miqhh3n3y47894vhwdcp8m611w55f826swmq9angl1";
};
# and so on...
}
/* This function creates a derivation for installing binaries directly
* from releases.hashicorp.com.
*/
{ name
, version
, sha256
, system ? builtins.currentSystem
, pname ? "${name}-bin"
, lib
, stdenv
, fetchurl
, unzip
, ...
}:
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
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment