System Gen86 @ 2025-07-24-20:32:00 by jonas@monolith
This commit is contained in:
parent
9a641f55cd
commit
680378e691
@ -17,12 +17,12 @@
|
|||||||
sopsFile = ../../secrets/monolith/wg.yaml;
|
sopsFile = ../../secrets/monolith/wg.yaml;
|
||||||
key = "privateKey";
|
key = "privateKey";
|
||||||
};
|
};
|
||||||
sops.secrets.spotify-shortcuts-clientId = {
|
sops.secrets.spotifyShortcutsClientId = {
|
||||||
sopsFile = ../../secrets/spotify-shortcuts.yaml;
|
sopsFile = ../../secrets/spotify-shortcuts.yaml;
|
||||||
key = "clientId";
|
key = "clientId";
|
||||||
mode = "0644";
|
mode = "0644";
|
||||||
};
|
};
|
||||||
sops.secrets.spotify-shortcuts-clientSecret = {
|
sops.secrets.spotifyShortcutsClientSecret = {
|
||||||
sopsFile = ../../secrets/spotify-shortcuts.yaml;
|
sopsFile = ../../secrets/spotify-shortcuts.yaml;
|
||||||
key = "clientSecret";
|
key = "clientSecret";
|
||||||
mode = "0644";
|
mode = "0644";
|
||||||
@ -81,8 +81,8 @@
|
|||||||
};
|
};
|
||||||
hive.programs.spotify-shortcuts = {
|
hive.programs.spotify-shortcuts = {
|
||||||
enable = true;
|
enable = true;
|
||||||
clientIdFile = config.sops.secrets.spotify-shortcuts-clientId.path;
|
clientIdSopsKey = config.sops.secrets.spotifyShortcutsClientId.name;
|
||||||
clientSecretFile = config.sops.secrets.spotify-shortcuts-clientSecret.path;
|
clientSecretSopsKey = config.sops.secrets.spotifyShortcutsClientSecret.name;
|
||||||
};
|
};
|
||||||
|
|
||||||
# system packages
|
# system packages
|
||||||
|
|||||||
@ -8,21 +8,26 @@
|
|||||||
in {
|
in {
|
||||||
options.hive.programs.spotify-shortcuts = {
|
options.hive.programs.spotify-shortcuts = {
|
||||||
enable = lib.mkEnableOption "Enable Spotify Shortcuts";
|
enable = lib.mkEnableOption "Enable Spotify Shortcuts";
|
||||||
clientIdFile = lib.mkOption {
|
clientIdSopsKey = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.singleLineStr;
|
||||||
description = "Spotify API Client ID Path";
|
description = "Spotify API Client ID sops secret name";
|
||||||
};
|
};
|
||||||
clientSecretFile = lib.mkOption {
|
clientSecretSopsKey = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.singleLineStr;
|
||||||
description = "Spotify API Client Secret Path";
|
description = "Spotify API Client Secret Path sops secret name";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = [pkgs.hive.spotify-shortcuts];
|
environment.systemPackages = [pkgs.hive.spotify-shortcuts];
|
||||||
environment.etc."profile.d/spotify-shortcuts.sh".text = ''
|
environment.variables = {
|
||||||
export SPOTIFY_SHORTCUTS_CLIENT_ID=$(cat ${cfg.clientIdFile})
|
SPOTIFY_SHORTCUTS_CONFIG = config.sops.templates."spotify-shortcuts-client.json".path;
|
||||||
export SPOTIFY_SHORTCUTS_CLIENT_SECRET=$(cat ${cfg.clientSecretFile})
|
};
|
||||||
|
sops.templates."spotify-shortcuts-client.json".content = ''
|
||||||
|
{
|
||||||
|
"clientId": "${config.sops.placeholder.${cfg.clientIdSopsKey}}",
|
||||||
|
"clientSecret": "${config.sops.placeholder.${cfg.clientSecretSopsKey}}"
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ from typing import List
|
|||||||
from os import getenv
|
from os import getenv
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from xdg.BaseDirectory import xdg_cache_home
|
from xdg.BaseDirectory import xdg_cache_home
|
||||||
|
from json import loads
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -13,6 +14,19 @@ class Config:
|
|||||||
client_id: str | None = None
|
client_id: str | None = None
|
||||||
client_secret: str | None = None
|
client_secret: str | None = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_file(path: Path):
|
||||||
|
if not path.exists():
|
||||||
|
raise FileNotFoundError(f"Configuration file {path} does not exist.")
|
||||||
|
with open(path, "r") as f:
|
||||||
|
data = loads(f.read())
|
||||||
|
|
||||||
|
return Config(
|
||||||
|
cache_file=Path(data.get("cacheFile", Config.cache_file)),
|
||||||
|
client_id=data.get("clientId", Config.client_id),
|
||||||
|
client_secret=data.get("clientSecret", Config.client_secret),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_config(args: List[str] = argv[1:]) -> Config:
|
def load_config(args: List[str] = argv[1:]) -> Config:
|
||||||
parser = ArgumentParser(description="Spotify CLI Tool")
|
parser = ArgumentParser(description="Spotify CLI Tool")
|
||||||
@ -37,14 +51,12 @@ def load_config(args: List[str] = argv[1:]) -> Config:
|
|||||||
|
|
||||||
ns = parser.parse_args(args)
|
ns = parser.parse_args(args)
|
||||||
|
|
||||||
cfg = Config(
|
cfg = Config()
|
||||||
cache_file=ns.cache_file,
|
if (cfg_file := getenv("SPOTIFY_SHORTCUTS_CONFIG", None)) != None:
|
||||||
client_id=ns.client_id,
|
cfg = Config.from_file(Path(cfg_file))
|
||||||
client_secret=ns.client_secret,
|
|
||||||
)
|
|
||||||
|
|
||||||
return Config(
|
return Config(
|
||||||
cache_file=Path(getenv("SPOTIFY_SHORTCUTS_CACHE_FILE", cfg.cache_file)),
|
cache_file=ns.cache_file or cfg.cache_file,
|
||||||
client_id=getenv("SPOTIFY_SHORTCUTS_CLIENT_ID", cfg.client_id),
|
client_id=ns.client_id or cfg.client_id,
|
||||||
client_secret=getenv("SPOTIFY_SHORTCUTS_CLIENT_SECRET", cfg.client_secret),
|
client_secret=ns.client_secret or cfg.client_secret,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user