Files

66 lines
2.0 KiB
Nix

{ pkgs, package }:
# Flake checks that mirror the git hooks. The logic lives in dev/hooks/*.sh so
# the devenv hooks and these derivations cannot drift apart. The package's own
# build already runs `cargo test`, so no separate test check exists here. The
# VM tests stay in flake.nix.
let
inherit (pkgs) lib;
src = lib.cleanSource ../.;
# Everything the lint scripts shell out to. HOOKS_REQUIRE_TOOLS makes a
# missing tool a failure instead of a skip.
baseTools = with pkgs; [ bash coreutils findutils gnugrep gnused ];
lintTools = baseTools ++ (with pkgs; [
taplo
yamllint
shellcheck
markdownlint-cli
nushell
nix
]);
hookCheck = name: tools: script: pkgs.runCommand "slinuxm-${name}"
{
nativeBuildInputs = tools;
HOOKS_REQUIRE_TOOLS = "1";
}
''
export HOME=$TMPDIR NIX_STATE_DIR=$TMPDIR/nix-state NIX_LOG_DIR=$TMPDIR/nix-log
cp -r ${src} work
chmod -R u+w work
patchShebangs work/dev/hooks
cd work
${script}
touch $out
'';
# Rust checks reuse the package's vendored dependencies and build inputs.
rustCheck = name: phase: package.overrideAttrs (old: {
pname = "${old.pname}-${name}";
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ pkgs.clippy pkgs.rustfmt ];
doCheck = false;
dontCargoBuild = true;
dontCargoInstall = true;
dontCheckForBrokenSymlinks = true;
buildPhase = ''
runHook preBuild
${phase}
runHook postBuild
'';
installPhase = "touch $out";
});
in
{
hooks-lint = hookCheck "lint" lintTools "bash dev/hooks/run.sh lint-all";
hooks-selection = hookCheck "selection" baseTools "bash dev/hooks/test-select.sh";
rust-fmt = rustCheck "fmt" "cargo fmt --check";
rust-clippy = rustCheck "clippy" "cargo clippy --all-targets --offline -- -D warnings";
rust-no-openssl = rustCheck "no-openssl" ''
found=$(cargo tree --offline -i openssl 2>/dev/null || true)
if [ -n "$found" ]; then echo "$found"; echo "openssl is in the dependency tree"; exit 1; fi
'';
}