devcontainers-nix – skill Khác cho agent AI
Tạo môi trường phát triển tái lập được với Dev Containers, Nix flakes và Devbox để đồng bộ toolchain cho các nhóm.
Cài skill devcontainers-nix bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/devcontainers-nix-db624.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /devcontainers-nix – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/devcontainers-nix-db624.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $devcontainers-nix – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/devcontainers-nix-db624.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /devcontainers-nix – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/devcontainers-nix-db624.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /devcontainers-nix – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Dev Containers & Nix Environments
Reproducible, portable development environments that eliminate environment drift.
When to Use This Skill
Use this skill when:
- Onboarding new developers (zero-to-productive in minutes)
- Standardizing toolchains across a team
- Eliminating "works on my machine" problems
- Setting up CI environments that match local dev
- Creating ephemeral, disposable dev environments
Environment execution boundaries
Devcontainer features, lifecycle hooks, Nix shell hooks, direnv and dependency installers execute code; inspect the complete configuration, locked inputs and source before activation. Do not run moving downloaded installers or accept a hash mismatch by deleting/recreating state; verify publisher/version and integrity first. Avoid privileged Docker-in-Docker and host sockets for untrusted repositories. Never pass production credentials into a development environment by default. Offline operation needs every dependency/artifact already available locally; a lockfile alone is insufficient. nix build/run need corresponding outputs, which the devShell-only example does not define.
Dev Containers
Basic Configuration
// .devcontainer/devcontainer.json
{
"name": "My Project",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
"features": {
"ghcr.io/devcontainers/features/node:1": { "version": "20" },
"ghcr.io/devcontainers/features/python:1": { "version": "3.12" },
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {}
},
"forwardPorts": [3000, 5432],
"postCreateCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-python.python"
],
"settings": {
"editor.formatOnSave": true
}
}
}
}Docker Compose Dev Container
// .devcontainer/devcontainer.json
{
"name": "Full Stack Dev",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"forwardPorts": [3000, 5432, 6379],
"postCreateCommand": "npm install && npx prisma migrate dev"
}# .devcontainer/docker-compose.yml
services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
volumes:
- ..:/workspace:cached
command: sleep infinity
depends_on: [db, redis]
db:
image: postgres:16
environment:
POSTGRES_DB: dev
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
redis:
image: redis:7-alpine
ports:
- "127.0.0.1:6379:6379"
volumes:
pgdata:Custom Dockerfile
# .devcontainer/Dockerfile
FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04
# System dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
jq \
unzip \
&& rm -rf /var/lib/apt/lists/*
# Install project-specific tools
RUN curl -fsSL https://get.opentofu.org/install-opentofu.sh -o /tmp/install-opentofu.sh \
&& sh /tmp/install-opentofu.sh -s -- --install-method standalone \
&& rm /tmp/install-opentofu.sh
RUN curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
&& install kubectl /usr/local/bin/
# Non-root user setup
USER vscode
WORKDIR /workspaceNix Flakes
Basic Flake
# flake.nix
{
description = "Project development environment";
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; [
# Languages
nodejs_20
python312
go_1_22
rustc
cargo
# Tools
docker-compose
kubectl
kubernetes-helm
opentofu
awscli2
jq
yq-go
# Databases
postgresql_16
redis
];
shellHook = ''
echo "Dev environment loaded"
export PROJECT_ROOT=$(pwd)
export PATH="$PROJECT_ROOT/node_modules/.bin:$PATH"
'';
};
}
);
}# Enter the dev shell
nix develop
# Or run a single command
nix develop --command bash -c "node --version && go version"
# Build and run
nix build
nix runPin Dependencies
# Lock flake inputs for reproducibility
nix flake lock
nix flake update # Update all inputs
# Update a specific input
nix flake lock --update-input nixpkgsDevbox (Nix Made Simple)
Devbox wraps Nix with a friendlier interface:
# Install Devbox
curl -fsSL https://get.jetify.com/devbox -o /tmp/install-devbox.sh && sh /tmp/install-devbox.sh && rm /tmp/install-devbox.sh
# Initialize project
devbox init
# Add packages
devbox add nodejs@20 [email protected] postgresql@16
devbox add [email protected] kubectl helm
# Enter shell
devbox shell
# Run commands without entering shell
devbox run node --versiondevbox.json Configuration
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox.schema.json",
"packages": [
"nodejs@20",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"postgresql@16",
"redis@7"
],
"env": {
"PROJECT_ROOT": "$PWD",
"DATABASE_URL": "postgresql://localhost:5432/dev"
},
"shell": {
"init_hook": [
"echo 'Dev environment ready'",
"npm ci --ignore-scripts"
],
"scripts": {
"dev": "npm run dev",
"test": "npm test",
"db:start": "pg_ctl -D .devbox/virtenv/postgresql/data start",
"db:stop": "pg_ctl -D .devbox/virtenv/postgresql/data stop",
"db:migrate": "npx prisma migrate dev"
}
}
}# Run project scripts
devbox run dev
devbox run test
devbox run db:start
# Generate direnv integration (auto-activate on cd)
devbox generate direnv
# Generate Dockerfile from devbox config
devbox generate dockerfileDevbox + direnv (Auto-Activate)
# Install direnv
devbox add direnv
# Generate .envrc
devbox generate direnv
# Allow direnv
direnv allow# .envrc (auto-generated)
eval "$(devbox generate direnv --print-envrc)"Now cd-ing into the project automatically loads the environment.
CI/CD Integration
GitHub Actions with Devbox
# .github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jetify-com/[email protected]
with:
enable-cache: true
- run: devbox run test
- run: devbox run lintGitHub Actions with Nix
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v14
with:
name: my-project
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: nix develop --command bash -c "npm ci && npm test"GitHub Codespaces
// .devcontainer/devcontainer.json — works in Codespaces
{
"name": "Codespaces Dev",
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/node:1": { "version": "20" }
},
"postCreateCommand": "npm install",
"portsAttributes": {
"3000": { "label": "App", "onAutoForward": "openBrowser" },
"5432": { "label": "Postgres", "onAutoForward": "ignore" }
}
}Comparison
| Feature | Dev Containers | Nix Flakes | Devbox |
|---------|---------------|------------|--------|
| Learning curve | Low | High | Low |
| Reproducibility | Good (Docker) | Excellent | Excellent (Nix) |
| Speed | Slow (build image) | Fast (cached) | Fast (cached) |
| IDE support | VS Code, JetBrains | Any terminal | Any terminal |
| CI integration | Docker-based | Nix actions | Devbox action |
| Offline support | Limited | Full | Full |
| macOS/Linux/Win | All | macOS/Linux | macOS/Linux |
Best Practices
- Pin all tool versions explicitly — never use
latest - Commit lock files (
flake.lock,devbox.lock, etc.) - Use direnv for automatic environment activation
- Cache Nix store in CI (Cachix or GitHub cache)
- Document setup in README:
devbox shellornix develop - Keep dev environment close to production (same Node/Python versions)
Troubleshooting
| Issue | Solution |
|-------|---------|
|
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- diagnose-android-overheating – Dùng khi chẩn đoán Android nóng máy, nóng khi nhàn rỗi, thermal throttling, nóng do sạc…
- diary – Hệ thống nhật ký hợp nhất: bộ ghi nhật ký tự động, giữ ngữ cảnh cho phát triển đa dự án.
- stripe-integration – Triển khai xử lý thanh toán Stripe an toàn, tuân thủ PCI, gồm checkout, subscription và…
- disaster-recovery – Triển khai chiến lược và runbook khôi phục sau thảm họa. Cấu hình mục tiêu RPO/RTO và…
- distributed-tracing – Triển khai distributed tracing với Jaeger và Tempo để quan sát luồng request qua các…
- doc2math – Chuyển tài liệu kỹ thuật dạng văn bản thành Đặc tả bài toán toán học có căn cứ, gồm…
- solana – Truy vấn ví, token, giao dịch và NFT trên Solana theo USD.
- domain-authority-simulator – Domain Authority Simulator. Dùng khi làm việc với tín hiệu domain và một rubric chấm…