feat: add read data from flake services file

This commit is contained in:
dettlaff 2024-05-18 06:27:49 +04:00 committed by Inex Code
parent f8a768643f
commit e6ddd1feed

View file

@ -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)