btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / no / nomad-autoscaler / package.nix
blob6a232472f6cd5fec2a4d5aa26fb54cc25bc9f769
1 { lib, fetchFromGitHub, buildGoModule, buildEnv }:
3 let
4   package = buildGoModule rec {
5     pname = "nomad-autoscaler";
6     version = "0.3.6";
8     outputs = [
9       "out"
10       "bin"
11       "aws_asg"
12       "azure_vmss"
13       "datadog"
14       "fixed_value"
15       "gce_mig"
16       "nomad_apm"
17       "nomad_target"
18       "pass_through"
19       "prometheus"
20       "target_value"
21       "threshold"
22     ];
24     src = fetchFromGitHub {
25       owner = "hashicorp";
26       repo = "nomad-autoscaler";
27       rev = "v${version}";
28       sha256 = "sha256-fK5GsszNhz/WP0zVk2lOfU/gwYijdQa5qhNYO33RhXc=";
29     };
31     vendorHash = "sha256-Duzjpl011mj/SNoX/jQGMXwqUHPDz7iIMygRmK1vC3Q=";
33     buildPhase = ''
34       runHook preBuild
35       make build plugins
36       runHook postBuild
37     '';
39     # tries to pull tests from network, and fails silently anyway
40     doCheck = false;
42     installPhase = ''
43       runHook preInstall
44       mkdir -p $bin/bin $out/bin
45       mv bin/nomad-autoscaler $bin/bin
46       ln -s $bin/bin/nomad-autoscaler $out/bin/nomad-autoscaler
48       for d in $(getAllOutputNames); do
49         mkdir -p ''${!d}/share
50       done
51       rmdir $bin/share
53       # have out contain all of the plugins
54       for plugin in bin/plugins/*; do
55         cp "$plugin" $out/share/
56       done
58       # populate the outputs as individual plugins
59       # can't think of a more generic way to handle this
60       # bash doesn't allow for dashes '-' to be in a variable name
61       # this means that the output names will need to differ slightly from the binary
62       mv bin/plugins/aws-asg $aws_asg/share/
63       mv bin/plugins/azure-vmss $azure_vmss/share/
64       mv bin/plugins/datadog $datadog/share/
65       mv bin/plugins/fixed-value $fixed_value/share/
66       mv bin/plugins/gce-mig $gce_mig/share/
67       mv bin/plugins/nomad-apm $nomad_apm/share/
68       mv bin/plugins/nomad-target $nomad_target/share/
69       mv bin/plugins/pass-through $pass_through/share/
70       mv bin/plugins/prometheus $prometheus/share/
71       mv bin/plugins/target-value $target_value/share/
72       mv bin/plugins/threshold $threshold/share/
73       runHook postInstall
74     '';
76     # make toggle-able, so that overrided versions can disable this check if
77     # they want newer versions of the plugins without having to modify
78     # the output logic
79     doInstallCheck = true;
80     installCheckPhase = ''
81       rmdir bin/plugins || {
82         echo "Not all plugins were extracted"
83         echo "Please move the following to their related output: $(ls bin/plugins)"
84         exit 1
85       }
86     '';
88     passthru = {
89       inherit plugins withPlugins;
90     };
92     meta = with lib; {
93       description = "Autoscaling daemon for Nomad";
94       mainProgram = "nomad-autoscaler";
95       homepage = "https://github.com/hashicorp/nomad-autoscaler";
96       license = licenses.mpl20;
97       maintainers = [ ];
98     };
99   };
101   plugins = let
102       plugins = builtins.filter (n: !(lib.elem n [ "out" "bin" ])) package.outputs;
103     in lib.genAttrs plugins (output: package.${output});
105   # Intended to be used as: (nomad-autoscaler.withPlugins (ps: [ ps.aws_asg ps.nomad_target ])
106   withPlugins = f: buildEnv {
107     name = "nomad-autoscaler-env";
108     paths = [ package.bin ] ++ f plugins;
109   };
111   package