2024-03-27 22:48:59 +00:00
|
|
|
# This file was copied mostly from check-maintainers-sorted.yaml.
|
|
|
|
# NOTE: Formatting with the RFC-style nixfmt command is not yet stable. See
|
|
|
|
# https://github.com/NixOS/rfcs/pull/166.
|
|
|
|
# Because of this, this action is not yet enabled for all files -- only for
|
|
|
|
# those who have opted in.
|
|
|
|
name: Check that Nix files are formatted
|
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request_target:
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
nixos:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.repository_owner == 'NixOS'
|
|
|
|
steps:
|
2024-06-29 23:01:52 +01:00
|
|
|
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
2024-03-27 22:48:59 +00:00
|
|
|
with:
|
|
|
|
# pull_request_target checks out the base branch by default
|
|
|
|
ref: refs/pull/${{ github.event.pull_request.number }}/merge
|
2024-06-25 23:52:13 +01:00
|
|
|
- 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"
|
2024-03-27 22:48:59 +00:00
|
|
|
- uses: cachix/install-nix-action@8887e596b4ee1134dae06b98d573bd674693f47c # v26
|
|
|
|
with:
|
|
|
|
# explicitly enable sandbox
|
|
|
|
extra_nix_config: sandbox = true
|
2024-06-25 23:52:13 +01:00
|
|
|
nix_path: nixpkgs=${{ env.url }}
|
2024-03-27 22:48:59 +00:00
|
|
|
- name: Install nixfmt
|
2024-04-03 18:57:03 +01:00
|
|
|
run: "nix-env -f '<nixpkgs>' -iAP nixfmt-rfc-style"
|
2024-03-27 22:48:59 +00:00
|
|
|
- name: Check that Nix files are formatted according to the RFC style
|
|
|
|
# Each environment variable beginning with NIX_FMT_PATHS_ is a list of
|
|
|
|
# paths to check with nixfmt.
|
|
|
|
env:
|
2024-05-06 20:04:27 +01:00
|
|
|
NIX_FMT_PATHS_BSD: pkgs/os-specific/bsd
|
2024-04-30 19:05:16 +01:00
|
|
|
NIX_FMT_PATHS_MPVSCRIPTS: pkgs/applications/video/mpv/scripts
|
2024-03-27 22:48:59 +00:00
|
|
|
# Format paths related to the Nixpkgs CUDA ecosystem.
|
2024-06-26 00:37:20 +01:00
|
|
|
NIX_FMT_PATHS_CUDA: |-
|
2024-03-27 22:48:59 +00:00
|
|
|
pkgs/development/cuda-modules
|
|
|
|
pkgs/test/cuda
|
|
|
|
pkgs/top-level/cuda-packages.nix
|
2024-06-26 00:37:20 +01:00
|
|
|
NIX_FMT_PATHS_MAINTAINERS: |-
|
2024-06-18 01:59:36 +01:00
|
|
|
maintainers/maintainer-list.nix
|
|
|
|
maintainers/team-list.nix
|
2024-06-26 00:37:20 +01:00
|
|
|
NIX_FMT_PATHS_K3S: |-
|
2024-05-07 18:59:02 +01:00
|
|
|
nixos/modules/services/cluster/k3s
|
|
|
|
nixos/tests/k3s
|
|
|
|
pkgs/applications/networking/cluster/k3s
|
2024-05-01 10:58:43 +01:00
|
|
|
NIX_FMT_PATHS_VSCODE_EXTS: pkgs/applications/editors/vscode/extensions
|
|
|
|
NIX_FMT_PATHS_PHP_PACKAGES: pkgs/development/php-packages
|
|
|
|
NIX_FMT_PATHS_BUILD_SUPPORT_PHP: pkgs/build-support/php
|
2024-03-27 22:48:59 +00:00
|
|
|
# Iterate over all environment variables beginning with NIX_FMT_PATHS_.
|
|
|
|
run: |
|
2024-06-26 00:08:17 +01:00
|
|
|
unformattedPaths=()
|
2024-03-27 22:48:59 +00:00
|
|
|
for env_var in "${!NIX_FMT_PATHS_@}"; do
|
|
|
|
readarray -t paths <<< "${!env_var}"
|
|
|
|
if [[ "${paths[*]}" == "" ]]; then
|
|
|
|
echo "Error: $env_var is empty."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Checking paths: ${paths[@]}"
|
|
|
|
if ! nixfmt --check "${paths[@]}"; then
|
2024-06-26 00:08:17 +01:00
|
|
|
unformattedPaths+=("${paths[@]}")
|
2024-03-27 22:48:59 +00:00
|
|
|
fi
|
|
|
|
done
|
2024-06-26 00:08:17 +01:00
|
|
|
if (( "${#unformattedPaths[@]}" > 0 )); then
|
|
|
|
echo "Some required Nix files are not properly formatted"
|
|
|
|
echo "Please run the following in \`nix-shell\`:"
|
|
|
|
echo "nixfmt ${unformattedPaths[*]@Q}"
|
|
|
|
exit 1
|
|
|
|
fi
|