refactor(dotfiles): share Nix file discovery #101

Merged
alexion merged 3 commits from registry-use-collect-nix-files into main 2026-09-26 23:50:03 -04:00
5 changed files with 30 additions and 17 deletions

View File

@@ -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 -- <reviewed-nix-paths>
```
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::<rule-id>`.
Make the fix direct.
Do not include alternatives when one fix best follows the cited rule.

View File

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

View File

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

View File

@@ -2,19 +2,13 @@
hosts,
lib,
root,
util,
}:
let
definitions =
lib.mapAttrs'
(
name: _type:
let
path = root + "/${name}";
in
lib.nameValuePair (registryName name) (mkRegistry path)
definitions = lib.listToAttrs (
map (path: lib.nameValuePair (registryName (builtins.baseNameOf path)) (mkRegistry path)) (
util.collectNixFiles root
)
(
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
);
registryName = fileName: lib.removeSuffix ".nix" fileName;

View File

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