diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8f49a87d6e0a..6b9f0667397b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -78,6 +78,36 @@ jobs: # Tests multiple versions at once, let's make sure all of them run, so keep-going. nix-build nixpkgs/untrusted/ci --arg nixpkgs ./nixpkgs/untrusted-pinned -A parse --keep-going + redirects: + runs-on: ubuntu-24.04-arm + timeout-minutes: 10 + steps: + - name: Checkout merge and target commits + uses: $/.github/actions/checkout + with: + merged-as-untrusted-at: ${{ inputs.mergedSha }} + target-as-trusted-at: ${{ inputs.targetSha }} + + - uses: cachix/install-nix-action@3dc140bfc76c49fbd4dd958429132e3746bcb086 # v31.11.5 + + - uses: cachix/cachix-action@ae1cbf444b9889291590b7d87f4b676406df16aa # v17 + continue-on-error: true + with: + # The nixpkgs-gha cache should not be trusted or used outside of Nixpkgs and its forks' CI. + name: ${{ vars.CACHIX_NAME || 'nixpkgs-gha' }} + extraPullNames: nixpkgs-gha + authToken: ${{ secrets.CACHIX_AUTH_TOKEN_GHA }} + pushFilter: -source$ + + - name: Check manual redirect URLs are preserved + run: | + nix-build nixpkgs/untrusted/ci --arg nixpkgs ./nixpkgs/untrusted-pinned \ + -A redirects-nixpkgs \ + -A redirects-nixos \ + --arg base ./nixpkgs/trusted \ + --arg head ./nixpkgs/untrusted \ + --keep-going + nixpkgs-vet: runs-on: ubuntu-24.04-arm timeout-minutes: 10 diff --git a/ci/default.nix b/ci/default.nix index cb5dee81b465..94757ef8cbc1 100644 --- a/ci/default.nix +++ b/ci/default.nix @@ -75,6 +75,12 @@ rec { nixpkgs-vet = pkgs.callPackage ./nixpkgs-vet.nix { nix = pkgs.nixVersions.latest; }; + redirects-nixpkgs = pkgs.callPackage ./redirects-check.nix { + redirectsFile = "doc/redirects.json"; + }; + redirects-nixos = pkgs.callPackage ./redirects-check.nix { + redirectsFile = "nixos/doc/manual/redirects.json"; + }; parse = pkgs.lib.recurseIntoAttrs { nix_latest = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.latest; }; stable = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.stable; }; diff --git a/ci/redirects-check.nix b/ci/redirects-check.nix new file mode 100644 index 000000000000..bb4166c226d6 --- /dev/null +++ b/ci/redirects-check.nix @@ -0,0 +1,40 @@ +{ + lib, + jq, + runCommand, + writeText, + redirectsFile, +}: +{ + base, + head, +}: +let + help = writeText "redirects-check-help" '' + Please don't remove old URLs, since this will break links and bookmarks. + Redirect them to a different anchor, such as a release note mentioning the removal. + + To avoid manual book keeping, inside `nix-shell ${dirOf redirectsFile}` run: + redirects remove-and-redirect + ''; + + redirects = + root: + lib.fileset.toSource { + inherit root; + fileset = lib.path.append root redirectsFile; + }; +in +runCommand "redirects-check" { nativeBuildInputs = [ jq ]; } '' + removed=$(comm -23 \ + <(jq -r '.[][]' "${redirects base}/${redirectsFile}" | sort -u) \ + <(jq -r '.[][]' "${redirects head}/${redirectsFile}" | sort -u)) + if [ -n "$removed" ]; then + cat ${help} + echo + echo "URLs removed from ${redirectsFile}:" + while IFS= read -r url; do echo " $url"; done <<< "$removed" + exit 1 + fi + touch $out +'' diff --git a/pkgs/by-name/ni/nixos-render-docs/README.md b/pkgs/by-name/ni/nixos-render-docs/README.md index 5c8742765582..f802b3b83315 100644 --- a/pkgs/by-name/ni/nixos-render-docs/README.md +++ b/pkgs/by-name/ni/nixos-render-docs/README.md @@ -28,6 +28,9 @@ This allows us to catch: - Content that was moved from one location to another - Various consistency errors in the redirects mapping +Additionally, we have a [CI check](../../../../ci/redirects-check.nix) that ensures no URLs are removed from the redirects files. +As a result, external links to the Nixpkgs and NixOS manuals never break. + ### Design considerations The creation, movement, and removal of every identifier is captured in the Git history.