fix: z2k deps + better ci
This commit is contained in:
8 files changed
+231
-40
No files matched your search
@@ -0,0 +1,14 @@
|
|||||||
|
# The workflows pin actions by commit SHA; Dependabot moves the SHA and its version
|
||||||
|
# comment together. Nix inputs and pinned sources are dependency-updates.yml's job.
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
day: monday
|
||||||
|
labels:
|
||||||
|
- dependencies
|
||||||
|
- github-actions
|
||||||
|
commit-message:
|
||||||
|
prefix: "chore(ci)"
|
||||||
@@ -25,7 +25,9 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
outputs:
|
outputs:
|
||||||
has_changes: ${{ steps.changes.outputs.has_changes }}
|
has_changes: ${{ steps.changes.outputs.has_changes }}
|
||||||
checks_failed: ${{ steps.checks.outputs.failed }}
|
# A skipped pin, failed package build or failed check: the pull request opens as a
|
||||||
|
# draft and the run ends red.
|
||||||
|
failed: ${{ (steps.pins.outputs.skipped == 'true' || steps.builds.outputs.failed == 'true' || steps.checks.outputs.failed == 'true') && 'true' || 'false' }}
|
||||||
steps:
|
steps:
|
||||||
# No token left in .git/config for the steps that run fetched code (flake updates,
|
# No token left in .git/config for the steps that run fetched code (flake updates,
|
||||||
# update-pins.sh, nix builds); create-pull-request authenticates on its own.
|
# update-pins.sh, nix builds); create-pull-request authenticates on its own.
|
||||||
@@ -55,15 +57,24 @@ jobs:
|
|||||||
else
|
else
|
||||||
echo "Skipping nixpkgs update: watched package versions on nixos-unstable are unchanged."
|
echo "Skipping nixpkgs update: watched package versions on nixos-unstable are unchanged."
|
||||||
fi
|
fi
|
||||||
nix flake update zapret
|
# Every other input, every run; update-pins.sh then refreshes the hashes of the
|
||||||
|
# sources that follow one (z2k-detect follows z2k).
|
||||||
|
nix flake update zapret z2k nfqws2-keenetic disko
|
||||||
|
|
||||||
|
# A pin that cannot be updated is put back and listed as "skipped"; the rest go through.
|
||||||
- name: Update pinned sources
|
- name: Update pinned sources
|
||||||
|
id: pins
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ github.token }}
|
GITHUB_TOKEN: ${{ github.token }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
scripts/update-pins.sh --self-test
|
scripts/update-pins.sh --self-test
|
||||||
scripts/update-pins.sh | tee "$RUNNER_TEMP/pin-updates.txt"
|
scripts/update-pins.sh | tee "$RUNNER_TEMP/pin-updates.txt"
|
||||||
|
if grep -q '^skipped ' "$RUNNER_TEMP/pin-updates.txt"; then
|
||||||
|
echo "skipped=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "skipped=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
# A nixpkgs bump can bring a nixfmt whose style differs; restyle the tree with
|
# A nixpkgs bump can bring a nixfmt whose style differs; restyle the tree with
|
||||||
# it so the nix-format check passes and the restyle rides along in the PR.
|
# it so the nix-format check passes and the restyle rides along in the PR.
|
||||||
@@ -80,12 +91,25 @@ jobs:
|
|||||||
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# One build per package, so a failure names it; like the checks, a failure makes the
|
||||||
|
# pull request a draft instead of holding the update back.
|
||||||
- name: Build updated packages
|
- name: Build updated packages
|
||||||
|
id: builds
|
||||||
if: steps.changes.outputs.has_changes == 'true'
|
if: steps.changes.outputs.has_changes == 'true'
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -uo pipefail
|
||||||
mapfile -t attrs < <(scripts/update-pins.sh --attrs)
|
mapfile -t attrs < <(scripts/update-pins.sh --attrs)
|
||||||
nix build --no-link "${attrs[@]}"
|
: > "$RUNNER_TEMP/failed-builds.txt"
|
||||||
|
for attr in "${attrs[@]}"; do
|
||||||
|
echo "::group::nix build ${attr}"
|
||||||
|
nix build --no-link --print-build-logs "$attr" || echo "${attr#.#}" >> "$RUNNER_TEMP/failed-builds.txt"
|
||||||
|
echo "::endgroup::"
|
||||||
|
done
|
||||||
|
if [[ -s "$RUNNER_TEMP/failed-builds.txt" ]]; then
|
||||||
|
echo "failed=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "failed=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
# A failing check does not hold the update back: the pull request opens as a draft
|
# A failing check does not hold the update back: the pull request opens as a draft
|
||||||
# naming the failures, and the run still ends red (open-pull-request's last step).
|
# naming the failures, and the run still ends red (open-pull-request's last step).
|
||||||
@@ -112,6 +136,8 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
SHOULD_UPDATE_NIXPKGS: ${{ steps.nixpkgs_gate.outputs.should_update_nixpkgs }}
|
SHOULD_UPDATE_NIXPKGS: ${{ steps.nixpkgs_gate.outputs.should_update_nixpkgs }}
|
||||||
CHANGED_WATCH_ATTRS: ${{ steps.nixpkgs_gate.outputs.nixpkgs_changed_watch_attrs }}
|
CHANGED_WATCH_ATTRS: ${{ steps.nixpkgs_gate.outputs.nixpkgs_changed_watch_attrs }}
|
||||||
|
PINS_SKIPPED: ${{ steps.pins.outputs.skipped }}
|
||||||
|
BUILDS_FAILED: ${{ steps.builds.outputs.failed }}
|
||||||
CHECKS_FAILED: ${{ steps.checks.outputs.failed }}
|
CHECKS_FAILED: ${{ steps.checks.outputs.failed }}
|
||||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||||
run: |
|
run: |
|
||||||
@@ -122,6 +148,9 @@ jobs:
|
|||||||
echo "Managed by CI; the \`ci/update-dependencies\` branch is reused across runs."
|
echo "Managed by CI; the \`ci/update-dependencies\` branch is reused across runs."
|
||||||
echo
|
echo
|
||||||
echo "### Pinned sources"
|
echo "### Pinned sources"
|
||||||
|
if [[ "$PINS_SKIPPED" == "true" ]]; then
|
||||||
|
echo "Some could not be updated and were kept, so this pull request is a draft ([run log]($RUN_URL))."
|
||||||
|
fi
|
||||||
if [[ -s "$RUNNER_TEMP/pin-updates.txt" ]]; then
|
if [[ -s "$RUNNER_TEMP/pin-updates.txt" ]]; then
|
||||||
sed 's/^/- /' "$RUNNER_TEMP/pin-updates.txt"
|
sed 's/^/- /' "$RUNNER_TEMP/pin-updates.txt"
|
||||||
else
|
else
|
||||||
@@ -131,7 +160,21 @@ jobs:
|
|||||||
echo "### Flake inputs"
|
echo "### Flake inputs"
|
||||||
echo "- nixpkgs updated: \`$SHOULD_UPDATE_NIXPKGS\`"
|
echo "- nixpkgs updated: \`$SHOULD_UPDATE_NIXPKGS\`"
|
||||||
echo "- changed watched attrs: \`$CHANGED_WATCH_ATTRS\`"
|
echo "- changed watched attrs: \`$CHANGED_WATCH_ATTRS\`"
|
||||||
echo "- zapret: refreshed every run"
|
# The locked revs that moved, against the checked-out lock file.
|
||||||
|
git show HEAD:flake.lock | jq -r --slurpfile new flake.lock '
|
||||||
|
.nodes as $old | $new[0].nodes | to_entries[]
|
||||||
|
| select(.value.locked.rev? != null)
|
||||||
|
| (.value.locked.rev) as $rev | ($old[.key].locked.rev // "none") as $prev
|
||||||
|
| select($rev != $prev)
|
||||||
|
| "- \(.key): `\($prev[0:7])` -> `\($rev[0:7])`"'
|
||||||
|
echo
|
||||||
|
echo "### Package builds"
|
||||||
|
if [[ "$BUILDS_FAILED" == "true" ]]; then
|
||||||
|
echo "Failed, so this pull request is a draft ([run log]($RUN_URL)):"
|
||||||
|
while IFS= read -r attr; do echo "- \`$attr\`"; done < "$RUNNER_TEMP/failed-builds.txt"
|
||||||
|
else
|
||||||
|
echo "- all built"
|
||||||
|
fi
|
||||||
echo
|
echo
|
||||||
echo "### Flake checks"
|
echo "### Flake checks"
|
||||||
if [[ "$CHECKS_FAILED" == "true" ]]; then
|
if [[ "$CHECKS_FAILED" == "true" ]]; then
|
||||||
@@ -170,9 +213,18 @@ jobs:
|
|||||||
${{ runner.temp }}/dependency-updates.md
|
${{ runner.temp }}/dependency-updates.md
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
|
# With nothing else to propose there is no pull request to carry a skipped pin.
|
||||||
- name: No dependency changes
|
- name: No dependency changes
|
||||||
if: steps.changes.outputs.has_changes != 'true'
|
if: steps.changes.outputs.has_changes != 'true'
|
||||||
run: echo "No dependency updates detected."
|
env:
|
||||||
|
PINS_SKIPPED: ${{ steps.pins.outputs.skipped }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
if [[ "$PINS_SKIPPED" == "true" ]]; then
|
||||||
|
grep '^skipped ' "$RUNNER_TEMP/pin-updates.txt" | sed 's/^/::error::/'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "No dependency updates detected."
|
||||||
|
|
||||||
open-pull-request:
|
open-pull-request:
|
||||||
needs: update-dependencies
|
needs: update-dependencies
|
||||||
@@ -210,7 +262,7 @@ jobs:
|
|||||||
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
||||||
with:
|
with:
|
||||||
# always-true also turns an open pull request back into a draft.
|
# always-true also turns an open pull request back into a draft.
|
||||||
draft: ${{ needs.update-dependencies.outputs.checks_failed == 'true' && 'always-true' || 'false' }}
|
draft: ${{ needs.update-dependencies.outputs.failed == 'true' && 'always-true' || 'false' }}
|
||||||
branch: ci/update-dependencies
|
branch: ci/update-dependencies
|
||||||
delete-branch: false
|
delete-branch: false
|
||||||
add-paths: |
|
add-paths: |
|
||||||
@@ -224,9 +276,9 @@ jobs:
|
|||||||
dependencies
|
dependencies
|
||||||
nix
|
nix
|
||||||
|
|
||||||
# draft: false leaves an existing draft alone; once the checks pass, mark it ready.
|
# draft: false leaves an existing draft alone; once nothing was skipped or failed, mark it ready.
|
||||||
- name: Mark the pull request ready for review
|
- name: Mark the pull request ready for review
|
||||||
if: needs.update-dependencies.outputs.checks_failed != 'true' && steps.pr.outputs.pull-request-operation == 'updated'
|
if: needs.update-dependencies.outputs.failed != 'true' && steps.pr.outputs.pull-request-operation == 'updated'
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
PR_NUMBER: ${{ steps.pr.outputs.pull-request-number }}
|
PR_NUMBER: ${{ steps.pr.outputs.pull-request-number }}
|
||||||
@@ -236,10 +288,10 @@ jobs:
|
|||||||
gh pr ready "$PR_NUMBER" --repo "$GITHUB_REPOSITORY"
|
gh pr ready "$PR_NUMBER" --repo "$GITHUB_REPOSITORY"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Fail the run on failed checks
|
- name: Fail the run on skipped pins, failed builds or checks
|
||||||
if: needs.update-dependencies.outputs.checks_failed == 'true'
|
if: needs.update-dependencies.outputs.failed == 'true'
|
||||||
env:
|
env:
|
||||||
PR_URL: ${{ steps.pr.outputs.pull-request-url }}
|
PR_URL: ${{ steps.pr.outputs.pull-request-url }}
|
||||||
run: |
|
run: |
|
||||||
echo "::error::Flake checks failed; the update is a draft pull request: $PR_URL"
|
echo "::error::Pins were skipped, or package builds or flake checks failed; the update is a draft pull request: $PR_URL"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -146,6 +146,7 @@
|
|||||||
tg-ws-proxy
|
tg-ws-proxy
|
||||||
whitelist-bypass
|
whitelist-bypass
|
||||||
wireproxy-awg
|
wireproxy-awg
|
||||||
|
z2k-detect
|
||||||
zapret2
|
zapret2
|
||||||
;
|
;
|
||||||
xray = import ./pkgs/xray.nix { inherit pkgs; };
|
xray = import ./pkgs/xray.nix { inherit pkgs; };
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ let
|
|||||||
lib
|
lib
|
||||||
pkgs
|
pkgs
|
||||||
cfg
|
cfg
|
||||||
|
packages
|
||||||
zapret2Sources
|
zapret2Sources
|
||||||
nft
|
nft
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
cfg,
|
cfg,
|
||||||
|
packages,
|
||||||
zapret2Sources,
|
zapret2Sources,
|
||||||
nft,
|
nft,
|
||||||
}:
|
}:
|
||||||
@@ -29,16 +30,8 @@ let
|
|||||||
lib.optional zapretGlobalEnabled "proxy-suite-zapret.service"
|
lib.optional zapretGlobalEnabled "proxy-suite-zapret.service"
|
||||||
++ lib.optional cfg.perAppRouting.zapret.enable "proxy-suite-per-app-zapret.service";
|
++ lib.optional cfg.perAppRouting.zapret.enable "proxy-suite-per-app-zapret.service";
|
||||||
|
|
||||||
z2kDetect = pkgs.buildGoModule {
|
# The z2k flake.lock holds, whatever `z2k` the consumer passes (pkgs/z2k-detect.nix).
|
||||||
pname = "z2k-detect";
|
z2kDetect = packages.z2k-detect;
|
||||||
version = "0-unstable-${z2k.shortRev or "local"}";
|
|
||||||
src = "${z2k}/z2k-detect";
|
|
||||||
vendorHash = "sha256-9Qv6O6/8MP9N44GPSDULEV/NcrHdEC3YZmIQmpaa1nE=";
|
|
||||||
subPackages = [ "cmd/z2k-detect" ];
|
|
||||||
# Its tests open raw sockets and dial out.
|
|
||||||
doCheck = false;
|
|
||||||
meta.mainProgram = "z2k-detect";
|
|
||||||
};
|
|
||||||
|
|
||||||
# $1 asn.txt, $2 sni.txt, $3 AS-to-prefix map; prints a sing-box source rule-set
|
# $1 asn.txt, $2 sni.txt, $3 AS-to-prefix map; prints a sing-box source rule-set
|
||||||
# with the prefixes of every cut-off network that no whitelisted name fixes.
|
# with the prefixes of every cut-off network that no whitelisted name fixes.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ let
|
|||||||
mkTgWsProxy = _args: import ./tg-ws-proxy.nix { inherit pkgs; };
|
mkTgWsProxy = _args: import ./tg-ws-proxy.nix { inherit pkgs; };
|
||||||
zapret2 = import ./zapret2.nix { inherit pkgs; };
|
zapret2 = import ./zapret2.nix { inherit pkgs; };
|
||||||
whitelist-bypass = import ./whitelist-bypass.nix { inherit pkgs; };
|
whitelist-bypass = import ./whitelist-bypass.nix { inherit pkgs; };
|
||||||
|
z2k-detect = import ./z2k-detect.nix { inherit pkgs; };
|
||||||
mkProxySuiteSupervisor = import ./proxy-suite-supervisor.nix {
|
mkProxySuiteSupervisor = import ./proxy-suite-supervisor.nix {
|
||||||
lib = pkgs.lib;
|
lib = pkgs.lib;
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
@@ -24,6 +25,7 @@ in
|
|||||||
mkProxySuiteSupervisor
|
mkProxySuiteSupervisor
|
||||||
zapret2
|
zapret2
|
||||||
whitelist-bypass
|
whitelist-bypass
|
||||||
|
z2k-detect
|
||||||
;
|
;
|
||||||
tg-ws-proxy = mkTgWsProxy { };
|
tg-ws-proxy = mkTgWsProxy { };
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
# z2k-detect, the 16 KB cutoff probe's Go side, at the z2k rev flake.lock holds. It is
|
||||||
|
# built from its own checkout, not from the module's `z2k` input: a consumer that
|
||||||
|
# supplies its own z2k (lon, npins, `follows`) would otherwise change go.sum under the
|
||||||
|
# pinned vendorHash. It talks to the lists and Lua only through the TSV maps.
|
||||||
|
#
|
||||||
|
# The rev comes from flake.lock; scripts/update-pins.sh refreshes hash and vendorHash
|
||||||
|
# after a z2k bump. The rev in the name keeps a store that still holds the previous
|
||||||
|
# checkout from reusing it under a stale hash.
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
let
|
||||||
|
locked = (pkgs.lib.importJSON ../flake.lock).nodes.z2k.locked;
|
||||||
|
shortRev = builtins.substring 0 7 locked.rev;
|
||||||
|
in
|
||||||
|
pkgs.buildGoModule (finalAttrs: {
|
||||||
|
pname = "z2k-detect";
|
||||||
|
version = "0-unstable-${shortRev}";
|
||||||
|
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
name = "z2k-detect-source-${shortRev}";
|
||||||
|
inherit (locked) owner repo rev;
|
||||||
|
sparseCheckout = [ "z2k-detect" ];
|
||||||
|
hash = "sha256-eagnkmLgZfa4Qc2UkhBHO721iWTdKnqzPGHKLcphJtY=";
|
||||||
|
};
|
||||||
|
sourceRoot = "${finalAttrs.src.name}/z2k-detect";
|
||||||
|
vendorHash = "sha256-9Qv6O6/8MP9N44GPSDULEV/NcrHdEC3YZmIQmpaa1nE=";
|
||||||
|
|
||||||
|
subPackages = [ "cmd/z2k-detect" ];
|
||||||
|
# Its tests open raw sockets and dial out.
|
||||||
|
doCheck = false;
|
||||||
|
|
||||||
|
meta.mainProgram = "z2k-detect";
|
||||||
|
})
|
||||||
+113
-18
@@ -8,8 +8,14 @@
|
|||||||
# that must stay in lockstep.
|
# that must stay in lockstep.
|
||||||
# flake-attr package built to recompute vendorHash; "-" when there is none.
|
# flake-attr package built to recompute vendorHash; "-" when there is none.
|
||||||
#
|
#
|
||||||
|
# LOCKED_PINS are sources whose rev comes from a flake.lock input, so `nix flake update`
|
||||||
|
# moves them: their hash and vendorHash are refreshed when the source no longer matches.
|
||||||
|
# Table columns: nix-file|flake-input|flake-attr.
|
||||||
|
#
|
||||||
# Prints one "updated <repo>: <old> -> <new>" line per change on stdout; progress
|
# Prints one "updated <repo>: <old> -> <new>" line per change on stdout; progress
|
||||||
# and errors go to stderr. `--attrs` lists the flake attrs instead.
|
# and errors go to stderr. A pin whose update fails (no tarball, no vendorHash to read
|
||||||
|
# from the build) is put back as it was and printed as a "skipped <name>: <reason>"
|
||||||
|
# line instead; the others still go through. `--attrs` lists the flake attrs instead.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
PINS=(
|
PINS=(
|
||||||
@@ -17,15 +23,26 @@ PINS=(
|
|||||||
"pkgs/zapret2.nix|bol-van|zapret2|version|zapret2"
|
"pkgs/zapret2.nix|bol-van|zapret2|version|zapret2"
|
||||||
"pkgs/xray.nix|XTLS|Xray-core|version|xray"
|
"pkgs/xray.nix|XTLS|Xray-core|version|xray"
|
||||||
"pkgs/whitelist-bypass.nix|kulikov0|whitelist-bypass|version|whitelist-bypass"
|
"pkgs/whitelist-bypass.nix|kulikov0|whitelist-bypass|version|whitelist-bypass"
|
||||||
|
"pkgs/wireproxy-awg.nix|artem-russkikh|wireproxy-awg|version|wireproxy-awg"
|
||||||
|
)
|
||||||
|
|
||||||
|
LOCKED_PINS=(
|
||||||
|
"pkgs/z2k-detect.nix|z2k|z2k-detect"
|
||||||
)
|
)
|
||||||
|
|
||||||
FAKE_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
FAKE_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
||||||
|
|
||||||
if [[ "${1:-}" == "--attrs" ]]; then
|
if [[ "${1:-}" == "--attrs" ]]; then
|
||||||
for pin in "${PINS[@]}"; do
|
{
|
||||||
IFS='|' read -r _ _ _ _ attr <<<"$pin"
|
for pin in "${PINS[@]}"; do
|
||||||
[[ "$attr" == "-" ]] || printf '.#%s\n' "$attr"
|
IFS='|' read -r _ _ _ _ attr <<<"$pin"
|
||||||
done | sort -u
|
[[ "$attr" == "-" ]] || printf '.#%s\n' "$attr"
|
||||||
|
done
|
||||||
|
for pin in "${LOCKED_PINS[@]}"; do
|
||||||
|
IFS='|' read -r _ _ attr <<<"$pin"
|
||||||
|
printf '.#%s\n' "$attr"
|
||||||
|
done
|
||||||
|
} | sort -u
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -109,7 +126,7 @@ refresh_vendor_hash() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
set_attr "$file" "$repo" vendorHash "$got"
|
set_attr "$file" "$repo" vendorHash "$got"
|
||||||
echo "updated ${repo} vendorHash: ${got}"
|
echo "updated ${repo:-$attr} vendorHash: ${got}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,47 +172,125 @@ fi
|
|||||||
|
|
||||||
declare -A BUMPED=()
|
declare -A BUMPED=()
|
||||||
|
|
||||||
for pin in "${PINS[@]}"; do
|
# One tag pin, in this shell so BUMPED sticks. Lines for stdout collect in PIN_OUT and
|
||||||
IFS='|' read -r file owner repo key attr <<<"$pin"
|
# are printed only once the whole pin went through; a failure sets SKIP_REASON and
|
||||||
[[ -f "$file" ]] || { echo "missing ${file}" >&2; exit 1; }
|
# returns 1, and the caller puts the file back.
|
||||||
|
update_pin() {
|
||||||
|
local file=$1 owner=$2 repo=$3 key=$4 attr=$5 current new tag tag_ref hash commit vendor
|
||||||
|
PIN_OUT="" SKIP_REASON=""
|
||||||
|
|
||||||
if [[ "$key" == =* ]]; then
|
if [[ "$key" == =* ]]; then
|
||||||
# Lockstep source: refetch only when the key it follows actually moved.
|
# Lockstep source: refetch only when the key it follows actually moved.
|
||||||
key=${key#=}
|
key=${key#=}
|
||||||
[[ -n "${BUMPED[$key]:-}" ]] || { echo "${repo}: follows ${key}, unchanged" >&2; continue; }
|
[[ -n "${BUMPED[$key]:-}" ]] || { echo "${repo}: follows ${key}, unchanged" >&2; return 0; }
|
||||||
new=$(get_key "$file" "$key")
|
new=$(get_key "$file" "$key")
|
||||||
current=$new
|
current=$new
|
||||||
else
|
else
|
||||||
current=$(get_key "$file" "$key")
|
current=$(get_key "$file" "$key")
|
||||||
[[ -n "$current" ]] || { echo "could not read ${key} from ${file}" >&2; exit 1; }
|
[[ -n "$current" ]] || { echo "could not read ${key} from ${file}" >&2; exit 1; }
|
||||||
tag=$(latest_tag "$owner" "$repo")
|
tag=$(latest_tag "$owner" "$repo") || { SKIP_REASON="could not list its tags"; return 1; }
|
||||||
# Keep whatever "v" convention the file already uses.
|
# Keep whatever "v" convention the file already uses.
|
||||||
if [[ "$current" == v* ]]; then new=$tag; else new=${tag#v}; fi
|
if [[ "$current" == v* ]]; then new=$tag; else new=${tag#v}; fi
|
||||||
if [[ "$current" == "$new" ]]; then
|
if [[ "$current" == "$new" ]]; then
|
||||||
echo "${repo}: already at ${current}" >&2
|
echo "${repo}: already at ${current}" >&2
|
||||||
continue
|
return 0
|
||||||
fi
|
fi
|
||||||
# These pins exist because they are ahead of nixpkgs; never walk one back.
|
# These pins exist because they are ahead of nixpkgs; never walk one back.
|
||||||
if [[ "$(newest "$current" "$new")" != "$new" ]]; then
|
if [[ "$(newest "$current" "$new")" != "$new" ]]; then
|
||||||
echo "${repo}: pinned ${current} is newer than upstream ${new}, keeping it" >&2
|
echo "${repo}: pinned ${current} is newer than upstream ${new}, keeping it" >&2
|
||||||
continue
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tag_ref=$new
|
tag_ref=$new
|
||||||
[[ "$tag_ref" == v* ]] || tag_ref="v${tag_ref}"
|
[[ "$tag_ref" == v* ]] || tag_ref="v${tag_ref}"
|
||||||
hash=$(nix store prefetch-file --json --unpack \
|
hash=$(nix store prefetch-file --json --unpack \
|
||||||
"https://github.com/${owner}/${repo}/archive/refs/tags/${tag_ref}.tar.gz" | jq -r '.hash')
|
"https://github.com/${owner}/${repo}/archive/refs/tags/${tag_ref}.tar.gz" | jq -r '.hash') || hash=""
|
||||||
[[ -n "$hash" && "$hash" != "null" ]] || { echo "could not hash ${repo} ${tag_ref}" >&2; exit 1; }
|
[[ -n "$hash" && "$hash" != "null" ]] || { SKIP_REASON="could not fetch ${tag_ref}, kept ${current}"; return 1; }
|
||||||
|
|
||||||
if [[ "$current" != "$new" ]]; then
|
if [[ "$current" != "$new" ]]; then
|
||||||
set_attr "$file" "" "$key" "$new" || { echo "could not write ${key} in ${file}" >&2; exit 1; }
|
set_attr "$file" "" "$key" "$new" || { echo "could not write ${key} in ${file}" >&2; exit 1; }
|
||||||
BUMPED[$key]=1
|
|
||||||
# The commit the tag names now, for the review: a moved tag shows up as a commit that
|
# The commit the tag names now, for the review: a moved tag shows up as a commit that
|
||||||
# is not on the project's history.
|
# is not on the project's history.
|
||||||
commit=$(gh_api "https://api.github.com/repos/${owner}/${repo}/commits/${tag_ref}" | jq -r '.sha // empty') || true
|
commit=$(gh_api "https://api.github.com/repos/${owner}/${repo}/commits/${tag_ref}" | jq -r '.sha // empty') || true
|
||||||
echo "updated ${repo}: ${current} -> ${new} (commit ${commit:-unknown})"
|
PIN_OUT+="updated ${repo}: ${current} -> ${new} (commit ${commit:-unknown})"$'\n'
|
||||||
fi
|
fi
|
||||||
set_attr "$file" "$repo" hash "$hash" || { echo "could not write hash for ${repo}" >&2; exit 1; }
|
set_attr "$file" "$repo" hash "$hash" || { echo "could not write hash for ${repo}" >&2; exit 1; }
|
||||||
refresh_vendor_hash "$file" "$repo" "$attr"
|
vendor=$(refresh_vendor_hash "$file" "$repo" "$attr") ||
|
||||||
|
{ SKIP_REASON="${new} does not build far enough to give its vendorHash, kept ${current}"; return 1; }
|
||||||
|
[[ -z "$vendor" ]] || PIN_OUT+="${vendor}"$'\n'
|
||||||
|
[[ "$current" == "$new" ]] || BUMPED[$key]=1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Locked sources: the fetch is named after the rev, so a moved input always refetches
|
||||||
|
# and a stale hash shows up as a mismatch here instead of reusing the old checkout.
|
||||||
|
update_locked_pin() {
|
||||||
|
local file=$1 input=$2 attr=$3 rev log got vendor
|
||||||
|
PIN_OUT="" SKIP_REASON=""
|
||||||
|
rev=$(jq -r --arg input "$input" '.nodes[$input].locked.rev // empty' flake.lock)
|
||||||
|
[[ -n "$rev" ]] || { echo "no locked rev for ${input} in flake.lock" >&2; exit 1; }
|
||||||
|
if log=$(nix build --no-link ".#${attr}.src" 2>&1); then
|
||||||
|
echo "${attr}: source matches ${input} ${rev:0:7}" >&2
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
got=$(grep -oE 'got: +sha256-[A-Za-z0-9+/]{43}=' <<<"$log" | grep -oE 'sha256-.*' | tail -n1)
|
||||||
|
if [[ -z "$got" ]]; then
|
||||||
|
echo "could not fetch the source of ${attr}:" >&2
|
||||||
|
tail -n 30 <<<"$log" >&2
|
||||||
|
SKIP_REASON="could not fetch ${input} ${rev:0:7}"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
set_attr "$file" "" hash "$got" || { echo "could not write hash in ${file}" >&2; exit 1; }
|
||||||
|
PIN_OUT+="updated ${attr}: source to ${input} ${rev:0:7}"$'\n'
|
||||||
|
vendor=$(refresh_vendor_hash "$file" "" "$attr") ||
|
||||||
|
{ SKIP_REASON="${input} ${rev:0:7} does not build far enough to give its vendorHash"; return 1; }
|
||||||
|
[[ -z "$vendor" ]] || PIN_OUT+="${vendor}"$'\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Put a locked input back at the committed rev, so the source and its hashes stay a
|
||||||
|
# matching pair. Only a node with no inputs of its own (a `flake = false` source) can be
|
||||||
|
# swapped alone; any other is left moved, and its package build fails in the open.
|
||||||
|
restore_locked_input() {
|
||||||
|
local input=$1 old tmp
|
||||||
|
old=$(git show HEAD:flake.lock 2>/dev/null | jq -c --arg input "$input" '.nodes[$input] // empty') || old=""
|
||||||
|
if [[ -z "$old" ]] || jq -e --arg input "$input" '.nodes[$input].inputs' flake.lock >/dev/null; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
tmp=$(mktemp)
|
||||||
|
jq --arg input "$input" --argjson old "$old" '.nodes[$input] = $old' flake.lock >"$tmp"
|
||||||
|
mv "$tmp" flake.lock
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot=$(mktemp)
|
||||||
|
trap 'rm -f "$snapshot"' EXIT
|
||||||
|
|
||||||
|
for pin in "${PINS[@]}"; do
|
||||||
|
IFS='|' read -r file owner repo key attr <<<"$pin"
|
||||||
|
[[ -f "$file" ]] || { echo "missing ${file}" >&2; exit 1; }
|
||||||
|
cp "$file" "$snapshot"
|
||||||
|
if update_pin "$file" "$owner" "$repo" "$key" "$attr"; then
|
||||||
|
printf '%s' "$PIN_OUT"
|
||||||
|
else
|
||||||
|
cp "$snapshot" "$file"
|
||||||
|
echo "${repo}: ${SKIP_REASON}" >&2
|
||||||
|
echo "skipped ${repo}: ${SKIP_REASON}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for pin in "${LOCKED_PINS[@]}"; do
|
||||||
|
IFS='|' read -r file input attr <<<"$pin"
|
||||||
|
[[ -f "$file" ]] || { echo "missing ${file}" >&2; exit 1; }
|
||||||
|
cp "$file" "$snapshot"
|
||||||
|
if update_locked_pin "$file" "$input" "$attr"; then
|
||||||
|
printf '%s' "$PIN_OUT"
|
||||||
|
else
|
||||||
|
cp "$snapshot" "$file"
|
||||||
|
if restore_locked_input "$input"; then
|
||||||
|
SKIP_REASON+=", kept ${input} at the committed rev"
|
||||||
|
else
|
||||||
|
SKIP_REASON+=", ${input} stays moved with stale hashes"
|
||||||
|
fi
|
||||||
|
echo "${attr}: ${SKIP_REASON}" >&2
|
||||||
|
echo "skipped ${attr}: ${SKIP_REASON}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
Reference in new issue
Block a user