expand the path to support working in systemd service
This commit is contained in:
parent
ba34ac0d67
commit
29fe7f76c1
3 changed files with 27 additions and 3 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
Changes yet to be released are documented here.
|
Changes yet to be released are documented here.
|
||||||
|
|
||||||
|
- Fix path expansion when running in systemd
|
||||||
- Add nixos, home-manager, and darwin-nix modules
|
- Add nixos, home-manager, and darwin-nix modules
|
||||||
|
|
||||||
## v0.1.0
|
## v0.1.0
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ func Load(path string) (*Config, error) {
|
||||||
return nil, fmt.Errorf("parsing config file: %w", err)
|
return nil, fmt.Errorf("parsing config file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.NetrcPath = os.ExpandEnv(cfg.NetrcPath)
|
cfg.NetrcPath = expandPath(cfg.NetrcPath)
|
||||||
cfg.ClientSecretFile = os.ExpandEnv(cfg.ClientSecretFile)
|
cfg.ClientSecretFile = expandPath(cfg.ClientSecretFile)
|
||||||
|
|
||||||
if cfg.ClientSecretFile != "" {
|
if cfg.ClientSecretFile != "" {
|
||||||
secret, err := os.ReadFile(cfg.ClientSecretFile)
|
secret, err := os.ReadFile(cfg.ClientSecretFile)
|
||||||
|
|
@ -71,6 +71,29 @@ func (c *Config) validate() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expandPath expands environment variables in a path. XDG base directory
|
||||||
|
// variables are resolved using the xdg library, which applies the XDG spec
|
||||||
|
// fallbacks (e.g. $HOME/.config when $XDG_CONFIG_HOME is unset). This ensures
|
||||||
|
// correct behaviour in systemd user services, which do not set XDG variables.
|
||||||
|
func expandPath(s string) string {
|
||||||
|
return os.Expand(s, func(key string) string {
|
||||||
|
switch key {
|
||||||
|
case "XDG_CONFIG_HOME":
|
||||||
|
return xdg.ConfigHome
|
||||||
|
case "XDG_DATA_HOME":
|
||||||
|
return xdg.DataHome
|
||||||
|
case "XDG_CACHE_HOME":
|
||||||
|
return xdg.CacheHome
|
||||||
|
case "XDG_STATE_HOME":
|
||||||
|
return xdg.StateHome
|
||||||
|
case "XDG_RUNTIME_DIR":
|
||||||
|
return xdg.RuntimeDir
|
||||||
|
default:
|
||||||
|
return os.Getenv(key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// RefreshTokenPath returns the path to the stored refresh token.
|
// RefreshTokenPath returns the path to the stored refresh token.
|
||||||
func RefreshTokenPath() string {
|
func RefreshTokenPath() string {
|
||||||
return filepath.Join(xdg.ConfigHome, "nix-cache-login", "refresh-token")
|
return filepath.Join(xdg.ConfigHome, "nix-cache-login", "refresh-token")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
buildGoModule {
|
buildGoModule {
|
||||||
pname = "nix-cache-login";
|
pname = "nix-cache-login";
|
||||||
version = "0.1.1";
|
version = "0.1.2";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
# src = fetchgit {
|
# src = fetchgit {
|
||||||
# url = "https://guardianproject.dev/ops/nix-cache-login.git";
|
# url = "https://guardianproject.dev/ops/nix-cache-login.git";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue