Wire hooks into devenv and flake checks
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019dpKwZWtahQU4V2NhpVmLt
This commit is contained in:
1 parent
46c644ff2b
commit
0bddfbb063
4 files changed
+109
-1
No files matched your search
@@ -0,0 +1,38 @@
|
|||||||
|
# Git hooks. The checks themselves live in dev/hooks/ (shared with the Nix
|
||||||
|
# flake checks in nix/checks.nix); this file only wires them into git-hooks.
|
||||||
|
# Hooks install when a devenv shell is entered. See docs/hooks.md.
|
||||||
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
packages = [
|
||||||
|
pkgs.taplo
|
||||||
|
pkgs.yamllint
|
||||||
|
pkgs.shellcheck
|
||||||
|
pkgs.markdownlint-cli
|
||||||
|
pkgs.nushell
|
||||||
|
];
|
||||||
|
|
||||||
|
git-hooks.hooks = {
|
||||||
|
# Fast: fmt, clippy (Rust files only), lint, secret scan.
|
||||||
|
slinuxm-pre-commit = {
|
||||||
|
enable = true;
|
||||||
|
name = "slinuxm pre-commit";
|
||||||
|
entry = "dev/hooks/run.sh pre-commit";
|
||||||
|
language = "system";
|
||||||
|
pass_filenames = false;
|
||||||
|
always_run = true;
|
||||||
|
stages = [ "pre-commit" ];
|
||||||
|
};
|
||||||
|
# Path-filtered tests and slow checks. Skip one run with
|
||||||
|
# SKIP=slinuxm-pre-push git push (pre-commit framework variable).
|
||||||
|
slinuxm-pre-push = {
|
||||||
|
enable = true;
|
||||||
|
name = "slinuxm pre-push";
|
||||||
|
entry = "dev/hooks/run.sh pre-push";
|
||||||
|
language = "system";
|
||||||
|
pass_filenames = false;
|
||||||
|
always_run = true;
|
||||||
|
stages = [ "pre-push" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
imports = [ ./devenv.hooks.nix ];
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
pkgs.git
|
pkgs.git
|
||||||
pkgs.pkg-config
|
pkgs.pkg-config
|
||||||
|
|||||||
@@ -28,7 +28,10 @@
|
|||||||
module = self.nixosModules.default;
|
module = self.nixosModules.default;
|
||||||
};
|
};
|
||||||
|
|
||||||
checks.${system} = {
|
checks.${system} = import ./nix/checks.nix {
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
package = self.packages.${system}.default;
|
||||||
|
} // {
|
||||||
package = self.packages.${system}.default;
|
package = self.packages.${system}.default;
|
||||||
vm = import ./nix/tests/vm.nix {
|
vm = import ./nix/tests/vm.nix {
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
{ 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" ''
|
||||||
|
out=$(cargo tree --offline -i openssl 2>/dev/null || true)
|
||||||
|
if [ -n "$out" ]; then echo "$out"; echo "openssl is in the dependency tree"; exit 1; fi
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in new issue
Block a user