added njalla script

This commit is contained in:
2026-03-27 19:17:27 -05:00
parent f1149f3465
commit 87ce6c9b47
3 changed files with 45 additions and 30 deletions

32
modules/core/njalla_.nix Normal file
View File

@@ -0,0 +1,32 @@
{ config, pkgs, lib, ... }:
{
# ── Ensure njalla directory and base script exist on every build ──
systemd.tmpfiles.rules = [
"d /var/lib/njalla 0750 root root -"
];
# ── Create base njalla.sh if it doesn't exist yet ────────────
systemd.services.njalla-init = {
description = "Initialize Njal.la DDNS script if missing";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
unitConfig = {
ConditionPathExists = "!/var/lib/njalla/njalla.sh";
};
script = ''
cat > /var/lib/njalla/njalla.sh <<'SCRIPT'
#!/usr/bin/env bash
IP=$(dig @resolver4.opendns.com myip.opendns.com +short -4)
## Add DDNS entries below one curl per line
## Run 'sudo sovran-setup-domains' to configure automatically
SCRIPT
chmod 700 /var/lib/njalla/njalla.sh
'';
};
}

View File

@@ -151,7 +151,6 @@ $PENDING_NJALLA"
# Create directories # Create directories
mkdir -p /var/lib/domains mkdir -p /var/lib/domains
mkdir -p /var/lib/njalla
NJALLA_ENTRIES="" NJALLA_ENTRIES=""
PENDING_NJALLA="" PENDING_NJALLA=""
@@ -223,18 +222,13 @@ $PENDING_NJALLA"
exit 1 exit 1
fi fi
# Write njalla.sh # Append curl entries to njalla.sh
if [ -n "$NJALLA_ENTRIES" ]; then
echo "" echo ""
printf "%b%s%b\n" "$GREEN" " Generating DDNS script " "$NC" printf "%b%s%b\n" "$GREEN" " Updating DDNS script " "$NC"
echo "$NJALLA_ENTRIES" >> /var/lib/njalla/njalla.sh
cat > /var/lib/njalla/njalla.sh <<SCRIPT echo " Appended entries to /var/lib/njalla/njalla.sh"
#!/usr/bin/env bash fi
IP=\$(dig @resolver4.opendns.com myip.opendns.com +short -4)
$NJALLA_ENTRIES
SCRIPT
chmod 700 /var/lib/njalla/njalla.sh
echo " Written to /var/lib/njalla/njalla.sh"
# Run DDNS update now # Run DDNS update now
echo "" echo ""
@@ -244,7 +238,7 @@ SCRIPT
echo " DNS records updated." echo " DNS records updated."
fi fi
# Mark setup complete <EFBFBD><EFBFBD> # Mark setup complete
touch /var/lib/domains/.setup-complete touch /var/lib/domains/.setup-complete
# Summary # Summary
@@ -283,7 +277,6 @@ SCRIPT
echo " Checking for newly enabled features that need domains..." echo " Checking for newly enabled features that need domains..."
mkdir -p /var/lib/domains mkdir -p /var/lib/domains
mkdir -p /var/lib/njalla
${missingDomainPrompts} ${missingDomainPrompts}
@@ -322,19 +315,8 @@ SCRIPT
if [ -n "$NEW_NJALLA_ENTRIES" ]; then if [ -n "$NEW_NJALLA_ENTRIES" ]; then
echo "" echo ""
printf "%b%s%b\n" "$GREEN" " Updating DDNS script " "$NC" printf "%b%s%b\n" "$GREEN" " Updating DDNS script " "$NC"
if [ -f /var/lib/njalla/njalla.sh ]; then
echo "$NEW_NJALLA_ENTRIES" >> /var/lib/njalla/njalla.sh echo "$NEW_NJALLA_ENTRIES" >> /var/lib/njalla/njalla.sh
echo " Appended new entries to /var/lib/njalla/njalla.sh" echo " Appended new entries to /var/lib/njalla/njalla.sh"
else
cat > /var/lib/njalla/njalla.sh <<SCRIPT
#!/usr/bin/env bash
IP=\$(dig @resolver4.opendns.com myip.opendns.com +short -4)
$NEW_NJALLA_ENTRIES
SCRIPT
chmod 700 /var/lib/njalla/njalla.sh
echo " Created /var/lib/njalla/njalla.sh"
fi
echo "" echo ""
read -p "Update Njal.la DNS records now? (y/n): " RUN_NOW read -p "Update Njal.la DNS records now? (y/n): " RUN_NOW
@@ -348,14 +330,14 @@ SCRIPT
echo "" echo ""
printf "%b%s%b\n" "$CYAN" "" "$NC" printf "%b%s%b\n" "$CYAN" "" "$NC"
printf "%b%s%b\n" "$CYAN" " New Domains Added!" "$NC" printf "%b%s%b\n" "$CYAN" " New Domains Added!" "$NC"
printf "%b%s%b\n" "$CYAN" "" "$NC" printf "%b%s%b\n" "$CYAN" "<EFBFBD><EFBFBD><EFBFBD>" "$NC"
echo "" echo ""
echo " All configured domains:" echo " All configured domains:"
${domainSummary} ${domainSummary}
echo "" echo ""
printf "%b%s%b\n" "$YELLOW" " Rebuilding to activate services with new domains..." "$NC" printf "%b%s%b\n" "$YELLOW" " Rebuilding to activate services with new domains..." "$NC"
echo "" echo ""
nixos-rebuild switch --impure nixos-rebuild switch --flake /etc/nixos#nixos
''; '';
needsSetup = pkgs.writeShellScriptBin "sovran-domains-need-setup" '' needsSetup = pkgs.writeShellScriptBin "sovran-domains-need-setup" ''

View File

@@ -6,6 +6,7 @@
./core/roles.nix ./core/roles.nix
./core/role-logic.nix ./core/role-logic.nix
./core/caddy.nix ./core/caddy.nix
./core/njalla.nix
./core/sovran-manage.nix ./core/sovran-manage.nix
./core/sovran-manage-domains.nix ./core/sovran-manage-domains.nix