nix-git/modules/netcup-dns.nix

87 lines
2.9 KiB
Nix

{ 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.3";
# https://nixos.wiki/wiki/Packaging/Python#Fix_Missing_setup.py
format = "pyproject";
src = fetchPypi {
inherit pname version;
sha256 = "sha256-9iZWO5RBN/iD3qZdiI4f+kzvZm57isex2Hcmm8ai9Js=";
};
propagatedBuildInputs = [
# Dependencies
pkgs.python3Packages.requests
pkgs.python3Packages.nc-dnsapi
# Build dependencies
build
twine
];
nativeBuildInputs = with pkgs.python3Packages; [
setuptools
];
}
)
];
in
{
# Install netcup-dns Python packages.
environment.systemPackages = [
(pkgs.python3.withPackages my-python-packages)
];
# Configure netcup-dns.
# This creates file `/etc/netcup-dns/netcup-dns-95191.json`.
# Update A and AAA entry of domains p1st.de, privacy1st.de, biketripplanner.de
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";
# Create directory `/run/netcup-dns`.
# `netcup-dns` uses it for caching.
# For systemd to create this directory automatically, `PermissionsStartOnly` is required: https://unix.stackexchange.com/questions/354583/how-to-automatically-create-a-runtime-folder-with-a-systemd-service-or-tmpfiles#comment628290_354583
RuntimeDirectoryMode = "0755";
RuntimeDirectory = "netcup-dns";
PermissionsStartOnly = true;
# Since we use `/run/netcup-dns` for caching between subsequent runs of `netcup-dns`, it should be kept and not deleted.
# Man page section `RuntimeDirectoryPreserve`:
# If set to yes, then the directories are not removed when the service is stopped. Note that since the runtime directory /run/ is a mount point of "tmpfs", then for system services the directories specified in RuntimeDirectory= are removed when the system is rebooted.
RuntimeDirectoryPreserve = true;
ExecStart = "${pkgs.python3.withPackages my-python-packages}/bin/netcup-dns --cache-directory /run/netcup-dns";
};
};
}