Files
home-manager/tests/modules/programs/claude-code/plugins-legacy-list.nix
jiezhuzzz cbb77679b3 claude-code: link plugins so agents and commands load
Claude Code lists a plugin's `agents/` and `commands/` entries with a
`readdir` that accepts only regular files, so symlinked directory entries
are skipped. Managed plugins were linked recursively, which materializes a
real directory holding one symlink per file, and wrapped with
`pkgs.symlinkJoin`, which mirrors directories and symlinks the leaf files.
Both layers dropped every agent and command a plugin provides.

Link each plugin as a single directory symlink, and wrap it with a
`runCommand` that links only top-level entries so component directories stay
symlinks to the original.

Also accept an attribute set for `plugins`, making the personal-plugin
directory name user-controlled and stable rather than derived from the
source's base name, which yields names such as `bxa1s0m3h4sh-source` that
change whenever the plugin is updated. The list form keeps working, with a
warning.
2026-07-27 11:11:02 -05:00

49 lines
1.4 KiB
Nix

{ config, pkgs, ... }:
let
pluginDirName = plugin: baseNameOf (toString plugin);
in
{
programs.claude-code = {
package = config.lib.test.mkStubPackage {
name = "claude-code";
version = "2.1.197";
buildScript = ''
mkdir -p $out/bin
cat > $out/bin/claude <<'EOF'
#!${pkgs.runtimeShell}
test "$#" -eq 1
test "$1" = rc
EOF
chmod +x $out/bin/claude
'';
};
enable = true;
plugins = [ ./test-plugin ];
};
test.asserts.warnings.expected = [
''
`programs.claude-code.plugins` is set to a list. Names are then derived
from each entry's base name, which for store paths yields unstable
directory names such as `bxa1s0m3h4sh-source`. Use an attribute set
instead so plugin directory names stay stable and readable:
plugins.my-plugin = ./my-plugin;
''
];
nmt.script = ''
"$TESTED/home-path/bin/claude" rc
# The list form still derives the directory name from the entry's base name.
pluginDir="$TESTED/home-files/.claude/skills/${pluginDirName ./test-plugin}"
assertLinkExists "home-files/.claude/skills/${pluginDirName ./test-plugin}"
assertFileContent "$pluginDir/.claude-plugin/plugin.json" ${./test-plugin/.claude-plugin/plugin.json}
assertFileContent \
"$pluginDir/agents/test-plugin-agent.md" \
${./test-plugin/agents/test-plugin-agent.md}
'';
}