-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding cross-compilation for darwin and linux to address #1
- Loading branch information
Showing
3 changed files
with
108 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,49 @@ | ||
{ buildGoModule }: src: desc: buildGoModule { | ||
pname = desc.name; | ||
version = desc.version; | ||
inherit src; | ||
|
||
{ name | ||
, src | ||
, provider-source-address | ||
, version | ||
, vendorSha256 ? null | ||
, buildGoModule | ||
, GOOS | ||
, GOARCH | ||
}: buildGoModule { | ||
pname = "${name}-${GOOS}-${GOARCH}"; | ||
subPackages = ["."]; | ||
vendorSha256 = desc.vendorSha256 or null; | ||
|
||
inherit | ||
src | ||
version | ||
vendorSha256 | ||
; | ||
|
||
CGO_ENABLED = "0"; | ||
ldflags = ["-extldflags=-static"]; | ||
|
||
postConfigure = '' | ||
export GOOS=${GOOS} | ||
export GOARCH=${GOARCH} | ||
''; | ||
|
||
# Terraform allow checking the provider versions, but this breaks | ||
# if the versions are not provided via file paths. | ||
postBuild = "mv $NIX_BUILD_TOP/go/bin/${desc.name}{,_v${desc.version}}"; | ||
postInstall = with desc; '' | ||
dir=$out/libexec/terraform-providers/${provider-source-address}/${version}/''${GOOS}_''${GOARCH} | ||
postBuild = '' | ||
( | ||
dir=$GOPATH/bin/${GOOS}_${GOARCH} | ||
if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]] | ||
then | ||
mv $dir/* $dir/.. | ||
fi | ||
if [[ -d $dir ]] | ||
then | ||
rmdir $dir | ||
fi | ||
) | ||
mv $GOPATH/bin/${name} $GOPATH/bin/${name}_v${version} | ||
''; | ||
postInstall = '' | ||
dir=$out/libexec/terraform-providers/${provider-source-address}/${version}/${GOOS}_${GOARCH} | ||
mkdir -p "$dir" | ||
mv $out/bin/* "$dir/terraform-provider-$(basename ${provider-source-address})_${version}" | ||
rmdir $out/bin | ||
''; | ||
passthru = desc; | ||
|
||
CGO_ENABLED = "0"; | ||
ldflags = ["-extldflags=-static"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,71 @@ | ||
{ pkgs ? import <nixpkgs> {} | ||
, namespace ? "registry.terraform.io/corpix" | ||
, repo ? "terraform-provider-${name}" | ||
, name ? "nixos" | ||
, version ? "0.0.1" | ||
}: let | ||
inherit (builtins) | ||
toString | ||
baseNameOf | ||
filterSource | ||
trace | ||
; | ||
inherit (pkgs) | ||
symlinkJoin | ||
buildGoModule | ||
; | ||
inherit (pkgs.lib) | ||
concatStringsSep | ||
hasPrefix | ||
hasSuffix | ||
; | ||
inherit (pkgs.nix-gitignore) | ||
gitignoreSourcePure | ||
; | ||
|
||
## | ||
|
||
mkProvider = import ./builder.nix { | ||
inherit buildGoModule; | ||
}; | ||
providerSourceFilter = name: type: | ||
let bname = baseNameOf name; | ||
in | ||
((type == "regular") | ||
&& ((hasSuffix ".go" name) | ||
|| (hasSuffix ".s" name) | ||
|| (hasSuffix "/go.sum" name) | ||
|| (hasSuffix "/go.mod" name) | ||
|| (hasSuffix "/provider/nix_conf_wrapper.nix" name) | ||
|| (hasSuffix "/vendor/modules.txt" name))) | ||
|| ((type == "directory") | ||
&& !(hasPrefix "." bname)); | ||
sources = let src = filterSource providerSourceFilter ./.; | ||
in trace "sources: ${src}" src; | ||
|
||
## | ||
|
||
builder = import ./builder.nix; | ||
build = platform: builder | ||
{ | ||
name = repo; | ||
version = version; | ||
src = sources; | ||
|
||
provider-source-address = "${namespace}/${name}"; | ||
|
||
inherit (platform) | ||
GOOS | ||
GOARCH | ||
; | ||
inherit buildGoModule; | ||
}; | ||
|
||
in mkProvider | ||
(gitignoreSourcePure [./.gitignore] ./.) | ||
{ | ||
name = "terraform-provider-${name}"; | ||
version = version; | ||
provider-source-address = "${namespace}/${name}"; | ||
} | ||
artifacts = map build | ||
[ | ||
{ GOOS = "linux"; GOARCH = "amd64"; } | ||
{ GOOS = "linux"; GOARCH = "arm64"; } | ||
{ GOOS = "darwin"; GOARCH = "amd64"; } | ||
{ GOOS = "darwin"; GOARCH = "arm64"; } | ||
]; | ||
in symlinkJoin { | ||
name = repo; | ||
paths = artifacts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters