git.iko.soy/typeable/nixpkgs
on master help sign in
hetzner-kube: fix darwin build
commit28b48756d5d2da3bb659f11a4eb0b1231a47d1af authorStéphan Kochen <git@stephank.nl> dateSun 16 May 2021, 10:59 (6 years ago) parent74e27e2
2 files changed+62
pkgs/applications/networking/cluster/hetzner-kube/default.nix+9 pkgs/applications/networking/cluster/hetzner-kube/fix-home.patch+53
pkgs/applications/networking/cluster/hetzner-kube/default.nix+9
@@ -11,6 +11,13 @@ buildGoModule rec {
1111 sha256 = "1iqgpmljqx6rhmvsir2675waj78amcfiw08knwvlmavjgpxx2ysw";
1212 };
1313
14+ patches = [
15+ # Use $HOME instead of the OS user database.
16+ # Upstream PR: https://github.com/xetys/hetzner-kube/pull/346
17+ # Unfortunately, the PR patch does not apply against release.
18+ ./fix-home.patch
19+ ];
20+
1421 vendorSha256 = "1jh2f66ys6rmrrwrf5zqfprgcvziyq6l4z8bfqwxgf1ysnxx525h";
1522
1623 doCheck = false;
@@ -25,6 +32,8 @@ buildGoModule rec {
2532 ];
2633
2734 postInstall = ''
35+ # Need a writable home, because it fails if unable to write config.
36+ export HOME=$TMP
2837 $out/bin/hetzner-kube completion bash > hetzner-kube
2938 $out/bin/hetzner-kube completion zsh > _hetzner-kube
3039 installShellCompletion --zsh _hetzner-kube
pkgs/applications/networking/cluster/hetzner-kube/fix-home.patchnew file+53
@@ -0,0 +1,53 @@
1+diff --git a/cmd/cluster_kubeconfig.go b/cmd/cluster_kubeconfig.go
2+index 54cc0c9..fab288a 100644
3+--- a/cmd/cluster_kubeconfig.go
4++++ b/cmd/cluster_kubeconfig.go
5+@@ -6,7 +6,7 @@ import (
6+ "io/ioutil"
7+ "log"
8+ "os"
9+- "os/user"
10++ "path/filepath"
11+ "strings"
12+
13+ "github.com/spf13/cobra"
14+@@ -52,9 +52,8 @@ Example 4: hetzner-kube cluster kubeconfig -n my-cluster -p > my-conf.yaml # pri
15+ } else {
16+ fmt.Println("create file")
17+
18+- usr, _ := user.Current()
19+- dir := usr.HomeDir
20+- path := fmt.Sprintf("%s/.kube", dir)
21++ dir, _ := os.UserHomeDir()
22++ path := filepath.Join(dir, ".kube")
23+
24+ if _, err := os.Stat(path); os.IsNotExist(err) {
25+ os.MkdirAll(path, 0755)
26+diff --git a/cmd/config.go b/cmd/config.go
27+index ce0f3e5..a03c4ba 100644
28+--- a/cmd/config.go
29++++ b/cmd/config.go
30+@@ -8,7 +8,6 @@ import (
31+ "io/ioutil"
32+ "log"
33+ "os"
34+- "os/user"
35+ "path/filepath"
36+
37+ "github.com/hetznercloud/hcloud-go/hcloud"
38+@@ -28,13 +27,8 @@ type AppSSHClient struct {
39+ // NewAppConfig creates a new AppConfig struct using the locally saved configuration file. If no local
40+ // configuration file is found a new config will be created.
41+ func NewAppConfig() AppConfig {
42+- usr, err := user.Current()
43+- if err != nil {
44+- return AppConfig{}
45+- }
46+- if usr.HomeDir != "" {
47+- DefaultConfigPath = filepath.Join(usr.HomeDir, ".hetzner-kube")
48+- }
49++ dir, _ := os.UserHomeDir()
50++ DefaultConfigPath = filepath.Join(dir, ".hetzner-kube")
51+
52+ appConf := AppConfig{
53+ Context: context.Background(),