From 39a89ffbdc49cc9ab6f67bc4be7ea2f7d3e2b38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Rivera?= Date: Sun, 26 Jul 2026 16:44:23 +0200 Subject: [PATCH] feat: expand env variables in config at runtime --- README.md | 2 ++ nixpkgs_notifier.py | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index badb350..6fca128 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ The default values are below. `ntfy.server` (string url) Ntfy server to use. `ntfy.topic` (string) Ntfy topic for the notification. +Note : `$` will be expanded into the environment variables at runtime. Don't forget to escape it with `\`. + ### Usage * Adding a PR : `nixpkgs-notifier add PR1 PR2 PR3 ...` diff --git a/nixpkgs_notifier.py b/nixpkgs_notifier.py index f8f1c90..2b3dc0d 100644 --- a/nixpkgs_notifier.py +++ b/nixpkgs_notifier.py @@ -74,6 +74,32 @@ def load_config(): print("Config file is broken. Using default config.") return DEFAULT_CONFIG +import re + +def expand_env_vars(obj): + if isinstance(obj, dict): + return { + key: expand_env_vars(value) + for key, value in obj.items() + } + + elif isinstance(obj, list): + return [ + expand_env_vars(item) + for item in obj + ] + + elif isinstance(obj, str): + pattern = r"(?