Skip to content

feat: add Nix flake with home-manager module for declarative builds#637

Open
helgeu wants to merge 4 commits intortk-ai:developfrom
helgeu:feat/nix-flake
Open

feat: add Nix flake with home-manager module for declarative builds#637
helgeu wants to merge 4 commits intortk-ai:developfrom
helgeu:feat/nix-flake

Conversation

@helgeu
Copy link

@helgeu helgeu commented Mar 16, 2026

Summary

  • Add a Nix flake (flake.nix + nix/package.nix) that builds rtk using rustPlatform.buildRustPackage
  • Add --dry-run --json flag to rtk init for declarative config managers (outputs file manifest as JSON)
  • Add home-manager module (nix/homeManagerModule.nix) for declarative Claude Code hook integration
  • Version is read from Cargo.toml at eval time — no manual version bumps needed
  • Includes an overlay (overlays.default) and homeManagerModules.default for Nix consumers

What this enables

# flake.nix
inputs.rtk.url = "github:rtk-ai/rtk";

# home-manager config
imports = [ inputs.rtk.homeManagerModules.default ];
programs.rtk = {
  enable = true;
  claudeCode = {
    enable = true;
    baseClaude = ./CLAUDE.md.template;   # optional: seed CLAUDE.md
    baseSettings = ./settings.json;       # optional: seed settings.json
  };
};
# Run directly without installing
nix run github:rtk-ai/rtk

# Programmatic config generation (for other package managers)
rtk init --dry-run --json

Design decisions

  • builtins.fromTOML for version: reads Cargo.toml at eval time so the package version stays in sync with releases automatically
  • --dry-run --json: outputs the full file manifest as JSON so Nix (or any declarative tool) can extract files at build time without side effects
  • jq -j in module: uses jq -j (not jq -r) to extract file content without adding a trailing newline, preserving exact content for rtk verify integrity checks
  • doCheck = false: tests require network access which is unavailable in the Nix sandbox

Test plan

  • nix build succeeds on macOS (aarch64)
  • rtk verify passes after darwin-rebuild switch with home-manager module
  • rtk gain and hook rewriting work end-to-end
  • nix build succeeds on Linux (x86_64)

🤖 Generated with Claude Code

helgeu added a commit to helgeu/setup that referenced this pull request Mar 16, 2026
Add rtk as a flake input from fork (helgeu/rtk#feat/nix-flake) and
include it in claude.nix alongside claude-code. RTK compresses verbose
CLI output before it enters an AI agent's context window.

Upstream PR: rtk-ai/rtk#637

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

Please retarget this PR to develop instead of master. We use develop as the integration branch — master is for releases only. You can change the base branch in the PR settings. Thanks!

@pszymkowiak pszymkowiak added the wrong-base PR targets master instead of develop label Mar 17, 2026
@helgeu helgeu changed the title feat: add Nix flake for declarative builds feat: add Nix flake with home-manager module for declarative builds Mar 18, 2026
@helgeu helgeu changed the base branch from master to develop March 18, 2026 20:31
@helgeu
Copy link
Author

helgeu commented Mar 18, 2026

Sorry about that! Retargeted to develop and rebased. Should be good now.

helgeu and others added 4 commits March 18, 2026 22:08
Add a Nix flake with a rustPlatform.buildRustPackage derivation and an
overlay for easy integration into other Nix configurations. The package
version is read from Cargo.toml so it stays in sync automatically.

Update installation docs (README, INSTALL.md, and all translated READMEs)
with Nix instructions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Separate config generation from filesystem writing in `rtk init`.
New `--dry-run --json` mode outputs a file manifest (paths, content,
permissions) to stdout without touching disk, enabling Nix, Ansible,
and other declarative tools to consume RTK's config as build-time
data.

New flags:
  --dry-run              Output manifest instead of writing files
  --json                 JSON format (requires --dry-run)
  --base-claude-md PATH  Seed CLAUDE.md from file (requires --dry-run)
  --base-settings PATH   Seed settings.json from file (requires --dry-run)

Also adds lib.mkConfig to flake.nix — a Nix helper that calls
rtk init --dry-run --json and deploys the resulting files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Export a proper home-manager module instead of a plain helper function.
Consumers now import rtk.homeManagerModules.default and set:

  programs.rtk = {
    enable = true;
    claudeCode.enable = true;
    claudeCode.baseClaude = ./CLAUDE.md.template;
    claudeCode.baseSettings = ./settings.json;
  };

The module handles package installation and home.file wiring internally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jq -r appends a trailing newline to output, making the hook file 1 byte
larger than what rtk verify expects. This causes the integrity check to
fail with a hash mismatch. jq -j outputs raw strings without adding a
trailing newline, preserving the exact content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wrong-base PR targets master instead of develop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants