$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill devcontainers-nixCreate reproducible development environments with Dev Containers, Nix flakes, and Devbox for consistent toolchains across teams. Use when onboarding developers, standardizing build environments, or eliminating "works on my machine" problems.
| 1 | # Dev Containers & Nix Environments |
| 2 | |
| 3 | Reproducible, portable development environments that eliminate environment drift. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Onboarding new developers (zero-to-productive in minutes) |
| 9 | - Standardizing toolchains across a team |
| 10 | - Eliminating "works on my machine" problems |
| 11 | - Setting up CI environments that match local dev |
| 12 | - Creating ephemeral, disposable dev environments |
| 13 | |
| 14 | ## Dev Containers |
| 15 | |
| 16 | ### Basic Configuration |
| 17 | |
| 18 | ```json |
| 19 | // .devcontainer/devcontainer.json |
| 20 | { |
| 21 | "name": "My Project", |
| 22 | "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", |
| 23 | "features": { |
| 24 | "ghcr.io/devcontainers/features/node:1": { "version": "20" }, |
| 25 | "ghcr.io/devcontainers/features/python:1": { "version": "3.12" }, |
| 26 | "ghcr.io/devcontainers/features/docker-in-docker:2": {}, |
| 27 | "ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {} |
| 28 | }, |
| 29 | "forwardPorts": [3000, 5432], |
| 30 | "postCreateCommand": "npm install", |
| 31 | "customizations": { |
| 32 | "vscode": { |
| 33 | "extensions": [ |
| 34 | "dbaeumer.vscode-eslint", |
| 35 | "esbenp.prettier-vscode", |
| 36 | "ms-python.python" |
| 37 | ], |
| 38 | "settings": { |
| 39 | "editor.formatOnSave": true |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | ``` |
| 45 | |
| 46 | ### Docker Compose Dev Container |
| 47 | |
| 48 | ```json |
| 49 | // .devcontainer/devcontainer.json |
| 50 | { |
| 51 | "name": "Full Stack Dev", |
| 52 | "dockerComposeFile": "docker-compose.yml", |
| 53 | "service": "app", |
| 54 | "workspaceFolder": "/workspace", |
| 55 | "forwardPorts": [3000, 5432, 6379], |
| 56 | "postCreateCommand": "npm install && npx prisma migrate dev" |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | ```yaml |
| 61 | # .devcontainer/docker-compose.yml |
| 62 | services: |
| 63 | app: |
| 64 | build: |
| 65 | context: .. |
| 66 | dockerfile: .devcontainer/Dockerfile |
| 67 | volumes: |
| 68 | - ..:/workspace:cached |
| 69 | command: sleep infinity |
| 70 | depends_on: [db, redis] |
| 71 | |
| 72 | db: |
| 73 | image: postgres:16 |
| 74 | environment: |
| 75 | POSTGRES_DB: dev |
| 76 | POSTGRES_USER: dev |
| 77 | POSTGRES_PASSWORD: dev |
| 78 | volumes: |
| 79 | - pgdata:/var/lib/postgresql/data |
| 80 | ports: |
| 81 | - "5432:5432" |
| 82 | |
| 83 | redis: |
| 84 | image: redis:7-alpine |
| 85 | ports: |
| 86 | - "6379:6379" |
| 87 | |
| 88 | volumes: |
| 89 | pgdata: |
| 90 | ``` |
| 91 | |
| 92 | ### Custom Dockerfile |
| 93 | |
| 94 | ```dockerfile |
| 95 | # .devcontainer/Dockerfile |
| 96 | FROM mcr.microsoft.com/devcontainers/base:ubuntu-22.04 |
| 97 | |
| 98 | # System dependencies |
| 99 | RUN apt-get update && apt-get install -y \ |
| 100 | build-essential \ |
| 101 | curl \ |
| 102 | git \ |
| 103 | jq \ |
| 104 | unzip \ |
| 105 | && rm -rf /var/lib/apt/lists/* |
| 106 | |
| 107 | # Install project-specific tools |
| 108 | RUN curl -fsSL https://get.opentofu.org/install-opentofu.sh | sh -s -- --install-method standalone |
| 109 | RUN curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \ |
| 110 | && install kubectl /usr/local/bin/ |
| 111 | |
| 112 | # Non-root user setup |
| 113 | USER vscode |
| 114 | WORKDIR /workspace |
| 115 | ``` |
| 116 | |
| 117 | ## Nix Flakes |
| 118 | |
| 119 | ### Basic Flake |
| 120 | |
| 121 | ```nix |
| 122 | # flake.nix |
| 123 | { |
| 124 | description = "Project development environment"; |
| 125 | |
| 126 | inputs = { |
| 127 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 128 | flake-utils.url = "github:numtide/flake-utils"; |
| 129 | }; |
| 130 | |
| 131 | outputs = { self, nixpkgs, flake-utils }: |
| 132 | flake-utils.lib.eachDefaultSystem (system: |
| 133 | let |
| 134 | pkgs = nixpkgs.legacyPackages.${system}; |
| 135 | in { |
| 136 | devShells.default = pkgs.mkShell { |
| 137 | buildInputs = with pkgs; [ |
| 138 | # Languages |
| 139 | nodejs_20 |
| 140 | python312 |
| 141 | go_1_22 |
| 142 | rustc |
| 143 | cargo |
| 144 | |
| 145 | # Tools |
| 146 | docker-compose |
| 147 | kubectl |
| 148 | kubernetes-helm |
| 149 | opentofu |
| 150 | awscli2 |
| 151 | jq |
| 152 | yq-go |
| 153 | |
| 154 | # Databases |
| 155 | postgresql_16 |
| 156 | redis |
| 157 | ]; |
| 158 | |
| 159 | shellHook = '' |
| 160 | echo "Dev environment loaded" |
| 161 | export PROJECT_ROOT=$(pwd) |
| 162 | export PATH="$PROJECT_ROOT/node_modules/.bin:$PATH" |
| 163 | ''; |
| 164 | }; |
| 165 | } |
| 166 | ); |
| 167 | } |
| 168 | ``` |
| 169 | |
| 170 | ```bash |
| 171 | # Enter the dev shell |
| 172 | nix develop |
| 173 | |
| 174 | # Or run a single command |
| 175 | nix develop --command bash -c "node --version && go version" |
| 176 | |
| 177 | # Build and run |
| 178 | nix build |
| 179 | nix run |
| 180 | ``` |
| 181 | |
| 182 | ### Pin Dependencies |
| 183 | |
| 184 | ```bash |
| 185 | # Lock flake inputs for reproducibility |
| 186 | nix flake lock |
| 187 | nix flake update # Update all inputs |
| 188 | |
| 189 | # Update a specific input |
| 190 | nix flake lock --update-input nixpkgs |
| 191 | ``` |
| 192 | |
| 193 | ## Devbox (Nix Made Simple) |
| 194 | |
| 195 | Devbox wraps Nix with a friendlier interface: |
| 196 | |
| 197 | ```bash |
| 198 | # Install Devbox |
| 199 | curl -fsSL https://get.jetify.com/devbox | bash |
| 200 | |
| 201 | # Initialize project |
| 202 | devbox init |
| 203 | |
| 204 | # Add packages |
| 205 | devbox add nodejs@20 python@3.12 postgresql@16 |
| 206 | devbox add go@1.22 kubectl helm |
| 207 | |
| 208 | # Enter shell |
| 209 | devbox shell |
| 210 | |
| 211 | # Run commands without entering shell |
| 212 | devbox run node --version |
| 213 | ``` |
| 214 | |
| 215 | ### devbox.json Configuration |
| 216 | |
| 217 | ```json |
| 218 | { |
| 219 | "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/main/.schema/devbox.schema.json", |
| 220 | "packages": [ |
| 221 | "nodejs@20", |