From 28b48756d5d2da3bb659f11a4eb0b1231a47d1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Sun, 16 May 2021 10:59:58 +0200 Subject: [PATCH] hetzner-kube: fix darwin build --- .../cluster/hetzner-kube/default.nix | 9 ++++ .../cluster/hetzner-kube/fix-home.patch | 53 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 pkgs/applications/networking/cluster/hetzner-kube/fix-home.patch diff --git a/pkgs/applications/networking/cluster/hetzner-kube/default.nix b/pkgs/applications/networking/cluster/hetzner-kube/default.nix index d0afe6d2e43..f66e5f88e72 100644 --- a/pkgs/applications/networking/cluster/hetzner-kube/default.nix +++ b/pkgs/applications/networking/cluster/hetzner-kube/default.nix @@ -11,6 +11,13 @@ buildGoModule rec { sha256 = "1iqgpmljqx6rhmvsir2675waj78amcfiw08knwvlmavjgpxx2ysw"; }; + patches = [ + # Use $HOME instead of the OS user database. + # Upstream PR: https://github.com/xetys/hetzner-kube/pull/346 + # Unfortunately, the PR patch does not apply against release. + ./fix-home.patch + ]; + vendorSha256 = "1jh2f66ys6rmrrwrf5zqfprgcvziyq6l4z8bfqwxgf1ysnxx525h"; doCheck = false; @@ -25,6 +32,8 @@ buildGoModule rec { ]; postInstall = '' + # Need a writable home, because it fails if unable to write config. + export HOME=$TMP $out/bin/hetzner-kube completion bash > hetzner-kube $out/bin/hetzner-kube completion zsh > _hetzner-kube installShellCompletion --zsh _hetzner-kube diff --git a/pkgs/applications/networking/cluster/hetzner-kube/fix-home.patch b/pkgs/applications/networking/cluster/hetzner-kube/fix-home.patch new file mode 100644 index 00000000000..1b3bbae65f4 --- /dev/null +++ b/pkgs/applications/networking/cluster/hetzner-kube/fix-home.patch @@ -0,0 +1,53 @@ +diff --git a/cmd/cluster_kubeconfig.go b/cmd/cluster_kubeconfig.go +index 54cc0c9..fab288a 100644 +--- a/cmd/cluster_kubeconfig.go ++++ b/cmd/cluster_kubeconfig.go +@@ -6,7 +6,7 @@ import ( + "io/ioutil" + "log" + "os" +- "os/user" ++ "path/filepath" + "strings" + + "github.com/spf13/cobra" +@@ -52,9 +52,8 @@ Example 4: hetzner-kube cluster kubeconfig -n my-cluster -p > my-conf.yaml # pri + } else { + fmt.Println("create file") + +- usr, _ := user.Current() +- dir := usr.HomeDir +- path := fmt.Sprintf("%s/.kube", dir) ++ dir, _ := os.UserHomeDir() ++ path := filepath.Join(dir, ".kube") + + if _, err := os.Stat(path); os.IsNotExist(err) { + os.MkdirAll(path, 0755) +diff --git a/cmd/config.go b/cmd/config.go +index ce0f3e5..a03c4ba 100644 +--- a/cmd/config.go ++++ b/cmd/config.go +@@ -8,7 +8,6 @@ import ( + "io/ioutil" + "log" + "os" +- "os/user" + "path/filepath" + + "github.com/hetznercloud/hcloud-go/hcloud" +@@ -28,13 +27,8 @@ type AppSSHClient struct { + // NewAppConfig creates a new AppConfig struct using the locally saved configuration file. If no local + // configuration file is found a new config will be created. + func NewAppConfig() AppConfig { +- usr, err := user.Current() +- if err != nil { +- return AppConfig{} +- } +- if usr.HomeDir != "" { +- DefaultConfigPath = filepath.Join(usr.HomeDir, ".hetzner-kube") +- } ++ dir, _ := os.UserHomeDir() ++ DefaultConfigPath = filepath.Join(dir, ".hetzner-kube") + + appConf := AppConfig{ + Context: context.Background(),