ci: add nix and lix parse checks

Co-authored-by: Wolfgang Walther <walther@technowledgy.de>
Co-authored-by: piegames <git@piegames.de>
This commit is contained in:
Austin Horstman 2026-04-21 14:24:32 -05:00
parent 4efe04e747
commit b95b90f8c9
4 changed files with 69 additions and 1 deletions

View file

@ -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

50
ci/parse.nix Normal file
View file

@ -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"
''

View file

@ -5,6 +5,7 @@
./generate-all-maintainers
./git-hooks.nix
./package-tests.nix
./parse.nix
./template-tests.nix
./tests.nix
];

16
flake/dev/parse.nix Normal file
View file

@ -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";
};
};
};
}