nix + skill

This commit is contained in:
Sridhar Ratnakumar 2025-11-10 14:58:52 -05:00
parent 1c0dddf544
commit af9786a87e
3 changed files with 54 additions and 28 deletions

View file

@ -20,6 +20,24 @@ let
skillsDir = ./skills;
skillDirs = lib.filterAttrs (_: type: type == "directory") (builtins.readDir skillsDir);
# Process skill: if it has default.nix, build and substitute; otherwise use as-is
processSkill = skillName:
let
skillPath = skillsDir + "/${skillName}";
hasDefaultNix = builtins.pathExists (skillPath + "/default.nix");
in
if hasDefaultNix then
let
skillPkg = pkgs.callPackage skillPath { };
in
pkgs.runCommand "${skillName}-skill" { } ''
mkdir -p $out
substitute ${skillPath}/SKILL.md $out/SKILL.md \
--replace-fail '@${skillName}@' '${skillPkg}/bin/${skillName}'
''
else
skillPath;
in
{
# Packages often used by Claude Code CLI.
@ -32,17 +50,11 @@ in
home.file = lib.mapAttrs'
(skillName: _:
lib.nameValuePair ".claude/skills/${skillName}" {
source = skillsDir + "/${skillName}";
source = processSkill skillName;
recursive = true;
}
)
skillDirs;
home.packages = [
# Used in skills
# TODO: Encapsulate
pkgs.reader
];
programs.claude-code = {
enable = true;

View file

@ -20,26 +20,6 @@ User wants to:
## Workflow
```bash
# Download HTML
curl -L "$URL" > /tmp/temp.html
# Extract article
reader /tmp/temp.html > /tmp/temp.txt
# Get title from first line
TITLE=$(head -n 1 /tmp/temp.txt | sed 's/^# //')
# Clean filename
FILENAME=$(echo "$TITLE" | tr '/:?"<>| ' '-' | cut -c 1-80 | sed 's/-*$//')".txt"
# Save
mv /tmp/temp.txt "/tmp/$FILENAME"
# Clean up
rm /tmp/temp.html
# Show preview
echo "✓ Saved: /tmp/$FILENAME"
head -n 10 "/tmp/$FILENAME"
@article-extractor@ "$URL"
```

View file

@ -0,0 +1,34 @@
{ writeShellApplication, curl, reader }:
# Inspired by https://github.com/michalparkola/tapestry-skills-for-claude-code/blob/main/article-extractor/SKILL.md
writeShellApplication {
name = "article-extractor";
runtimeInputs = [ curl reader ];
text = ''
URL="$1"
# Download HTML
curl -L "$URL" > /tmp/temp.html
# Extract article
reader /tmp/temp.html > /tmp/temp.txt
# Get title from first line
TITLE=$(head -n 1 /tmp/temp.txt | sed 's/^# //')
# Clean filename
FILENAME=$(echo "$TITLE" | tr '/:?"<>| ' '-' | cut -c 1-80 | sed 's/-*$//')".txt"
# Save
mv /tmp/temp.txt "/tmp/$FILENAME"
# Clean up
rm /tmp/temp.html
# Show preview
echo " Saved: /tmp/$FILENAME"
head -n 10 "/tmp/$FILENAME"
'';
}