git.iko.soy/typeable/nixpkgs
on master help sign in
minikube: switch to build from source & fix on Darwin

Linux behavior should be largely unchanged but we now build minikube ourselves. Unfortunately localkube is still tricky to build so I pull in a binary version from upstream.

commitfe339d281bd1947983a8d590736227707a9f56b9 authorDan Peebles <pumpkin@me.com> dateSat 11 Mar 2017, 20:12 (10 years ago) parent25d3a0b
1 file changed+59−29
pkgs/applications/networking/cluster/minikube/default.nix+59−29
pkgs/applications/networking/cluster/minikube/default.nix+59−29
@@ -1,47 +1,77 @@
1−{ stdenv, lib, fetchurl, makeWrapper, docker-machine-kvm, kubernetes, libvirt, qemu }:
1+{ stdenv, buildGoPackage, fetchFromGitHub, fetchurl, go-bindata, kubernetes, libvirt, qemu, docker-machine-kvm, makeWrapper }:
22
33let
4− arch = if stdenv.isLinux
5− then "linux-amd64"
6− else "darwin-amd64";
7− checksum = if stdenv.isLinux
8− then "0cdcabsx5l4jbpyj3zzyz5bnzks6wl64bmzdsnk41x92ar5y5yal"
9− else "12f3b7s5lwpvzx4wj6i6h62n4zjshqf206fxxwpwx9kpsdaw6xdi";
4+ binPath = [ kubernetes ]
5+ ++ stdenv.lib.optionals stdenv.isLinux [ libvirt qemu docker-machine-kvm ]
6+ ++ stdenv.lib.optionals stdenv.isDarwin [];
107
11−# TODO: compile from source
12−
13−in stdenv.mkDerivation rec {
14− pname = "minikube";
8+ # Normally, minikube bundles localkube in its own binary via go-bindata. Unfortunately, it needs to make that localkube
9+ # a static linux binary, and our Linux nixpkgs go compiler doesn't seem to work when asking for a cgo binary that's static
10+ # (presumably because we don't have some static system libraries it wants), and cross-compiling cgo on Darwin is a nightmare.
11+ #
12+ # Note that minikube can download (and cache) versions of localkube it needs on demand. Unfortunately, minikube's knowledge
13+ # of where it can download versions of localkube seems to rely on a json file that doesn't get updated as often as we'd like,
14+ # so for example it doesn't know about v1.5.3 even though there's a perfectly good version of localkube hosted there. So
15+ # instead, we download localkube ourselves and shove it into the minikube binary. The versions URL that minikube uses is
16+ # currently https://storage.googleapis.com/minikube/k8s_releases.json. Note that we can't use 1.5.3 with minikube 0.17.1
17+ # expects to be able to pass it a command-line argument that it doesn't understand. v1.5.4 and higher should be fine. There
18+ # doesn't seem to ae any official release of localkube for 1.5.4 yet so I'm temporarily grabbing a version built from the
19+ # minikube CI server.
20+ localkube-binary = fetchurl {
21+ url = "https://storage.googleapis.com/minikube-builds/1216/localkube";
22+ # url = "https://storage.googleapis.com/minikube/k8sReleases/v${kubernetes.version}/localkube-linux-amd64";
23+ sha256 = "1vqrsak7n045ci6af3rpgs2qwjnrqk8k7c3ax6wzli4m8vhsiv57";
24+ };
25+in buildGoPackage rec {
26+ pname = "minikube";
27+ name = "${pname}-${version}";
1528 version = "0.17.1";
16− name = "${pname}-${version}";
1729
18− src = fetchurl {
19− url = "https://storage.googleapis.com/minikube/releases/v${version}/minikube-${arch}";
20− sha256 = "${checksum}";
30+ goPackagePath = "k8s.io/minikube";
31+
32+ src = fetchFromGitHub {
33+ owner = "kubernetes";
34+ repo = "minikube";
35+ rev = "v${version}";
36+ sha256 = "1m61yipn0p3cfavjddhrg1rcmr0hv6k3zxvqqd9fisl79g0sdfsr";
2137 };
2238
23− phases = [ "installPhase" "fixupPhase" ];
39+ # kubernetes is here only to shut up a loud warning when generating the completions below. minikube checks very eagerly
40+ # that kubectl is on the $PATH, even if it doesn't use it at all to generate the completions
41+ buildInputs = [ go-bindata makeWrapper kubernetes ];
42+ subPackages = [ "cmd/minikube" ];
2443
25− buildInputs = [ makeWrapper ];
44+ preBuild = ''
45+ pushd go/src/${goPackagePath} >/dev/null
2646
27− binPath = lib.makeBinPath [ docker-machine-kvm kubernetes libvirt qemu ];
47+ mkdir -p out
48+ cp ${localkube-binary} out/localkube
2849
29− installPhase = ''
30− install -Dm755 ${src} $out/bin/${pname}
31− '';
50+ go-bindata -nomemcopy -o pkg/minikube/assets/assets.go -pkg assets ./out/localkube deploy/addons/...
3251
33− fixupPhase = ''
34− patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" "$out/bin/minikube"
52+ ISO_VERSION=$(grep "^ISO_VERSION" Makefile | sed "s/^.*\s//")
53+ ISO_BUCKET=$(grep "^ISO_BUCKET" Makefile | sed "s/^.*\s//")
3554
36− wrapProgram $out/bin/${pname} \
37− --prefix PATH : ${binPath}
55+ export buildFlagsArray="-ldflags=\
56+ -X k8s.io/minikube/pkg/version.version=v${version} \
57+ -X k8s.io/minikube/pkg/version.isoVersion=$ISO_VERSION \
58+ -X k8s.io/minikube/pkg/version.isoPath=$ISO_BUCKET"
59+
60+ popd >/dev/null
61+ '';
62+
63+ postInstall = ''
64+ mkdir -p $bin/share/bash-completion/completions/
65+ MINIKUBE_WANTUPDATENOTIFICATION=false HOME=$PWD $bin/bin/minikube completion bash > $bin/share/bash-completion/completions/minikube
3866 '';
3967
68+ postFixup = "wrapProgram $bin/bin/${pname} --prefix PATH : ${stdenv.lib.makeBinPath binPath}";
69+
4070 meta = with stdenv.lib; {
41− homepage = https://github.com/kubernetes/minikube;
71+ homepage = https://github.com/kubernetes/minikube;
4272 description = "A tool that makes it easy to run Kubernetes locally";
43− license = licenses.asl20;
44− maintainers = with maintainers; [ ebzzry ];
45− platforms = with platforms; linux ++ darwin;
73+ license = licenses.asl20;
74+ maintainers = with maintainers; [ ebzzry copumpkin ];
75+ platforms = with platforms; unix;
4676 };
4777}