diff --git a/.pi/prompts/review.md b/.pi/prompts/review.md index e115e3f..d732bbd 100644 --- a/.pi/prompts/review.md +++ b/.pi/prompts/review.md @@ -17,6 +17,15 @@ If the target includes multiple matching file types, use all matching skills. If the target is a diff, choose skills from the changed files. Do not use a style skill when no reviewed file matches it. +For every reviewed `*.nix` file, run: + +```bash +bazel run //src/natu:natu -- +``` + +Pass every reviewed Nix path to Natu. +Report every Natu diagnostic as an actionable finding. + Report only actionable findings. Order findings by severity. Do not report preferences unless a loaded rule states them. @@ -36,6 +45,7 @@ Keep the code excerpt to one to three lines when possible. Use a longer excerpt only when the violation needs surrounding context. Use `...` to omit unrelated lines from a multi-line excerpt. Use a style-skill rule citation in the form `skill::rule-file:line`. +Cite Natu diagnostics as `natu::`. Make the fix direct. Do not include alternatives when one fix best follows the cited rule. diff --git a/src/dotfiles/default.nix b/src/dotfiles/default.nix index 245364c..2a53e2a 100644 --- a/src/dotfiles/default.nix +++ b/src/dotfiles/default.nix @@ -17,7 +17,7 @@ let util = import ./util.nix { inherit lib; }; registry = import ./registry.nix { - inherit lib; + inherit lib util; hosts = self.nixosConfigurations; root = root + "/registry"; }; diff --git a/src/dotfiles/guests.nix b/src/dotfiles/guests.nix index ba4cad9..896ff97 100644 --- a/src/dotfiles/guests.nix +++ b/src/dotfiles/guests.nix @@ -276,10 +276,7 @@ let }; }; - names = map (file: lib.removeSuffix ".nix" file) (lib.attrNames guestFiles); - guestFiles = lib.filterAttrs (file: type: type == "regular" && lib.hasSuffix ".nix" file) ( - builtins.readDir root - ); + names = map (path: lib.removeSuffix ".nix" (builtins.baseNameOf path)) files; in { imports = files ++ map mkGuest names; diff --git a/src/dotfiles/registry.nix b/src/dotfiles/registry.nix index 8d6c2e0..6950765 100644 --- a/src/dotfiles/registry.nix +++ b/src/dotfiles/registry.nix @@ -2,20 +2,14 @@ hosts, lib, root, + util, }: let - definitions = - lib.mapAttrs' - ( - name: _type: - let - path = root + "/${name}"; - in - lib.nameValuePair (registryName name) (mkRegistry path) - ) - ( - lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root) - ); + definitions = lib.listToAttrs ( + map (path: lib.nameValuePair (registryName (builtins.baseNameOf path)) (mkRegistry path)) ( + util.collectNixFiles root + ) + ); registryName = fileName: lib.removeSuffix ".nix" fileName; diff --git a/src/skills/style/nix/rules/general.md b/src/skills/style/nix/rules/general.md new file mode 100644 index 0000000..3b51109 --- /dev/null +++ b/src/skills/style/nix/rules/general.md @@ -0,0 +1,12 @@ +## Discover Nix files + +### Rule + +Use `util.collectNixFiles` to discover Nix files. +Do not use `builtins.readDir` with a `.nix` suffix filter for this purpose. +Pass `util` to Nix functions that need the helper. + +### Rationale + +`util.collectNixFiles` centralizes recursive discovery of Nix files. +Repository Nix code uses one implementation.