Skip to content

Add flake checks (formatter, linters, secret scanner) + CI#3

Merged
myme merged 11 commits into
mainfrom
flake-checks
Jun 10, 2026
Merged

Add flake checks (formatter, linters, secret scanner) + CI#3
myme merged 11 commits into
mainfrom
flake-checks

Conversation

@myme

@myme myme commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

Wires up a "compliance" baseline for the dotfiles flake — formatter, linters, secret scanner, and CI. Same checks run from nix fmt, nix flake check, pre-push hook, and GitHub Actions.

  • treefmt-nix + nixfmt (RFC 166) for formatting (nix fmt)
  • cachix/git-hooks.nix with hooks: treefmt, statix (anti-patterns), deadnix (dead code), gitleaks (secrets)
  • Hooks fire on git push only (commits stay free; push is the gate); installed automatically by nix develop shellHook
  • aarch64-darwin added to supported systems; Linux-only outputs (deploy/xmonad shells, packages, apps) gated with lib.optionalAttrs
  • Treewide reformat + statix/deadnix auto-fixes + manual restructuring of repeated attribute keys (W20)
  • GH Actions: nix flake check on PRs to main; weekly flake.lock PR via DeterminateSystems/update-flake-lock
  • gitleaks uses --no-git so it scans the working tree, not 1900 commits of history (which surfaced old deleted files like davmail config and ancient npmrc tokens on every push)

Known unrelated issue

nixosConfigurations.map fails nix flake check with two pre-existing nixpkgs-unstable deprecations unrelated to this change:

  • systemd.sleep.extraConfig → must move to systemd.sleep.settings.Sleep
  • networking.resolvconf.enable = true conflicts with environment.etc."resolv.conf" being set

CI will surface this. Worth a separate follow-up commit to fix in modules/sleep.nix and machines/map/default.nix.

myme added 11 commits June 9, 2026 22:17
Wire treefmt-nix (nixfmt) and cachix/git-hooks.nix into the flake so
`nix fmt`, `nix flake check`, and pre-push hooks all share one config:

- nixfmt via treefmt-nix (`nix fmt`, treefmt.nix)
- statix (Nix anti-patterns) and deadnix (dead code) hooks
- gitleaks secret scanner as a custom hook reading .gitleaks.toml
- pre-commit-check installed as a pre-push hook on `nix develop`
- aarch64-darwin added to per-system outputs so checks run on macOS;
  Linux-only outputs (deploy/xmonad shells, packages, apps) gated
- GH Actions workflows: nix flake check on PRs, weekly flake.lock PR
Idiomatic Nix rewrites from `statix fix`:
- `if x ? y then x.y else default` → `x.y or default`
- `{ x = x; ... }` → `{ inherit x; ... }`
- `{ ... }:` → `_:` for unused argument patterns
- a few `let` binding cleanups
The default `gitleaks detect` scans the full git history, which surfaces
secrets from long-deleted files (davmail config, old .npmrc tokens, etc.)
on every push. For a pre-push hook the relevant scope is "what's about
to be sent", not the full audit. `--no-git` scans the working tree only.

History audit can still be run on demand: `gitleaks detect --source=.`.
Auto-fixes from `deadnix --edit`:
- Unused module function args (config, lib, pkgs, options, system) removed
  from modules that don't reference them
- Unused let bindings removed (is_stable in two places, removeHostname,
  unused lambda args in flake.nix, etc.)

Also drop `home-manager` from the overlay.nix call site in flake.nix —
deadnix removed it from overlay.nix's parameter list since it wasn't
used; the call site had to follow.
statix W20 flags split assignments to the same top-level key (e.g.
`services.foo = ...; services.bar = ...;`) and suggests nesting them
into a single attribute set (`services = { foo = ...; bar = ...; };`).

Applied across modules/, machines/, and home-manager/. Also collapses
an empty function pattern `{ ... }: ...` to `_: ...` in qemu-vm.nix.
CI on the new check workflow surfaced three real issues in existing
NixOS configurations:

- `systemd.sleep.extraConfig` is removed → use
  `systemd.sleep.settings.Sleep.HibernateDelaySec`
- `security.acme.defaults.credentialsFile` is renamed → use
  `environmentFile` (single env-file form, matches existing usage)
- `networking.resolvconf.enable` (default true) conflicts with
  `environment.etc."resolv.conf"` which is set by both NetworkManager
  and NixOS-WSL → disable globally
CI surfaced four more issues after the first round:

- `systemd.sleep.settings` is only declared when the standard systemd
  module is loaded — WSL skips that module → gate `modules/sleep.nix`
  config on `flavor != "wsl"`
- `pkgs.nodePackages.*` was removed; typescript, typescript-language-server,
  prettier, and mermaid-cli all live at the top level now
- `virtualisation.libvirtd.qemu.ovmf.enable` removed — OVMF images now
  ship with QEMU by default
Two CI fixes:

`nix flake check` asserts every nixosConfiguration has fileSystems."/".
Two configs hit it:
- machines/generic.nix — only consumed by lib/nixos2hm for non-NixOS
  Linux; never booted. Stub with tmpfs.
- machines/qemu-vm.nix — meant for `nixos-rebuild build-vm` which
  overrides fileSystems itself. Real-ish stub so it can also evaluate
  standalone.

modules/sleep.nix forks on option existence: stable (25.11) still has
`systemd.sleep.extraConfig`, unstable (which removed it) has
`.settings.Sleep`. Drop the else-branch once stable catches up.
`deploy-rs.lib.<system>.deployChecks` builds activation derivations
for every node regardless of node system, so `checks.x86_64-linux`
was trying to build rassie's aarch64-linux derivation on the x86_64
CI runner — fails with a platform mismatch.

Filter the node set per-system so each architecture's checks only
exercise its own nodes. CI on x86_64 verifies x86_64 nodes; when an
aarch64 runner enters the matrix later it'll cover rassie.
@myme myme merged commit 164f99a into main Jun 10, 2026
1 check passed
@myme myme deleted the flake-checks branch June 10, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant