This commit is contained in:
Lucas Thelen 2025-10-03 00:27:36 +00:00
parent b8455c491b
commit 82cd5fb545
2 changed files with 50 additions and 30 deletions

6
flake.lock generated
View file

@ -68,11 +68,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1758589230, "lastModified": 1759281824,
"narHash": "sha256-zMTCFGe8aVGTEr2RqUi/QzC1nOIQ0N1HRsbqB4f646k=", "narHash": "sha256-FIBE1qXv9TKvSNwst6FumyHwCRH3BlWDpfsnqRDCll0=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d1d883129b193f0b495d75c148c2c3a7d95789a0", "rev": "5b5be50345d4113d04ba58c444348849f5585b4a",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -5,8 +5,9 @@ let
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
HOSTED_ZONE_ID="Z09728753LLLNSYFXIBIM" # Get from Route 53 console HOSTED_ZONE_ID="Z09728753LLLNSYFXIBIM"
DOMAIN=${domain} DOMAIN="${domain}"
SUBDOMAIN="jellyfin.${domain}"
# Get current public IP # Get current public IP
CURRENT_IP=$(${pkgs.curl}/bin/curl -s https://ifconfig.me) CURRENT_IP=$(${pkgs.curl}/bin/curl -s https://ifconfig.me)
@ -17,11 +18,13 @@ let
exit 1 exit 1
fi fi
# Get current DNS record # Function to update a DNS record
DNS_IP=$(${pkgs.dig}/bin/dig +short "$DOMAIN" @8.8.8.8 | tail -n1) update_record() {
local RECORD_NAME=$1
local DNS_IP=$(${pkgs.dig}/bin/dig +short "$RECORD_NAME" @8.8.8.8 | tail -n1)
if [ "$CURRENT_IP" != "$DNS_IP" ]; then if [ "$CURRENT_IP" != "$DNS_IP" ]; then
echo "[$(date)] IP changed: $DNS_IP -> $CURRENT_IP" echo "[$(date)] $RECORD_NAME IP changed: $DNS_IP -> $CURRENT_IP"
${pkgs.awscli2}/bin/aws route53 change-resource-record-sets \ ${pkgs.awscli2}/bin/aws route53 change-resource-record-sets \
--hosted-zone-id "$HOSTED_ZONE_ID" \ --hosted-zone-id "$HOSTED_ZONE_ID" \
@ -29,7 +32,7 @@ let
\"Changes\": [{ \"Changes\": [{
\"Action\": \"UPSERT\", \"Action\": \"UPSERT\",
\"ResourceRecordSet\": { \"ResourceRecordSet\": {
\"Name\": \"$DOMAIN\", \"Name\": \"$RECORD_NAME\",
\"Type\": \"A\", \"Type\": \"A\",
\"TTL\": 300, \"TTL\": 300,
\"ResourceRecords\": [{\"Value\": \"$CURRENT_IP\"}] \"ResourceRecords\": [{\"Value\": \"$CURRENT_IP\"}]
@ -37,10 +40,15 @@ let
}] }]
}" }"
echo "[$(date)] DNS updated successfully to $CURRENT_IP" echo "[$(date)] $RECORD_NAME DNS updated successfully to $CURRENT_IP"
else else
echo "[$(date)] IP unchanged: $CURRENT_IP" echo "[$(date)] $RECORD_NAME IP unchanged: $CURRENT_IP"
fi fi
}
# Update both records
update_record "$DOMAIN"
update_record "$SUBDOMAIN"
''; '';
in { in {
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [ 80 443 ];
@ -54,11 +62,23 @@ in {
recommendedTlsSettings = true; recommendedTlsSettings = true;
virtualHosts."${domain}" = { virtualHosts."${domain}" = {
forceSSL = false; forceSSL = true;
enableACME = false; enableACME = true;
root = "${inputs.thelenlucas.packages.${pkgs.system}.default}"; root = "${inputs.thelenlucas.packages.${pkgs.system}.default}";
}; };
virtualHosts."jellyfin.${domain}" = {
forceSSL = true;
enableACME = true;
locations."/" = { proxyPass = "http://localhost:8096"; };
};
};
security.acme = {
acceptTerms = true;
defaults.email = "thelenlucas@gmail.com";
}; };
environment.systemPackages = [ pkgs.awscli2 ]; environment.systemPackages = [ pkgs.awscli2 ];