From e28f6401240aa97e31d7fe94d4c28a75a9738052 Mon Sep 17 00:00:00 2001 From: kurogeek Date: Thu, 23 Jul 2026 11:37:22 +0700 Subject: [PATCH] mob next [ci-skip] [ci skip] [skip ci] lastFile:inventories/default.nix --- inventories/default.nix | 66 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/inventories/default.nix b/inventories/default.nix index d5593e7..9de5fd7 100644 --- a/inventories/default.nix +++ b/inventories/default.nix @@ -59,7 +59,7 @@ roles.default.settings.interfaces = [ "ygg" ]; }; - auto-update = { + auto-pull-update = { module = { name = "dm-pull-deploy"; input = "clan-community"; @@ -68,6 +68,70 @@ gitUrl = "https://git.b4l.co.th/newedge/infra.git"; branch = "main"; }; + roles.push.extraModules = [ + ( + { pkgs, config, ... }: + { + + environment.systemPackages = [ + (pkgs.writeShellApplication { + name = "custom-dm-send-deploy"; + runtimeInputs = [ + config.services.data-mesher.package + pkgs.git + pkgs.nix + pkgs.jq + ]; + text = + let + settings.branch = "main"; + settings.gitUrl = "https://git.b4l.co.th/newedge/infra.git"; + in + '' + if [ $# -gt 1 ]; then + echo "Usage: dm-send-deploy []" + echo "Without arguments, sends the latest commit on '${settings.branch}' from ${settings.gitUrl}" + echo "Example: dm-send-deploy git+https://example.com/repo.git?rev=abc123..." + exit 1 + fi + + KEY="${config.clan.core.vars.generators.dm-pull-deploy-signing-key.files."signing.key".path}" + if [ ! -r "$KEY" ]; then + echo "Error: cannot read signing key at $KEY (are you root?)" + exit 1 + fi + + if [ $# -eq 1 ]; then + FLAKE_REF="$1" + else + REV=$(git ls-remote "${settings.gitUrl}" "refs/heads/${settings.branch}" | cut -f1) + if [ -z "$REV" ]; then + echo "Error: could not determine latest commit on ${settings.branch} from ${settings.gitUrl}" + exit 1 + fi + FLAKE_REF="git+${settings.gitUrl}?rev=$REV" + fi + + TMPFILE=$(mktemp) + trap 'rm -f "$TMPFILE"' EXIT + + printf '%s' "$FLAKE_REF" > "$TMPFILE" + + NETWORK_ID="${config.clan.core.vars.generators.data-mesher-network.files."network.pub".path}" + + data-mesher file update "$TMPFILE" \ + --url http://localhost:7331 \ + --network-id "$NETWORK_ID" \ + --key "$KEY" \ + --name "dm_pull_deploy/target" + + echo "Deployment target pushed: $FLAKE_REF" + ''; + }) + ]; + } + ) + ]; roles.default.tags = [ "all" ]; roles.default.settings.action = "switch"; };