From af9786a87eb020f16fd4ae6d76d1ce44d3e1dd50 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar <3998+srid@users.noreply.github.com> Date: Mon, 10 Nov 2025 14:58:52 -0500 Subject: [PATCH] nix + skill --- modules/home/claude-code/default.nix | 26 ++++++++++---- .../skills/article-extractor/SKILL.md | 22 +----------- .../skills/article-extractor/default.nix | 34 +++++++++++++++++++ 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 modules/home/claude-code/skills/article-extractor/default.nix diff --git a/modules/home/claude-code/default.nix b/modules/home/claude-code/default.nix index 3b5e592..a64cfcb 100644 --- a/modules/home/claude-code/default.nix +++ b/modules/home/claude-code/default.nix @@ -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; diff --git a/modules/home/claude-code/skills/article-extractor/SKILL.md b/modules/home/claude-code/skills/article-extractor/SKILL.md index a72c0a2..183c90d 100644 --- a/modules/home/claude-code/skills/article-extractor/SKILL.md +++ b/modules/home/claude-code/skills/article-extractor/SKILL.md @@ -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" ``` diff --git a/modules/home/claude-code/skills/article-extractor/default.nix b/modules/home/claude-code/skills/article-extractor/default.nix new file mode 100644 index 0000000..aa4c9ed --- /dev/null +++ b/modules/home/claude-code/skills/article-extractor/default.nix @@ -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" + ''; +}