mirror of
https://github.com/Mic92/sops-nix.git
synced 2024-12-14 11:57:52 +00:00
darwin/home-manager: %r dir
This commit is contained in:
parent
98834d958b
commit
466d039190
3 changed files with 16 additions and 4 deletions
|
@ -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.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue