Files
Vidhan Bhatt cc51f24b9b claude-code: allow hooks to accept a path like skills/commands
programs.claude-code.hooks previously only accepted inline strings.
It now shares the same either-lines-or-path content option used by
agents, commands, and rules, so a hook script can be referenced from
a file instead of being inlined.

mkSourceEntry used lib.isPath, which does not match derivations such
as pkgs.writeShellScript. Since lib.types.path accepts derivations,
a derivation-backed hook (or agent, command, rule, or output style)
sent the derivation to home.file.*.text and failed evaluation. Use
lib.hm.strings.isPathLike instead, and add a derivation-backed hook
test.

No release-notes entry: other option additions/extensions to this
module (e.g. path support for agents/commands, the rules option
itself) haven't warranted one either.
2026-08-05 14:33:00 -05:00

35 lines
941 B
Nix

{ pkgs, ... }:
let
derivation-hook = pkgs.writeShellScript "derivation-hook" ''
echo "About to edit file: $1"
'';
in
{
programs.claude-code = {
enable = true;
hooks = {
inline-hook = ''
#!/usr/bin/env bash
echo "About to edit file: $1"
'';
test-hook = ./hooks/test-hook;
inherit derivation-hook;
};
};
nmt.script = ''
assertFileExists home-files/.claude/hooks/inline-hook
assertFileIsExecutable home-files/.claude/hooks/inline-hook
assertFileExists home-files/.claude/hooks/test-hook
assertFileIsExecutable home-files/.claude/hooks/test-hook
assertFileContent home-files/.claude/hooks/test-hook \
${./hooks/test-hook}
assertFileExists home-files/.claude/hooks/derivation-hook
assertFileIsExecutable home-files/.claude/hooks/derivation-hook
assertFileContent home-files/.claude/hooks/derivation-hook \
${derivation-hook}
'';
}