Skip to content

Conversation

@karol-broda
Copy link

@karol-broda karol-broda commented Dec 22, 2025

adds a nix-flake addon that generates a flake.nix and .envrc for the project

the flake exposes a devshell with the appropriate runtime (bun or node) based on what you picked during setup. also includes docker-compose if you're using docker for your db

Summary by CodeRabbit

  • New Features

    • Added "Nix Flake" addon option and added template support for a .envrc file.
  • Documentation

    • CLI flags and addon docs updated to list the Nix Flake option.
  • Tests

    • Expanded test coverage to include the Nix Flake addon.
  • Chores

    • Added Nix flake and direnv configuration templates and related CLI selection entries.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 22, 2025

@karol-broda is attempting to deploy a commit to the Better T Stack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Walkthrough

Adds a new "nix-flake" addon: registers it across types, CLI, and web, adds templates (flake and .envrc), maps _envrc.envrc in the template manager, updates tests, and adds a repository-level flake.nix. (49 words)

Changes

Cohort / File(s) Summary
Env / Project flake
\.envrc, flake.nix
Add repository .envrc (direnv use flake) and a top-level flake.nix defining multi-platform devShells (bun/node, shellHook).
Types & CLI constants & web options
packages/types/src/schemas.ts, apps/cli/src/constants.ts, apps/web/src/lib/constant.ts
Register "nix-flake": add enum option in schemas, add key to ADDON_COMPATIBILITY, and add TECH_OPTION entry for the web UI.
Template processing
apps/cli/src/helpers/core/template-manager.ts
Map template basename _envrc → destination .envrc in processAndCopyFiles (same pattern as _gitignore, _npmrc).
Addon prompts / UI
apps/cli/src/prompts/addons.ts
Add display label and hint for "nix-flake" and include it in ADDON_GROUPS.Other so it appears in addon selection.
Addon templates
apps/cli/templates/addons/nix-flake/_envrc.hbs, apps/cli/templates/addons/nix-flake/flake.nix.hbs
Add direnv template (use flake) and a Handlebars Nix flake template that conditionally includes bun/node and docker-compose blocks and emits per-system devShells.
Tests
apps/cli/test/addons.test.ts
Include "nix-flake" in Universal Addons and All Available Addons test sets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas needing extra attention:
    • flake.nix and apps/cli/templates/addons/nix-flake/flake.nix.hbs — validate Nix syntax, conditional template blocks, and multi-platform outputs.
    • apps/cli/src/helpers/core/template-manager.ts — confirm _envrc mapping preserves templating behavior and edge cases.
    • Cross-file consistency for the new "nix-flake" identifier across types, constants, prompts, web options, and tests.

Possibly related PRs

Suggested labels

patch

Poem

🐰 I found a flake beneath the hay,
I hopped in shells to code all day,
Bun or node, the paths align,
Direnv whispers "use flake" — fine!
Hooray, reproducible play!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding nix-flake addon support and related configurations, which is the primary focus across all modified files.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c73aa3 and 9e6642d.

📒 Files selected for processing (1)
  • apps/cli/templates/addons/nix-flake/flake.nix.hbs
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/cli/templates/addons/nix-flake/flake.nix.hbs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/cli/templates/addons/nix-flake/flake.nix.hbs (1)

21-21: Consider parameterizing Node.js version for easier maintenance.

The Node.js version is hardcoded to nodejs_22. As new LTS versions are released, this will require manual template updates.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d09793 and a28a6a8.

⛔ Files ignored due to path filters (1)
  • flake.lock is excluded by !**/*.lock
📒 Files selected for processing (9)
  • .envrc
  • apps/cli/src/constants.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • apps/cli/src/prompts/addons.ts
  • apps/cli/templates/addons/nix-flake/_envrc.hbs
  • apps/cli/templates/addons/nix-flake/flake.nix.hbs
  • apps/cli/test/addons.test.ts
  • flake.nix
  • packages/types/src/schemas.ts
🧰 Additional context used
📓 Path-based instructions (7)
**/*.hbs

📄 CodeRabbit inference engine (.cursor/rules/better-t-stack-repo.mdc)

**/*.hbs: In Handlebars templates, avoid generic if/else blocks. Write explicit conditions, such as: use if (eq orm "prisma") for Prisma, and else if (eq orm "drizzle") for Drizzle
Escape the '{{' in Handlebars templates like '{{'

Files:

  • apps/cli/templates/addons/nix-flake/flake.nix.hbs
  • apps/cli/templates/addons/nix-flake/_envrc.hbs
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/better-t-stack-repo.mdc)

Define functions using the standard function declaration syntax, not arrow functions

Files:

  • apps/cli/src/prompts/addons.ts
  • apps/cli/src/constants.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • packages/types/src/schemas.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/better-t-stack-repo.mdc)

**/*.{ts,tsx}: Use TypeScript type aliases instead of interface declarations
Do not use explicit return types

Files:

  • apps/cli/src/prompts/addons.ts
  • apps/cli/src/constants.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • packages/types/src/schemas.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.{ts,tsx,js,jsx}: Use bun <file> instead of node <file> or ts-node <file> for running TypeScript/JavaScript files
Bun automatically loads .env files, so don't use the dotenv package
Use Bun.serve() which supports WebSockets, HTTPS, and routes instead of express
Use bun:sqlite module for SQLite instead of better-sqlite3
Use Bun.redis for Redis instead of ioredis
Use Bun.sql for Postgres instead of pg or postgres.js
Use built-in WebSocket instead of the ws package
Prefer Bun.file over node:fs readFile/writeFile methods
Use Bun.$ template literal syntax instead of execa for shell command execution
Import .css files directly in TypeScript/JavaScript files; Bun's CSS bundler will handle bundling
Run server with bun --hot <file> to enable hot reloading during development

Files:

  • apps/cli/src/prompts/addons.ts
  • apps/cli/src/constants.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • packages/types/src/schemas.ts
**/*.{ts,tsx,js,jsx,css}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

Use bun build <file> instead of webpack or esbuild for bundling TypeScript, JavaScript, and CSS files

Files:

  • apps/cli/src/prompts/addons.ts
  • apps/cli/src/constants.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • packages/types/src/schemas.ts
**/*.{html,tsx,ts,jsx,js}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

Use HTML imports with Bun.serve() for frontend instead of Vite

Files:

  • apps/cli/src/prompts/addons.ts
  • apps/cli/src/constants.ts
  • apps/cli/test/addons.test.ts
  • apps/cli/src/helpers/core/template-manager.ts
  • packages/types/src/schemas.ts
**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc)

**/*.test.{ts,tsx,js,jsx}: Use bun test instead of jest or vitest for running tests
Use bun:test module with test and expect functions for writing tests

Files:

  • apps/cli/test/addons.test.ts
🧠 Learnings (2)
📚 Learning: 2025-12-18T19:15:48.478Z
Learnt from: therealsamyak
Repo: AmanVarshney01/create-better-t-stack PR: 711
File: apps/cli/src/helpers/addons/ultracite-setup.ts:200-205
Timestamp: 2025-12-18T19:15:48.478Z
Learning: In apps/cli/src/helpers/addons/ultracite-setup.ts, the Ultracite CLI's `--integrations` flag requires git hooks to be passed as a single space-separated string (e.g., `gitHooks.join(" ")`) rather than using the spread operator like other Ultracite flags. This has been tested and confirmed to work.

Applied to files:

  • apps/cli/test/addons.test.ts
📚 Learning: 2025-12-03T07:48:26.419Z
Learnt from: CR
Repo: AmanVarshney01/create-better-t-stack PR: 0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-12-03T07:48:26.419Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Bun automatically loads .env files, so don't use the dotenv package

Applied to files:

  • apps/cli/src/helpers/core/template-manager.ts
🔇 Additional comments (12)
apps/cli/src/helpers/core/template-manager.ts (1)

38-39: LGTM!

The _envrc to .envrc mapping follows the established pattern for special dotfile handling alongside _gitignore and _npmrc.

apps/cli/templates/addons/nix-flake/_envrc.hbs (1)

1-2: LGTM!

Standard direnv configuration for Nix flake environments. The template correctly enables the flake-based dev shell.

.envrc (1)

1-1: Verify the intentional difference between root and template .envrc files.

The root .envrc uses --impure while the generated template (_envrc.hbs) uses plain use flake. This may be intentional—the --impure flag allows access to environment variables during flake evaluation, which might be needed for the CLI development but not for generated projects. Please confirm this distinction is deliberate.

packages/types/src/schemas.ts (1)

47-47: LGTM!

The nix-flake addon is properly added to the schema enum, maintaining consistency with other addon entries.

apps/cli/src/constants.ts (1)

192-192: LGTM!

The nix-flake addon is correctly registered as a universal addon with no frontend restrictions, consistent with similar addons like biome, husky, and turborepo.

apps/cli/test/addons.test.ts (2)

7-7: LGTM!

The nix-flake addon is correctly added to the universal addons test list, ensuring it receives proper test coverage.


291-291: LGTM!

Consistent addition to the testableAddons array ensures end-to-end test coverage for the new addon.

apps/cli/src/prompts/addons.ts (2)

66-69: LGTM!

Clear and descriptive label/hint for the Nix Flake addon. The hint accurately conveys the reproducible development environment benefit.


81-81: LGTM!

Appropriate grouping under "Other" alongside similar infrastructure addons.

flake.nix (2)

10-35: LGTM!

Well-structured multi-system flake configuration with proper devShell definitions for all major platforms. The mkShellFor helper cleanly abstracts the per-system shell creation, and the shellHook provides useful version feedback during development.


4-8: No action required. The flake correctly references nixos-25.11, which is a valid, currently available stable release.

apps/cli/templates/addons/nix-flake/flake.nix.hbs (1)

18-22: LGTM! Conditional logic follows coding guidelines.

The explicit if (eq runtime "bun") and else if (eq runtime "node") conditions correctly follow the coding guideline to avoid generic if/else blocks. The Handlebars syntax is properly used.

Comment on lines 4 to 8
inputs = \{
nixpkgs = \{
url = "github:NixOS/nixpkgs/nixos-unstable";
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Align nixpkgs input with root flake for consistency and reproducibility.

The template uses nixos-unstable while the root flake.nix pins to nixos-25.11. This inconsistency can lead to:

  • Reproducibility issues across environments
  • Unexpected breaking changes when unstable updates
  • Different behavior between the template-generated projects and the root configuration

Consider aligning with the root flake's approach by using a stable release branch.

🔎 Proposed fix
   inputs = \{
     nixpkgs = \{
-      url = "github:NixOS/nixpkgs/nixos-unstable";
+      url = "github:NixOS/nixpkgs/nixos-25.11";
     };
   };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
inputs = \{
nixpkgs = \{
url = "github:NixOS/nixpkgs/nixos-unstable";
};
};
inputs = \{
nixpkgs = \{
url = "github:NixOS/nixpkgs/nixos-25.11";
};
};
🤖 Prompt for AI Agents
In apps/cli/templates/addons/nix-flake/flake.nix.hbs around lines 4-8, the
nixpkgs input is pinned to "nixos-unstable", which diverges from the root
flake's stable pin (nixos-25.11); update the template to use the same stable
release branch or the exact pin used by the root flake (e.g., change the url to
match "github:NixOS/nixpkgs/nixos-25.11" or wire the template to read the root
flake's pinned ref) so generated projects use the same nixpkgs version for
reproducibility and consistency.

@AmanVarshney01
Copy link
Owner

interesting... is the PR complete? @karol-broda

@karol-broda
Copy link
Author

yes, it should be complete. the only remaining question is whether we want to include a nix lock file to pin bun as well, since node major is pinned but bun would track nixpkgs unstable and update as nixpkgs updates @AmanVarshney01

@karol-broda
Copy link
Author

maybe adding a nix svg icon to the r2 bucket, also i now added it to the web builder constants, i only tested the cli directly so i forgot to do that

@karol-broda
Copy link
Author

@AmanVarshney01 actually , i just started writing and thought that it maybe would be good to also add database tooling or stuff like that in the flake, like psql or something. also i forgot to handle adding wrangler

@karol-broda
Copy link
Author

yea now i think it should handle everything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants