Switch to a multihost/home-manager setup

This commit is contained in:
2026-07-07 06:45:07 +01:00
parent 2d21314705
commit f8a8083a07
19 changed files with 388 additions and 390 deletions
+33
View File
@@ -0,0 +1,33 @@
#!@bash@/bin/bash
source /run/secrets/main.env
cache=/var/lib/cloudflare-ddns/old_ip
IP=$(@curl@/bin/curl -s 'https://api.ipify.org')
arr=("" "git." "www." "acs.")
if [[ -f "$cache" ]]; then
old_ip=$(cat "$cache")
else
old_ip=""
fi
if [[ "$IP" != "$old_ip" ]]; then
for sub in "${arr[@]}"; do
RECORD_ID=$(@curl@/bin/curl -s -X GET \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
| @jq@/bin/jq -r ".result[] | select(.name==\"${sub}syedm.dev\" and .type==\"A\") | .id")
if [ -n "$RECORD_ID" ]; then
@curl@/bin/curl -s -X PUT \
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"type\":\"A\",\"name\":\"${sub}syedm.dev\",\"content\":\"$IP\",\"ttl\":3600,\"proxied\":false}"
fi
done
echo "$IP" > "$cache"
fi
+40
View File
@@ -0,0 +1,40 @@
{ config, pkgs, ... }:
let
script = pkgs.replaceVars ./ddns.sh {
bash = pkgs.bash;
curl = pkgs.curl;
jq = pkgs.jq;
};
cloudflare-ddns = pkgs.writeShellScriptBin "cloudflare-ddns" (builtins.readFile script);
in
{
environment.systemPackages = [ cloudflare-ddns ];
systemd.services.cloudflare-ddns = {
description = "Cloudflare DDNS updater";
serviceConfig = {
Type = "oneshot";
User = "root";
};
script = "${cloudflare-ddns}/bin/cloudflare-ddns";
};
systemd.timers.cloudflare-ddns = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "2min";
OnUnitActiveSec = "5min";
Persistent = true;
};
};
systemd.tmpfiles.rules = [
"d /var/lib/cloudflare-ddns 0750 root root -"
];
}
+25
View File
@@ -0,0 +1,25 @@
{ ... }:
{
services.gitea = {
enable = true;
appName = "My personal projects.";
database.type = "sqlite3";
settings = {
server = {
DOMAIN = "git.syedm.dev";
ROOT_URL = "https://git.syedm.dev/";
HTTP_ADDR = "0.0.0.0";
HTTP_PORT = 3000;
SSH_DOMAIN = "git.syedm.dev";
SSH_PORT = 22;
};
service = {
DISABLE_REGISTRATION = true;
REQUIRE_SIGNIN_VIEW = false;
};
session.COOKIE_SECURE = true;
log.LEVEL = "Info";
};
};
}
+23
View File
@@ -0,0 +1,23 @@
{ ... }:
{
systemd.services.msjd = {
description = "Msjd";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
WorkingDirectory = "/home/me/main/msjd";
ExecStart = "${pkgs.nodejs}/bin/node index.mjs";
User = "me";
Restart = "always";
RestartSec = 3;
Environment = [
"NODE_ENV=production"
"PORT=3709"
];
};
};
}