codex: add support for managed rules files

This commit is contained in:
Austin Horstman 2026-04-01 19:34:40 -05:00
parent 6267895e98
commit 41e6e2ab37
5 changed files with 111 additions and 1 deletions

View file

@ -5,6 +5,7 @@
codex-empty-settings = ./empty-settings.nix;
codex-mcp-integration = ./mcp-integration.nix;
codex-mcp-integration-with-override = ./mcp-integration-with-override.nix;
codex-rules = ./rules.nix;
codex-skills-inline = ./skills-inline.nix;
codex-skills-inline-null-package = ./skills-inline-null-package.nix;
codex-skills-inline-legacy-path = ./skills-inline-legacy-path.nix;

View file

@ -0,0 +1,43 @@
{
programs.codex = {
enable = true;
rules = {
default = builtins.toFile "default.rules" ''
prefix_rule(
pattern = ["git", "status"],
decision = "allow",
justification = "Allow routine status checks",
)
'';
github = ''
prefix_rule(
pattern = ["gh", "pr", "view"],
decision = "prompt",
justification = "Review PRs with confirmation",
)
'';
};
};
nmt.script = ''
assertFileExists home-files/.codex/rules/default.rules
assertFileContent home-files/.codex/rules/default.rules \
${builtins.toFile "expected-default.rules" ''
prefix_rule(
pattern = ["git", "status"],
decision = "allow",
justification = "Allow routine status checks",
)
''}
assertFileExists home-files/.codex/rules/github.rules
assertFileContent home-files/.codex/rules/github.rules \
${builtins.toFile "expected-github.rules" ''
prefix_rule(
pattern = ["gh", "pr", "view"],
decision = "prompt",
justification = "Review PRs with confirmation",
)
''}
'';
}

View file

@ -11,6 +11,13 @@ in
programs.codex = {
enable = true;
package = codexPackage;
rules.default = ''
prefix_rule(
pattern = ["nix", "build"],
decision = "allow",
justification = "Allow local builds",
)
'';
settings = {
model = "gemma3:latest";
model_provider = "ollama";
@ -36,5 +43,14 @@ in
assertFileExists home-files/.config/codex/AGENTS.md
assertFileContent home-files/.config/codex/AGENTS.md \
${./AGENTS.md}
assertFileExists home-files/.config/codex/rules/default.rules
assertFileContent home-files/.config/codex/rules/default.rules \
${builtins.toFile "expected-xdg-default.rules" ''
prefix_rule(
pattern = ["nix", "build"],
decision = "allow",
justification = "Allow local builds",
)
''}
'';
}