From e6ddd1feedaa01233059cae6b2fb9ba8b6e656df Mon Sep 17 00:00:00 2001 From: dettlaff Date: Sat, 18 May 2024 06:27:49 +0400 Subject: [PATCH] feat: add read data from flake services file --- .../services/flake_service_manager.py | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/selfprivacy_api/services/flake_service_manager.py b/selfprivacy_api/services/flake_service_manager.py index c7e8822..cb638ba 100644 --- a/selfprivacy_api/services/flake_service_manager.py +++ b/selfprivacy_api/services/flake_service_manager.py @@ -1,11 +1,31 @@ +import re + FLAKE_CONFIG_PATH = "/etc/nixos/sp-modules/flake.nix" class FlakeServiceManager: def __enter__(self): self.services = {} + + with open(FLAKE_CONFIG_PATH, "r") as file: + for line in file: + service_name, url = self._extract_services(input_string=line) + if service_name and url: + self.services[service_name] = url + return self + def _extract_services(self, input_string: str): + pattern = r"inputs\.(\w+)\.url\s*=\s*(\S+);" + match = re.search(pattern, input_string) + + if match: + variable_name = match.group(1) + url = match.group(2) + return variable_name, url + else: + return None, None + def __exit__(self, exc_type, exc_value, traceback): with open(FLAKE_CONFIG_PATH, "w") as file: file.write( @@ -24,8 +44,21 @@ class FlakeServiceManager: file.write( """ - inputs.my.url = path:./my; outputs = _: { }; } """ ) + + +if __name__ == "__main__": + with FlakeServiceManager() as manager: + # manager.services = { + # "bitwarden": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/bitwarden", + # "gitea": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/gitea", + # "jitsi-meet": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/jitsi-meet", + # "nextcloud": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/nextcloud", + # "ocserv": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/ocserv", + # "pleroma": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/pleroma", + # "simple-nixos-mailserver": "git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes&dir=sp-modules/simple-nixos-mailserver", + # } + print(manager.services)