From 133585ddfa1b7121f478648bd3c2fab9a092437e Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Thu, 12 Feb 2026 13:21:40 -0600 Subject: [PATCH] pay-respects: add rules support Allow creating rules files now following docs from https://github.com/iffse/pay-respects/blob/main/rules.md Signed-off-by: Austin Horstman --- modules/programs/pay-respects.nix | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/modules/programs/pay-respects.nix b/modules/programs/pay-respects.nix index 53877c39..1936a5a8 100644 --- a/modules/programs/pay-respects.nix +++ b/modules/programs/pay-respects.nix @@ -8,6 +8,7 @@ let cfg = config.programs.pay-respects; payRespectsCmd = lib.getExe cfg.package; cfgOptions = lib.concatStringsSep " " cfg.options; + tomlFormat = pkgs.formats.toml { }; in { meta.maintainers = [ lib.maintainers.ALameLlama ]; @@ -29,6 +30,49 @@ in ''; }; + rules = lib.mkOption { + type = lib.types.attrsOf tomlFormat.type; + default = { }; + example = lib.literalExpression '' + { + cargo = { + command = "cargo"; + match_err = [ + { + pattern = [ "run `cargo init` to initialize a new rust project" ]; + suggest = [ "cargo init" ]; + } + ]; + }; + + _PR_GENERAL = { + match_err = [ + { + pattern = [ "permission denied" ]; + suggest = [ + "#[executable(sudo), !cmd_contains(sudo)]\nsudo {{command}}" + ]; + } + ]; + }; + } + ''; + description = '' + Runtime rule files written to + {file}`$XDG_CONFIG_HOME/pay-respects/rules/.toml`. + + Attribute names map to filenames. For example, setting `rules.cargo = { ... };` + creates {file}`$XDG_CONFIG_HOME/pay-respects/rules/cargo.toml`. + The filename must match the command name, except for `_PR_GENERAL`. + + See + for runtime rule syntax and behavior. + + Note that these rules are only applied when the runtime-rules module is + available to `pay-respects`. + ''; + }; + enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; }; enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; }; @@ -41,6 +85,13 @@ in config = lib.mkIf cfg.enable { home.packages = [ cfg.package ]; + xdg.configFile = lib.mapAttrs' ( + name: rule: + lib.nameValuePair "pay-respects/rules/${name}.toml" { + source = tomlFormat.generate "pay-respects-rule-${name}.toml" rule; + } + ) cfg.rules; + programs = { bash.initExtra = lib.mkIf cfg.enableBashIntegration '' eval "$(${payRespectsCmd} bash ${cfgOptions})"