From 8dbd422a50d32fc1549fbd6c8d6bd07712515bc8 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Tue, 14 Nov 2023 19:04:58 +0100 Subject: [PATCH] refactor netcup-dns --- hosts/yodaNas/configuration.nix | 1 + hosts/yodaNas/host-specific.nix | 68 -------------------------------- modules/netcup-dns.nix | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 68 deletions(-) create mode 100644 modules/netcup-dns.nix diff --git a/hosts/yodaNas/configuration.nix b/hosts/yodaNas/configuration.nix index ed3702d..4d2ee53 100644 --- a/hosts/yodaNas/configuration.nix +++ b/hosts/yodaNas/configuration.nix @@ -23,6 +23,7 @@ ../../modules/journalwatch.nix ../../modules/btrbk + ../../modules/netcup-dns.nix ../../modules/de-p1st-monitor.nix ../../modules/spin-down.nix diff --git a/hosts/yodaNas/host-specific.nix b/hosts/yodaNas/host-specific.nix index 09d4fd7..8f408be 100644 --- a/hosts/yodaNas/host-specific.nix +++ b/hosts/yodaNas/host-specific.nix @@ -1,73 +1,5 @@ { config, pkgs, ... }: -let - my-python-packages = ps: with ps; [ - # netcup-dns is not (yet) packaged, thus we build it from PyPI - ( - buildPythonPackage rec { - pname = "netcup-dns"; - version = "0.2.0"; - # https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py - format = "pyproject"; - src = fetchPypi { - inherit pname version; - sha256 = "sha256-tZKPe02tHrTelyw30BQsJhdZpmDsggZ0rr4ag0eHtng="; - }; - propagatedBuildInputs = [ - # Dependencies - pkgs.python3Packages.requests - pkgs.python3Packages.nc-dnsapi - # Build dependencies - build - twine - ]; - } - ) - ]; -in { - # Install netcup-dns Python packages. - environment.systemPackages = [ - (pkgs.python3.withPackages my-python-packages) - ]; - - # Configure netcup-dns. - # Create file `/etc/netcup-dns/netcup-dns-95191.json`. - deployment.keys."netcup-dns-95191.json" = { - keyFile = ../../secrets/netcup-dns.json; - destDir = "/etc/netcup-dns"; - user = "netcup-dns"; - group = "netcup-dns"; - }; - # Create netcup-dns daemon user. - users.users."netcup-dns" = { - isSystemUser = true; - group = "netcup-dns"; - description = "netcup-dns daemon"; - }; - users.groups."netcup-dns" = {}; - # Create netcup-dns timer. - systemd.timers."netcup-dns" = { - wantedBy = [ "timers.target" ]; - partOf = [ "netcup-dns.service" ]; - timerConfig = { - OnBootSec = "0m"; - OnUnitInactiveSec = "3m"; - - AccuracySec = "15s"; - RandomizedDelaySec = "15s"; - }; - }; - systemd.services."netcup-dns" = { - serviceConfig = { - Type = "oneshot"; - PrivateTmp = true; - User = "netcup-dns"; - Nice = 19; - IOSchedulingClass = "idle"; - ExecStart = "${pkgs.python3.withPackages my-python-packages}/bin/netcup-dns"; - }; - }; - # Update and start Jinja-Compose project # during boot and after every 30 minutes. # To view the log, run diff --git a/modules/netcup-dns.nix b/modules/netcup-dns.nix new file mode 100644 index 0000000..259d385 --- /dev/null +++ b/modules/netcup-dns.nix @@ -0,0 +1,70 @@ +{ config, pkgs, ... }: +let + my-python-packages = ps: with ps; [ + # netcup-dns is not (yet) packaged, thus we build it from PyPI + ( + buildPythonPackage rec { + pname = "netcup-dns"; + version = "0.2.0"; + # https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py + format = "pyproject"; + src = fetchPypi { + inherit pname version; + sha256 = "sha256-tZKPe02tHrTelyw30BQsJhdZpmDsggZ0rr4ag0eHtng="; + }; + propagatedBuildInputs = [ + # Dependencies + pkgs.python3Packages.requests + pkgs.python3Packages.nc-dnsapi + # Build dependencies + build + twine + ]; + } + ) + ]; +in +{ + # Install netcup-dns Python packages. + environment.systemPackages = [ + (pkgs.python3.withPackages my-python-packages) + ]; + + # Configure netcup-dns. + # Create file `/etc/netcup-dns/netcup-dns-95191.json`. + deployment.keys."netcup-dns-95191.json" = { + keyFile = ../../secrets/netcup-dns.json; + destDir = "/etc/netcup-dns"; + user = "netcup-dns"; + group = "netcup-dns"; + }; + # Create netcup-dns daemon user. + users.users."netcup-dns" = { + isSystemUser = true; + group = "netcup-dns"; + description = "netcup-dns daemon"; + }; + users.groups."netcup-dns" = {}; + # Create netcup-dns timer. + systemd.timers."netcup-dns" = { + wantedBy = [ "timers.target" ]; + partOf = [ "netcup-dns.service" ]; + timerConfig = { + OnBootSec = "0m"; + OnUnitInactiveSec = "3m"; + + AccuracySec = "15s"; + RandomizedDelaySec = "15s"; + }; + }; + systemd.services."netcup-dns" = { + serviceConfig = { + Type = "oneshot"; + PrivateTmp = true; + User = "netcup-dns"; + Nice = 19; + IOSchedulingClass = "idle"; + ExecStart = "${pkgs.python3.withPackages my-python-packages}/bin/netcup-dns"; + }; + }; +}