remove subdomain without root sub

This commit is contained in:
satr14washere 2026-03-21 18:54:34 +07:00
commit 1c473875f1
4 changed files with 134 additions and 9 deletions

View file

@ -1,9 +0,0 @@
{
"owner": {
"username": "hanmetaforce",
"discord": "917913229668274186"
},
"record": {
"TXT": ["dh=8c752ee2abcc39a26557a464a8a2401c635c374a"]
}
}

60
flake.lock generated Normal file
View file

@ -0,0 +1,60 @@
{
"nodes": {
"dns": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1768143854,
"narHash": "sha256-E5/kyPz4zAZn/lZdvqlF83jMgCWNxmqYjjWuadngCbk=",
"owner": "nix-community",
"repo": "dns.nix",
"rev": "a97cf4156e9f044fe4bed5be531061000dfabb07",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "dns.nix",
"type": "github"
}
},
"flake-utils": {
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1774086600,
"narHash": "sha256-zjWIPOLpA2yU1PvqaqZ99BP5IRuhTcMpHhw2uDT7lS8=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6de7809357a63167ebc0cb96d1200fa135f2df8b",
"type": "github"
},
"original": {
"owner": "NixOS",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"dns": "dns"
}
}
},
"root": "root",
"version": 7
}

32
flake.nix Normal file
View file

@ -0,0 +1,32 @@
{
description = "Zone File Generator For part-of.my.id";
inputs.dns.url = "github:nix-community/dns.nix";
outputs = { dns, ... }: let
email = "admin@satr14.my.id";
domains."0" = {
domain = "part-of.my.id";
nameservers = [
"adele.ns.cloudflare.com"
"fattouche.ns.cloudflare.com"
];
};
in {
packages.x86_64-linux = builtins.mapAttrs (_: domain:
dns.util.x86_64-linux.writeZone domain.domain (
with dns.lib.combinators; {
SOA = {
adminEmail = email;
nameServer = builtins.head domain.nameservers;
serial = builtins.currentTime;
};
NS = domain.nameservers;
# note: Cloudflare ignores SOA and NS records uploaded via Zone File, they are just so that dns.nix builds a valid zone file.
A = [ "1.1.1.1" ];
}
)
) domains;
};
}

42
scripts/deploy-apex.sh Normal file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
# script to deploy the APEX domain to Cloudflare with CNAME flattening
set -euo pipefail
ZONE_ID="${CF_ZONE_ID:?}"
TOKEN="${CF_API_TOKEN:?}"
TARGET="website-e7n.pages.dev"
EXISTING=$(curl -s \
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?type=CNAME&name=@" \
-H "Authorization: Bearer ${TOKEN}" \
| jq -r '.result[0] // empty')
EXISTING_CONTENT=$(echo "$EXISTING" | jq -r '.content // empty')
EXISTING_ID=$(echo "$EXISTING" | jq -r '.id // empty')
if [[ "$EXISTING_CONTENT" == "$TARGET" ]]; then
echo "Apex CNAME unchanged, skipping."
exit 0
fi
if [[ -z "$EXISTING_ID" ]]; then
echo "No apex CNAME found, creating..."
METHOD="POST"
URL="https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records"
else
echo "Apex CNAME changed ($EXISTING_CONTENT$TARGET), updating..."
METHOD="PUT"
URL="https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${EXISTING_ID}"
fi
curl -s -X "$METHOD" "$URL" \
-H "Authorization: Bearer ${TOKEN}" \
-H "Content-Type: application/json" \
--data "{
\"type\": \"CNAME\",
\"name\": \"@\",
\"content\": \"${TARGET}\",
\"proxied\": true
}" | jq -e '.success'