diff --git a/modules/bitcoinecosystem.nix b/modules/bitcoinecosystem.nix index e7d1912..d356263 100755 --- a/modules/bitcoinecosystem.nix +++ b/modules/bitcoinecosystem.nix @@ -69,4 +69,8 @@ lib.mkIf config.sovran_systemsOS.services.bitcoin { }; nix-bitcoin.useVersionLockedPkgs = false; + + sovran_systemsOS.domainRequirements = [ + { name = "btcpayserver"; label = "BTCPay Server"; example = "pay.yourdomain.com"; } + ]; } diff --git a/modules/core/roles.nix b/modules/core/roles.nix index 28b230e..3f4dc86 100755 --- a/modules/core/roles.nix +++ b/modules/core/roles.nix @@ -55,10 +55,24 @@ btcpayserver = lib.mkOption { type = lib.types.bool; default = true; - description = "Expose BTCPay Server via Caddy (service still runs via nix-bitcoin regardless)"; + description = "Expose BTCPay Server via Caddy"; }; }; + # ── Domain setup registry ───────────────────────────────── + domainRequirements = lib.mkOption { + type = lib.types.listOf (lib.types.submodule { + options = { + name = lib.mkOption { type = lib.types.str; }; + label = lib.mkOption { type = lib.types.str; }; + example = lib.mkOption { type = lib.types.str; }; + needsDDNS = lib.mkOption { type = lib.types.bool; default = true; }; + }; + }); + default = []; + description = "Domain requirements registered by each module"; + }; + nostr_npub = lib.mkOption { type = lib.types.str; default = ""; diff --git a/modules/core/sovran-manage-domains.nix b/modules/core/sovran-manage-domains.nix new file mode 100644 index 0000000..ab44e26 --- /dev/null +++ b/modules/core/sovran-manage-domains.nix @@ -0,0 +1,133 @@ +{ config, pkgs, lib, ... }: + +let + domains = config.sovran_systemsOS.domainRequirements; + + # Build the domain prompts dynamically from registered modules + 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 '' + read -p " Njal.la DDNS URL for $DOMAIN (paste full URL, or Enter to skip): " DDNS_URL + if [ -n "$DDNS_URL" ]; then + NJALLA_ENTRIES="$NJALLA_ENTRIES +curl \"''${DDNS_URL%auto}''${DOLLAR}{IP}\"" + fi + ''} + else + echo " Skipped." + fi + '') domains; + + # Build the summary list + domainSummary = lib.concatMapStringsSep "\n" (d: '' + if [ -f "/var/lib/domains/${d.name}" ]; then + echo " ${d.label}: $(cat /var/lib/domains/${d.name})" + fi + '') domains; +in +{ + environment.systemPackages = [ + (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 DDNS URL like:" + echo "" + echo -e " ''${CYAN}https://njal.la/update/?h=sub.domain.com&k=abc123&auto''${NC}" + echo "" + echo " Have those URLs 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 + + # ── Module domains (auto-generated from enabled modules) ── + ${domainPrompts} + + # ── Write njalla.sh ─────────────────────────────── + echo "" + echo -e "''${GREEN}── Generating DDNS script ──''${NC}" + + cat > /var/lib/njalla/njalla.sh <