{ config, pkgs, lib, ... }: let domains = config.sovran_systemsOS.domainRequirements; domainNamesList = lib.concatMapStringsSep " " (d: d.name) domains; ddnsPrompt = '' read -p " Njal.la DDNS curl command (paste full line, or Enter to skip): " DDNS_LINE if [ -n "$DDNS_LINE" ]; then # Strip any leading "curl " if they pasted the whole command DDNS_LINE="''${DDNS_LINE#curl }" # Strip surrounding quotes DDNS_LINE="''${DDNS_LINE%\"}" DDNS_LINE="''${DDNS_LINE#\"}" # Replace &auto with &a=''${IP} at the end DDNS_LINE="''${DDNS_LINE%auto}&a=''${DOLLAR}{IP}" # Remove any trailing double &a= if they already had &a= DDNS_LINE=$(echo "$DDNS_LINE" | sed 's/&a=&a=/\&a=/g') ''; domainPrompts = lib.concatMapStringsSep "\n" (d: '' echo "" echo -e "''${GREEN}── ${d.label} ──''${NC}" EXISTING="" if [ -f "/var/lib/domains/${d.name}" ]; then EXISTING=$(cat "/var/lib/domains/${d.name}") echo -e " Current: ''${CYAN}$EXISTING''${NC}" fi read -p " Subdomain (e.g. ${d.example}) or Enter to keep current: " DOMAIN_INPUT DOMAIN="''${DOMAIN_INPUT:-$EXISTING}" if [ -n "$DOMAIN" ]; then echo "$DOMAIN" > "/var/lib/domains/${d.name}" echo " Saved: $DOMAIN" ${lib.optionalString d.needsDDNS '' ${ddnsPrompt} NJALLA_ENTRIES="$NJALLA_ENTRIES curl \"$DDNS_LINE\"" fi ''} else echo " Skipped." fi '') domains; missingDomainPrompts = lib.concatMapStringsSep "\n" (d: '' if [ ! -f "/var/lib/domains/${d.name}" ]; then MISSING=true echo "" echo -e "''${GREEN}── ${d.label} (NEW) ──''${NC}" read -p " Subdomain (e.g. ${d.example}): " DOMAIN if [ -n "$DOMAIN" ]; then echo "$DOMAIN" > "/var/lib/domains/${d.name}" echo " Saved: $DOMAIN" ${lib.optionalString d.needsDDNS '' ${ddnsPrompt} NEW_NJALLA_ENTRIES="$NEW_NJALLA_ENTRIES curl \"$DDNS_LINE\"" fi ''} else echo " Skipped." fi fi '') domains; domainSummary = lib.concatMapStringsSep "\n" (d: '' if [ -f "/var/lib/domains/${d.name}" ]; then echo " ${d.label}: $(cat /var/lib/domains/${d.name})" fi '') domains; setupScript = pkgs.writeShellScriptBin "sovran-setup-domains" '' set -euo pipefail GREEN='\033[0;32m' YELLOW='\033[1;33m' CYAN='\033[0;36m' NC='\033[0m' DOLLAR='$' echo "" echo -e "''${CYAN}══════════════════════════════════════════════''${NC}" echo -e "''${CYAN} Sovran_SystemsOS — Domain & DDNS Setup''${NC}" echo -e "''${CYAN}══════════════════════════════════════════════''${NC}" echo "" echo -e "''${YELLOW}Before running this, you need:''${NC}" echo "" echo " 1. Domains/subdomains purchased on https://njal.la" echo " 2. For each subdomain, add a Dynamic record in" echo " your Njal.la dashboard." echo " 3. Njal.la will give you a curl command like:" echo "" echo -e " ''${CYAN}curl \"https://njal.la/update/?h=sub.domain.com&k=abc123&auto\"''${NC}" echo "" echo " Have those curl commands ready." echo "" read -p "Press Enter to continue..." # ── Create directories ──────────────────────────── mkdir -p /var/lib/domains mkdir -p /var/lib/njalla NJALLA_ENTRIES="" # ── SSL Email ───────────────────────────────────── echo "" echo -e "''${GREEN}── SSL Certificate Email ──''${NC}" echo "Let's Encrypt needs an email for certificate notifications." EXISTING_EMAIL="" if [ -f "/var/lib/domains/sslemail" ]; then EXISTING_EMAIL=$(cat /var/lib/domains/sslemail) echo -e " Current: ''${CYAN}$EXISTING_EMAIL''${NC}" fi read -p " Email address (or Enter to keep current): " EMAIL_INPUT SSL_EMAIL="''${EMAIL_INPUT:-$EXISTING_EMAIL}" if [ -n "$SSL_EMAIL" ]; then echo "$SSL_EMAIL" > /var/lib/domains/sslemail echo " Saved." fi # ── All module domains ──────────────────────────── ${domainPrompts} # ── Write njalla.sh ─────────────────────────────── echo "" echo -e "''${GREEN}── Generating DDNS script ──''${NC}" cat > /var/lib/njalla/njalla.sh <