-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuilder.nix
49 lines (45 loc) · 1.03 KB
/
builder.nix
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
{ name
, src
, provider-source-address
, version
, vendorSha256 ? null
, buildGoModule
, GOOS
, GOARCH
}: buildGoModule {
pname = "${name}-${GOOS}-${GOARCH}";
subPackages = ["."];
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 = ''
(
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
'';
}