From e5ca975988d5eff6c9c04d6166e77fccc72480a2 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 2 Oct 2023 13:11:30 +0200 Subject: [PATCH] add netcup-dns, start Jinja-Compose, refactor --- hosts/yodaNas/configuration.nix | 9 +- hosts/yodaNas/host-specific.nix | 98 +++++++++++++++++++ hosts/yodaYoga/configuration.nix | 3 +- .../yodaYoga/host-specific.nix | 0 4 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 hosts/yodaNas/host-specific.nix rename modules/yodaYoga.nix => hosts/yodaYoga/host-specific.nix (100%) diff --git a/hosts/yodaNas/configuration.nix b/hosts/yodaNas/configuration.nix index 46ccc0d..60f83e0 100644 --- a/hosts/yodaNas/configuration.nix +++ b/hosts/yodaNas/configuration.nix @@ -22,8 +22,7 @@ in ../../modules/home-manager.nix # NUR. ../../modules/nur.nix - # Device specific. - #../../modules/yodaNas.nix + ./host-specific.nix ../../modules/base.nix ../../modules/base-headless.nix @@ -66,10 +65,4 @@ in boot.kernelParams = []; boot.kernelPackages = pkgs.linuxPackages; - - # TODO: For "/" this cfg resides in base.nix - fileSystems = { - "/mnt/data".options = [ "compress=zstd" "noatime" "commit=120" ]; - "/mnt/backup".options = [ "compress=zstd" "noatime" "commit=120" ]; - }; } diff --git a/hosts/yodaNas/host-specific.nix b/hosts/yodaNas/host-specific.nix new file mode 100644 index 0000000..356aca7 --- /dev/null +++ b/hosts/yodaNas/host-specific.nix @@ -0,0 +1,98 @@ +{ 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 +{ + # TODO: For "/" this cfg resides in base.nix + fileSystems = { + "/mnt/data".options = [ "compress=zstd" "noatime" "commit=120" ]; + "/mnt/backup".options = [ "compress=zstd" "noatime" "commit=120" ]; + }; + + # Install netcup-dns. + 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" ]; + # https://man.archlinux.org/man/systemd.timer.5 + timerConfig = { + OnCalendar = "3m"; + AccuracySec = "15s"; + RandomizedDelaySec = "15s"; + Persistent = true; + }; + }; + systemd.services."netcup-dns" = { + serviceConfig = { + Type = "oneshot"; + PrivateTmp = true; + User = "netcup-dns"; + Nice = 19; + IOSchedulingClass = "idle"; + #ExecStart = "/run/current-system/sw/bin/netcup-dns"; + #ExecStart = "${my-python-packages}/bin/netcup-dns"; + ExecStart = "${pkgs.python3.withPackages my-python-packages}/bin/netcup-dns"; + }; +# path = with pkgs; [ +# my-python-packages +# ]; + }; + + # Start Jinja-Compose project during boot. + # To few the log, run + # journalctl -b -u Jinja-Compose -f + # + systemd.services."Jinja-Compose" = { + description = "Start Jinja-Compose project"; + path = with pkgs; [ + # The `docker-compose` helper script is written in `bash` (!) + bash + docker + ]; + script = '' + /mnt/data/docker-compose/docker-compose up -d --wait + ''; + # Start after login. + wantedBy = [ "multi-user.target" ]; + }; +} diff --git a/hosts/yodaYoga/configuration.nix b/hosts/yodaYoga/configuration.nix index b33e4f0..abd05b4 100644 --- a/hosts/yodaYoga/configuration.nix +++ b/hosts/yodaYoga/configuration.nix @@ -22,8 +22,7 @@ in ../../modules/home-manager.nix # NUR. ../../modules/nur.nix - # Device specific. - ../../modules/yodaYoga.nix + ./host-specific.nix ../../modules/base.nix ../../modules/base-headless.nix diff --git a/modules/yodaYoga.nix b/hosts/yodaYoga/host-specific.nix similarity index 100% rename from modules/yodaYoga.nix rename to hosts/yodaYoga/host-specific.nix