Skills.MD
# Template Creation Guide
Expert guidance for creating comprehensive development environment templates
with Nix flakes.
## Core Principles
1. **Reproducibility** - Same template produces identical environments
everywhere
2. **Developer experience** - Fast to use, easy to understand
3. **Language-specific best practices** - Follow conventions for each ecosystem
4. **Integration-ready** - Works with editors, CI/CD, containers
5. **Maintainability** - Easy to update dependencies and configurations
## Template Creation Workflow
Copy this checklist when creating templates:
```
Template Creation Progress:
- [ ] Step 1: Identify target language/framework requirements
- [ ] Step 2: Design flake structure and inputs
- [ ] Step 3: Create devShell with all needed tools
- [ ] Step 4: Add language-specific configuration files
- [ ] Step 5: Configure editor/IDE integration
- [ ] Step 6: Add CI/CD configuration
- [ ] Step 7: Write documentation
- [ ] Step 8: Test on clean system
```
## Flake Template Structure
### Basic Template Layout
```
template/
├── flake.nix # Main flake definition
├── flake.lock # Locked dependencies
├── .envrc # direnv integration
├── .gitignore # Git ignore patterns
├── README.md # Documentation
└── src/ # Source code placeholder
```
### Standard flake.nix Template
```nix
{
description = "Project description";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# Add development tools here
];
shellHook = ''
echo "Development environment loaded"
'';
};
# Optional: packages, apps, etc.
}
);
}
```
## Language-Specific Templates
### Node.js/TypeScript
```nix
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs_20
nodePackages.npm
nodePackages.typescript
nodePackages.typescript-language-server
];
shellHook = ''
export PATH="$PWD/node_modules/.bin:$PATH"
'';
};
```
Configuration files to include:
- `tsconfig.json` - TypeScript configuration
- `package.json` - Package manifest
- `.prettierrc` - Code formatting
- `.eslintrc.js` - Linting rules
### Python
```nix
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
python311
python311Packages.pip
python311Packages.virtualenv
python311Packages.black
python311Packages.mypy
pyright
];
shellHook = ''
# Create venv if it doesn't exist
if [ ! -d .venv ]; then
python -m venv .venv
fi
source .venv/bin/activate
'';
};
```
Configuration files to include:
- `pyproject.toml` - Project configuration
- `requirements.txt` or `poetry.lock` - Dependencies
- `.python-version` - Python version
### Rust
```nix
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
rustc
cargo
rust-analyzer
clippy
rustfmt
];
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
```
Configuration files to include:
- `Cargo.toml` - Package manifest
- `rust-toolchain.toml` - Toolchain version
- `.rustfmt.toml` - Formatting rules
### Go
```nix
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
go
gopls
golangci-lint
delve
];
shellHook = ''
export GOPATH="$PWD/.go"
export PATH="$GOPATH/bin:$PATH"
'';
};
```
## Editor Integration
### VS Code
`.vscode/settings.json`:
```json
{
"editor.formatOnSave": true,
"nix.enableLanguageServer": true,
"nix.serverPath": "nil"
}
```
### direnv (.envrc)
```bash
use flake
```
## CI/CD Integration
### GitHub Actions
```yaml
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v14
with:
name: your-cache
- run: nix build
- run: nix flake check
```
## Template Quality Checklist
- [ ] `nix flake check` passes
- [ ] DevShell includes all required tools
- [ ] Editor integration configured
- [ ] CI/CD workflow included
- [ ] README with setup instructions
- [ ] `.gitignore` covers generated files
- [ ] License file included
- [ ] Works on Linux and macOS
## Common Patterns
### Multi-Shell Template
```nix
devShells = {
default = pkgs.mkShell {
# Default development environment
};
ci = pkgs.mkShell {
# Minimal CI environment
};
full = pkgs.mkShell {
# Full environment with optional tools
};
};
```
### Cross-Platform Considerations
```nix
buildInputs = with pkgs; [
# Common tools
git
jq
] ++ lib.optionals stdenv.isDarwin [
# macOS-specific
darwin.apple_sdk.frameworks.Security
] ++ lib.optionals stdenv.isLinux [
# Linux-specific
inotify-tools
];
```
## See Also
- **Flake management**: See [managing-flakes](../managing-flakes/) for input and
lock file management
- **Writing Nix**: See [writing-nix](../writing-nix/) for Nix code best
practices
- **Module scaffolding**: See
[scaffolding-modules](../../khanelinix/scaffolding-modules/) for NixOS module
templates
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「template-creation」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次