From 466d03919097d800b9231ed8eff22e4ad07c348b Mon Sep 17 00:00:00 2001 From: Pogobanane Date: Sun, 10 Jul 2022 22:17:40 +0200 Subject: [PATCH] darwin/home-manager: %r dir --- modules/home-manager/sops.nix | 4 +++- pkgs/sops-install-secrets/darwin.go | 10 ++++++++++ pkgs/sops-install-secrets/main.go | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/home-manager/sops.nix b/modules/home-manager/sops.nix index 3d345d5..6565f4e 100644 --- a/modules/home-manager/sops.nix +++ b/modules/home-manager/sops.nix @@ -28,7 +28,9 @@ let default = "%r/secrets/${name}"; description = '' Path where secrets are symlinked to. - If the default is kept no symlink is created. + If the default is kept no other symlink is created. + `%r` is replaced by $XDG_RUNTIME_DIR on linux or `getconf + DARWIN_USER_TEMP_DIR` on darwin. ''; }; diff --git a/pkgs/sops-install-secrets/darwin.go b/pkgs/sops-install-secrets/darwin.go index ba3f943..f1c2657 100644 --- a/pkgs/sops-install-secrets/darwin.go +++ b/pkgs/sops-install-secrets/darwin.go @@ -14,6 +14,16 @@ import ( "golang.org/x/sys/unix" ) +func RuntimeDir() (string, error) { + // TODO this could be garbage collected on a 3d basis + out, err := exec.Command("getconf", "DARWIN_USER_TEMP_DIR").Output() + rundir := strings.TrimRight(string(out[:]), " \t\n") + if err != nil { + return "", fmt.Errorf("Cannot get DARWIN_USER_TEMP_DIR: %v", err) + } + return rundir, nil +} + func SecureSymlinkChown(symlinkToCheck string, expectedTarget string, owner, group int) error { // not sure what O_PATH is needed for anyways fd, err := unix.Open(symlinkToCheck, unix.O_CLOEXEC|unix.O_SYMLINK|unix.O_NOFOLLOW, 0) diff --git a/pkgs/sops-install-secrets/main.go b/pkgs/sops-install-secrets/main.go index da5106b..015c1ea 100644 --- a/pkgs/sops-install-secrets/main.go +++ b/pkgs/sops-install-secrets/main.go @@ -892,9 +892,9 @@ func installSecrets(args []string) error { } if manifest.UserMode { - rundir, ok := os.LookupEnv("XDG_RUNTIME_DIR") - if opts.checkMode == Off && !ok { - return fmt.Errorf("$XDG_RUNTIME_DIR is not set!") + rundir, err := RuntimeDir() + if opts.checkMode == Off && err != nil { + return fmt.Errorf("Error: %v", err) } manifest.SecretsMountPoint = replaceRuntimeDir(manifest.SecretsMountPoint, rundir) manifest.SymlinkPath = replaceRuntimeDir(manifest.SymlinkPath, rundir)