diff --git a/.github/workflows/check-nix-format.yml b/.github/workflows/check-nix-format.yml index 131803213cb5..5a3b7fe40cb9 100644 --- a/.github/workflows/check-nix-format.yml +++ b/.github/workflows/check-nix-format.yml @@ -19,13 +19,18 @@ jobs: with: # pull_request_target checks out the base branch by default ref: refs/pull/${{ github.event.pull_request.number }}/merge + - name: Get Nixpkgs revision for nixfmt + run: | + # pin to a commit from nixpkgs-unstable to avoid e.g. building nixfmt + # from staging + # This should not be a URL, because it would allow PRs to run arbitrary code in CI! + rev=$(jq -r .rev ci/pinned-nixpkgs.json) + echo "url=https://github.com/NixOS/nixpkgs/archive/$rev.tar.gz" >> "$GITHUB_ENV" - uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26 with: # explicitly enable sandbox extra_nix_config: sandbox = true - # fix a commit from nixpkgs-unstable to avoid e.g. building nixfmt - # from staging - nix_path: nixpkgs=https://github.com/NixOS/nixpkgs/archive/4b455dc2048f73a79eb3713f342369ff58f93e0b.tar.gz + nix_path: nixpkgs=${{ env.url }} - name: Install nixfmt run: "nix-env -f '' -iAP nixfmt-rfc-style" - name: Check that Nix files are formatted according to the RFC style diff --git a/ci/README.md b/ci/README.md index 79dc4b3bce71..64cd8e5bcea9 100644 --- a/ci/README.md +++ b/ci/README.md @@ -2,3 +2,11 @@ This directory contains files to support CI, such as [GitHub Actions](https://github.com/NixOS/nixpkgs/tree/master/.github/workflows) and [Ofborg](https://github.com/nixos/ofborg). This is in contrast with [`maintainers/scripts`](`../maintainers/scripts`) which is for human use instead. + +## Pinned Nixpkgs + +CI may need certain packages from Nixpkgs. +In order to ensure that the needed packages are generally available without building, +[`pinned-nixpkgs.json`](./pinned-nixpkgs.json) contains a pinned Nixpkgs version tested by Hydra. + +Run [`update-pinned-nixpkgs.sh`](./update-pinned-nixpkgs.sh) to update it. diff --git a/ci/pinned-nixpkgs.json b/ci/pinned-nixpkgs.json new file mode 100644 index 000000000000..29af1b022581 --- /dev/null +++ b/ci/pinned-nixpkgs.json @@ -0,0 +1,4 @@ +{ + "rev": "cfb89a95f19bea461fc37228dc4d07b22fe617c2", + "sha256": "1yhsacvry6j8r02lk70p9dphjpi8lpzgq2qay8hiy4nqlys0mrch" +} diff --git a/ci/update-pinned-nixpkgs.sh b/ci/update-pinned-nixpkgs.sh new file mode 100755 index 000000000000..776558130057 --- /dev/null +++ b/ci/update-pinned-nixpkgs.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p jq + +set -euo pipefail + +# https://stackoverflow.com/a/246128 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +repo=https://github.com/nixos/nixpkgs +branch=nixpkgs-unstable +file=$SCRIPT_DIR/pinned-nixpkgs.json + +rev=$(git ls-remote "$repo" refs/heads/"$branch" | cut -f1) +sha256=$(nix-prefetch-url --unpack "$repo/archive/$rev.tar.gz" --name source) + +jq -n --arg rev "$rev" --arg sha256 "$sha256" '$ARGS.named' | tee /dev/stderr > $file