-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdefault.nix
82 lines (75 loc) · 1.82 KB
/
default.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{ pkgs ? import <nixpkgs> {}
, namespace ? "registry.terraform.io/corpix"
, repo ? "terraform-provider-${name}"
, name ? "nixos"
, version ? "0.0.1"
, targets ? [
{ GOOS = "linux"; GOARCH = "amd64"; }
{ GOOS = "linux"; GOARCH = "arm64"; }
{ GOOS = "darwin"; GOARCH = "amd64"; }
{ GOOS = "darwin"; GOARCH = "arm64"; }
]
}: let
inherit (builtins)
toString
baseNameOf
filterSource
trace
;
inherit (pkgs)
stdenvNoCC
buildGoModule
;
inherit (pkgs.lib)
concatStringsSep
concatMapStringsSep
hasPrefix
hasSuffix
;
inherit (pkgs.nix-gitignore)
gitignoreSourcePure
;
##
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;
};
artifacts = map build targets;
in stdenvNoCC.mkDerivation {
name = repo;
buildInputs = [pkgs.findutils];
unpackPhase = ":";
buildPhase = ":";
installPhase = ''
mkdir $out
${concatMapStringsSep "\n"
(artifact: "cp --no-preserve=mode -r ${artifact}/* $out")
artifacts}
find $out -type f | xargs chmod 755
'';
fixupPhase = ":";
}