Files
nixpkgs/.github/workflows/mirror-nixpkgs.yml
T
2026-08-27 12:27:39 +08:00

46 lines
1.5 KiB
YAML

name: Mirror Nixpkgs Branches
on:
schedule:
- cron: "17 13 * * 2"
workflow_dispatch:
permissions:
contents: write
jobs:
mirror:
runs-on: ubuntu-latest
steps:
- name: Mirror upstream branches
env:
NIX_BRANCH_TOKEN: ${{ secrets.NIX_BRANCH_TOKEN }}
TARGET_REPOSITORY: ${{ github.repository }}
run: |
set -euo pipefail
: "${NIX_BRANCH_TOKEN:?Set the NIX_BRANCH_TOKEN repository secret.}"
for branch in nixos-26.05 nixos-unstable; do
archive="$(mktemp)"
checkout="$(mktemp -d)"
trap 'rm -f "$archive"; rm -rf "$checkout"' EXIT
curl --fail --location --retry 3 \
"https://codeload.github.com/NixOS/nixpkgs/tar.gz/refs/heads/$branch" \
--output "$archive"
tar --extract --gzip --file "$archive" --strip-components=1 --directory "$checkout"
git -C "$checkout" init
git -C "$checkout" config user.name "github-actions[bot]"
git -C "$checkout" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C "$checkout" add --all
git -C "$checkout" commit --message "Snapshot of NixOS/nixpkgs $branch"
git -C "$checkout" remote add target \
"https://x-access-token:${NIX_BRANCH_TOKEN}@github.com/${TARGET_REPOSITORY}.git"
git -C "$checkout" push --force target "HEAD:refs/heads/$branch"
rm -f "$archive"
rm -rf "$checkout"
trap - EXIT
done