You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1 KiB

{ sshKeyFile, writeShellApplication, jq, git, ... }: writeShellApplication {
name = "release-host-branch";
runtimeInputs = [ jq git ];
text = ''
job="$(jq -r '.job' < "$HYDRA_JSON")"
outpath="$(jq -r '.outputs[] | select(.name == "out") | .path' < "$HYDRA_JSON")"
echo "Running for $job, built $outpath"
if [[ "$job" != "hosts."* ]]; then
echo "Not a NixOS Host job, skipping."
exit 0
fi
host="''${job##*.}"
commit="$(jq -r '.flakes[] | select(.from.id == "self") | .to.rev' "''${outpath}/etc/nix/registry.json")"
echo "System is $host at $commit"
# Start ssh-agent if nescessary
ssh-add || eval "$(ssh-agent)"
ssh-add ${sshKeyFile}
export GIT_SSH_COMMAND="ssh -A" # Forward agent
repo="/tmp/hydra/nix-config"
# Check if repo already exists
if git -C "$repo" rev-parse --git-dir &> /dev/null; then
git -C "$repo" fetch origin
else
mkdir -p "$repo"
git clone --bare git@m7.rs:nix-config "$repo"
fi
git -C "$repo" branch -f "release-$host" "$commit"
git -C "$repo" push -f origin "release-$host" -o "release-$host"
'';
}