From b95b90f8c99c3a9c0182a3d0e454249cfb9dcbcc Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Tue, 21 Apr 2026 14:24:32 -0500 Subject: [PATCH] ci: add nix and lix parse checks Co-authored-by: Wolfgang Walther Co-authored-by: piegames --- .github/workflows/lint.yml | 3 ++- ci/parse.nix | 50 ++++++++++++++++++++++++++++++++++++++ flake/dev/default.nix | 1 + flake/dev/parse.nix | 16 ++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ci/parse.nix create mode 100644 flake/dev/parse.nix diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 26864370..2e5290ee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,6 @@ on: - "**.svg" - ".gitignore" - "LICENSE" - - "flake.lock" defaults: run: @@ -21,5 +20,7 @@ jobs: uses: actions/checkout@v6 - name: Install Nix uses: cachix/install-nix-action@v31 + - name: Run nix and Lix parse checks + run: nix build --show-trace --keep-going .#checks.x86_64-linux.parseNix .#checks.x86_64-linux.parseLix --accept-flake-config - name: Run treefmt check run: nix build .#checks.x86_64-linux.treefmt --accept-flake-config diff --git a/ci/parse.nix b/ci/parse.nix new file mode 100644 index 00000000..a30ff9aa --- /dev/null +++ b/ci/parse.nix @@ -0,0 +1,50 @@ +{ + lib, + nix, + pipeOperatorFlag, + runCommand, +}: +runCommand "nix-parse-${nix.name}" + { + nativeBuildInputs = [ nix ]; + nixvim = + with lib.fileset; + toSource { + root = ../.; + fileset = fileFilter (file: file.hasExt "nix") ../.; + }; + inherit pipeOperatorFlag; + } + '' + export HOME="$TMPDIR" + export XDG_CONFIG_HOME="$TMPDIR" + export NIX_CONF_DIR="$TMPDIR/nix-conf" + parseLog="$TMPDIR/nix-parse.log" + mkdir -p "$NIX_CONF_DIR" + : > "$NIX_CONF_DIR/nix.conf" + + export NIX_STORE_DIR="$TMPDIR/store" + export NIX_STATE_DIR="$TMPDIR/state" + nix-store --init + + cd "$nixvim" + + # This will only show the first parse error, not all of them. + # That's fine, because the other CI jobs will report in more detail. + # This job is about checking parsing across different + # implementations / versions, not about providing the best DX. + # Returning all parse errors requires significantly more resources. + if ! find . -type f -iname '*.nix' -print0 | xargs -0 -P "$(nproc)" nix-instantiate --extra-experimental-features "$pipeOperatorFlag" --parse > /dev/null 2> "$parseLog"; then + cat "$parseLog" >&2 + echo "Parse failed in nix-instantiate." >&2 + exit 1 + fi + + if grep -q "^warning:" "$parseLog"; then + cat "$parseLog" >&2 + echo "Failing due to warnings in stderr" >&2 + exit 1 + fi + + touch "$out" + '' diff --git a/flake/dev/default.nix b/flake/dev/default.nix index b3e15b8e..47261164 100644 --- a/flake/dev/default.nix +++ b/flake/dev/default.nix @@ -5,6 +5,7 @@ ./generate-all-maintainers ./git-hooks.nix ./package-tests.nix + ./parse.nix ./template-tests.nix ./tests.nix ]; diff --git a/flake/dev/parse.nix b/flake/dev/parse.nix new file mode 100644 index 00000000..84fb03ea --- /dev/null +++ b/flake/dev/parse.nix @@ -0,0 +1,16 @@ +_: { + perSystem = + { pkgs, ... }: + { + checks = { + parseNix = pkgs.callPackage ../../ci/parse.nix { + nix = pkgs.nixVersions.latest; + pipeOperatorFlag = "pipe-operators"; + }; + parseLix = pkgs.callPackage ../../ci/parse.nix { + nix = pkgs.lixPackageSets.latest.lix; + pipeOperatorFlag = "pipe-operator"; + }; + }; + }; +}