use EnvironmentFile in dyndns systemd service to drastically uncomplicate things

This commit is contained in:
2026-02-11 22:21:56 +01:00
parent 52486cdb13
commit 9d92c0bbd8
2 changed files with 8 additions and 19 deletions
+3 -7
View File
@@ -3,12 +3,7 @@
... ...
}: }:
let let
pyenv = pkgs.python3.withPackages ( pyenv = pkgs.python3.withPackages (ps: with ps; [ nc-dnsapi ]);
ps: with ps; [
nc-dnsapi
python-dotenv
]
);
in in
{ {
users.groups.dyndns = { }; users.groups.dyndns = { };
@@ -32,7 +27,8 @@ in
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
User = "dyndns"; User = "dyndns";
ExecStart = "${pyenv.interpreter} ${./dyndns.py} ${./nc.env.secret}"; ExecStart = "${pyenv.interpreter} ${./dyndns.py}";
EnvironmentFile = ./. + "/nc.env.secret";
}; };
}; };
} }
+5 -12
View File
@@ -1,17 +1,10 @@
from nc_dnsapi import Client from nc_dnsapi import Client
from dotenv import dotenv_values import os, urllib3
import sys, urllib3
if len(sys.argv) != 2: CUSTOMER = os.environ["NC_CUSTOMER"]
raise Exception("Something funky is going on with argv") API_PASSWORD = os.environ["NC_API_PASSWORD"]
API_KEY = os.environ["NC_API_KEY"]
dotenv_path = sys.argv[1] DOMAIN = os.environ["NC_DOMAIN"]
secrets = dotenv_values(dotenv_path)
CUSTOMER = secrets["NC_CUSTOMER"]
API_PASSWORD = secrets["NC_API_PASSWORD"]
API_KEY = secrets["NC_API_KEY"]
DOMAIN = secrets["NC_DOMAIN"]
ip = urllib3.request("GET", "https://api.ipify.org").data.decode() ip = urllib3.request("GET", "https://api.ipify.org").data.decode()