nix-reference
String Escaping
When writing Nix strings that contain code for other languages (TypeScript, JavaScript, etc.), remember:
| What you want in output | Nix syntax |
|---|---|
${variable} |
''${variable} |
$${variable} |
$''${variable} |
''${literal} |
'''${literal} |
Rule: Use two single quotes '' before ${} to prevent Nix from interpolating it.
Example - Generating TypeScript with template literals:
Nix source:
{
xdg.configFile."my-plugin.ts".text = ''
function log(msg: string) {
console.log(`[''${timestamp}] ''${msg}`);
}
'';
}
Generated TypeScript:
function log(msg: string) {
console.log(`[${timestamp}] ${msg}`);
}
Nix Command Reference
Flake Commands
nix build .#<package>- Build a packagenix run .#<package>- Run a packagenix develop- Enter dev shellnix flake check- Validate flakenix flake update- Update flake.lock
Interactive nix-shell
See examples/interactive-shell.bash
nix-shell Shebang Patterns
Note: Update the nixpkgs channel URL (e.g.,
nixos-25.11) to match your current NixOS release.
Finding your current release:
- On NixOS:
nixos-version(shows current system version, e.g.,25.05.20250224...) - From flake.lock: Check the
nixpkgsinput revision or runnix flake metadatato see locked references - Check system flake:
cat /etc/nixos/flake.nix | grep -E "nixos-24|nixos-25"or similar - Use
channelscommand:nix-channel --list(if using channels instead of flakes)
Bash script
#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash curl jq
#! nix-shell -I nixpkgs=https://nixos.org/channels/nixos-25.11/nixexprs.tar.xz
curl -s https://api.example.com | jq .
Python script
#!/usr/bin/env nix-shell
#! nix-shell -i python3 --pure
#! nix-shell -p python3 python3Packages.requests
#! nix-shell -I nixpkgs=https://nixos.org/channels/nixos-25.11/nixexprs.tar.xz
import requests
print(requests.get("https://api.example.com").json())
devShell Patterns
mkShell vs mkShellNoCC
mkShell- When you need C compiler (native extensions)mkShellNoCC- Pure scripting (Python, Node.js, Go)
Basic flake template (recommended)
Python with uv (recommended)
See examples/flake-python-uv.nix
Overlay Pattern
See examples/overlay-pattern.nix
Never Use
nix-env -i(use flakes or declarative config)
More from sirn/dotfiles
code-explain
Explain code, triage changes, or map project structure. Use when user asks to explain, understand, triage, or explore project structure.
19code-plan
Generate comprehensive implementation plan based on analysis. Use when user asks to plan this, create a plan, how should I implement, or wants implementation guidance.
19code-commit
Commit current changes using jj. Analyzes changes, suggests commit messages following repository conventions, proposes splits if needed, and creates commits. Use ONLY when user explicitly asks to commit changes or create commits.
18gemini-reference
Reference for calling the Gemini CLI agent from other agents. ALWAYS read BEFORE invoking Gemini to ensure correct JSON protocol, session management, and subtask delegation patterns.
18code-quality
Run comprehensive quality checks by orchestrating review, verification, testing, and linting. Use when user asks to check code quality, run full checks, or verify code health.
18context7
Retrieve up-to-date documentation context for libraries using the Context7 API. Use when needing current library documentation (React, Python stdlib, Rust, etc.) BEFORE implementing or writing code.
17