|
| 1 | +# Omnix Development Instructions |
| 2 | + |
| 3 | +**ALWAYS follow these instructions first and fallback to additional search and context gathering only if the information here is incomplete or found to be in error.** |
| 4 | + |
| 5 | +Omnix is a Rust-based CLI tool that supplements the Nix CLI to improve developer experience. The project requires Nix and uses a Nix flake-based development environment with multiple Rust crates organized as a workspace. |
| 6 | + |
| 7 | +## Prerequisites and Environment Setup |
| 8 | + |
| 9 | +### Essential Requirements |
| 10 | +- **Nix Package Manager**: Install from [nixos.asia/en/install](https://nixos.asia/en/install) or run: |
| 11 | + ```bash |
| 12 | + curl -L https://nixos.org/nix/install | sh -s -- --daemon |
| 13 | + ``` |
| 14 | +- **direnv**: Install and set up according to [nixos.asia/en/direnv](https://nixos.asia/en/direnv) |
| 15 | +- **Network Access**: Required for downloading dependencies and Nix packages |
| 16 | + |
| 17 | +### Development Environment Setup |
| 18 | +```bash |
| 19 | +# 1. Clone and enter the repository |
| 20 | +git clone <repo-url> |
| 21 | +cd omnix |
| 22 | + |
| 23 | +# 2. Activate direnv (this may take several minutes on first run) |
| 24 | +direnv allow |
| 25 | + |
| 26 | +# 3. Verify the environment is working |
| 27 | +just --list |
| 28 | +``` |
| 29 | + |
| 30 | +The `direnv allow` command will: |
| 31 | +- Download and cache Nix dependencies |
| 32 | +- Set up the development shell environment |
| 33 | +- Configure all necessary environment variables |
| 34 | +- Install development tools (just, bacon, etc.) |
| 35 | + |
| 36 | +## Building and Running |
| 37 | + |
| 38 | +### **CRITICAL**: Nix Environment Required |
| 39 | +**DO NOT attempt to build with `cargo build`, `just run`, `just clippy`, or `just cargo-test` directly** - they will fail because the code requires compile-time environment variables (FLAKE_ADDSTRINGCONTEXT, TRUE_FLAKE, FALSE_FLAKE, FLAKE_METADATA, DEFAULT_FLAKE_SCHEMAS, INSPECT_FLAKE, NIX_SYSTEMS) set by the Nix development environment. Always use the Nix-based workflows or ensure `direnv` is properly activated. |
| 40 | + |
| 41 | +### Primary Build Commands |
| 42 | +```bash |
| 43 | +# Full Nix build - NEVER CANCEL: Takes 10-15 minutes. Set timeout to 30+ minutes. |
| 44 | +nix build --accept-flake-config |
| 45 | + |
| 46 | +# Build and run the CLI |
| 47 | +nix run --accept-flake-config |
| 48 | + |
| 49 | +# For development with live reloading (recommended approach) |
| 50 | +just watch # or `just w` - requires Nix environment |
| 51 | +just watch show . # with arguments |
| 52 | +``` |
| 53 | + |
| 54 | +### Alternative Build Testing (Network Limited) |
| 55 | +When Nix installation is not possible due to network restrictions, you can verify project structure and some tooling: |
| 56 | +```bash |
| 57 | +# These work without Nix but will fail at compilation: |
| 58 | +just --list # Shows available commands |
| 59 | +cargo check # Will fail with env var errors after ~30 seconds |
| 60 | +just clippy # Will fail with same errors |
| 61 | +``` |
| 62 | + |
| 63 | +### Development Workflow |
| 64 | +```bash |
| 65 | +# Start live development mode - NEVER CANCEL: Initial compile takes 3-5 minutes |
| 66 | +just watch |
| 67 | + |
| 68 | +# Run specific commands during development (requires active direnv shell) |
| 69 | +nix run -- show . # Direct nix run approach |
| 70 | +nix run -- health . # Health checking |
| 71 | +``` |
| 72 | + |
| 73 | +## Testing and Quality Assurance |
| 74 | + |
| 75 | +### **CRITICAL**: All Testing Requires Nix Environment |
| 76 | +All test and quality assurance commands require the full Nix environment to be active. |
| 77 | + |
| 78 | +### Running Tests |
| 79 | +```bash |
| 80 | +# Run all tests - NEVER CANCEL: Takes 5-10 minutes. Set timeout to 20+ minutes. |
| 81 | +just cargo-test # Requires direnv/Nix environment |
| 82 | + |
| 83 | +# Run CI locally - NEVER CANCEL: Takes 15-30 minutes. Set timeout to 60+ minutes. |
| 84 | +just ci # Full Nix-based CI |
| 85 | + |
| 86 | +# Run CI with cargo in devshell (faster for development) |
| 87 | +just ci-cargo # Requires direnv/Nix environment |
| 88 | +``` |
| 89 | + |
| 90 | +### Code Quality Checks |
| 91 | +```bash |
| 92 | +# Run clippy linting - NEVER CANCEL: Fails after ~30 seconds without Nix. Set timeout to 10+ minutes with Nix. |
| 93 | +just clippy # Requires direnv/Nix environment |
| 94 | + |
| 95 | +# Run all pre-commit hooks and formatting (nixpkgs-fmt + rustfmt) |
| 96 | +just pca # Requires direnv/Nix environment |
| 97 | + |
| 98 | +# Build documentation |
| 99 | +just cargo-doc # Requires direnv/Nix environment |
| 100 | +``` |
| 101 | + |
| 102 | +### **MANDATORY**: Pre-commit Validation |
| 103 | +ALWAYS run these commands before committing changes or CI will fail: |
| 104 | +```bash |
| 105 | +just pca # Auto-format the entire codebase (nixpkgs-fmt + rustfmt) |
| 106 | +just clippy # Lint checks with zero warnings policy |
| 107 | +just cargo-test # Ensure all tests pass |
| 108 | +``` |
| 109 | + |
| 110 | +### Network-Limited Development |
| 111 | +When Nix environment is not available, you can still: |
| 112 | +```bash |
| 113 | +# Verify project structure and documentation |
| 114 | +ls -la # Inspect repository layout |
| 115 | +cat justfile # Review available commands |
| 116 | +cat README.md # Read project documentation |
| 117 | +find . -name "*.rs" | head # Explore Rust source files |
| 118 | +``` |
| 119 | + |
| 120 | +## Documentation |
| 121 | + |
| 122 | +### Website Documentation |
| 123 | +```bash |
| 124 | +# Preview documentation website |
| 125 | +just doc run |
| 126 | + |
| 127 | +# Check documentation for broken links |
| 128 | +just doc check |
| 129 | +``` |
| 130 | + |
| 131 | +### API Documentation |
| 132 | +```bash |
| 133 | +# Build Rust API documentation |
| 134 | +just cargo-doc |
| 135 | +``` |
| 136 | + |
| 137 | +## Project Structure and Navigation |
| 138 | + |
| 139 | +## Project Structure and Navigation |
| 140 | + |
| 141 | +### Key Directories |
| 142 | +- `crates/` - Rust workspace with 8 crates (~1MB total source): |
| 143 | + - `omnix-cli/` - Main CLI application (184K) |
| 144 | + - `nix_rs/` - Nix integration library (224K) |
| 145 | + - `omnix-ci/` - CI functionality (196K) |
| 146 | + - `omnix-health/` - Health checks (120K) |
| 147 | + - `omnix-gui/` - GUI components (152K) |
| 148 | + - `omnix-init/` - Project initialization (72K) |
| 149 | + - `omnix-develop/` - Development environment (32K) |
| 150 | + - `omnix-common/` - Shared utilities (44K) |
| 151 | +- `doc/` - Documentation source (~224K, emanote-based website) |
| 152 | +- `nix/` - Nix modules and environment definitions |
| 153 | +- `.github/workflows/` - CI/CD pipeline definitions |
| 154 | +- `target/` - Rust build artifacts (auto-generated, can be large) |
| 155 | + |
| 156 | +### Configuration Files |
| 157 | +- `flake.nix` - Main Nix flake definition and dependency management |
| 158 | +- `om.yaml` - Omnix configuration (CI, health, development settings) |
| 159 | +- `justfile` - Command definitions and development workflows |
| 160 | +- `bacon.toml` - File watching configuration for live development |
| 161 | +- `.envrc` - direnv setup that sources omnix's own development environment |
| 162 | +- `Cargo.toml` - Rust workspace configuration |
| 163 | +- `rust-toolchain.toml` - Rust compiler version specification |
| 164 | + |
| 165 | +### Common File Locations |
| 166 | +- Build outputs: `result/` (created by `nix build`) |
| 167 | +- Test configurations: `crates/*/tests/` |
| 168 | +- CI configuration: `om.yaml` (ci section) |
| 169 | +- Module definitions: `nix/modules/flake/` |
| 170 | +- Documentation source: `doc/*.md` and `doc/om/*.md` |
| 171 | +- Registry templates: `crates/omnix-init/registry/` |
| 172 | + |
| 173 | +### Code Organization Patterns |
| 174 | +```bash |
| 175 | +# Find all Rust source files |
| 176 | +find crates/ -name "*.rs" | wc -l # ~200+ source files |
| 177 | + |
| 178 | +# Explore main CLI structure |
| 179 | +ls crates/omnix-cli/src/ # Main application logic |
| 180 | + |
| 181 | +# Find all configuration files |
| 182 | +find . -name "*.nix" -o -name "*.yaml" -o -name "*.toml" | head -10 |
| 183 | + |
| 184 | +# Review test organization |
| 185 | +find . -path "*/tests/*" -name "*.rs" | head -5 |
| 186 | +``` |
| 187 | + |
| 188 | +## Troubleshooting and Common Issues |
| 189 | + |
| 190 | +### Build Failures |
| 191 | +- **`environment variable 'FLAKE_ADDSTRINGCONTEXT' not defined`**: This error occurs when building without Nix environment. Run `direnv allow` first. |
| 192 | +- **Cargo build fails with env var errors**: Use `nix build` or ensure `direnv` is properly activated |
| 193 | +- **`just` commands fail with compilation errors**: All `just` commands that invoke `cargo` require the Nix development environment |
| 194 | +- **Network timeout during `direnv allow`**: Builds require internet access for Nix packages from nixos.org and cache.nixos.asia |
| 195 | + |
| 196 | +### Environment Setup Issues |
| 197 | +- **`direnv: error .envrc is blocked`**: Run `direnv allow` in the repository root |
| 198 | +- **`nix: command not found`**: Install Nix first using the installer or package manager |
| 199 | +- **Slow first-time setup**: Initial `direnv allow` downloads ~1GB+ of dependencies |
| 200 | + |
| 201 | +### Network and Cache Issues |
| 202 | +- **Builds taking > 30 minutes**: Check access to cache.nixos.asia for binary cache |
| 203 | +- **DNS resolution failures**: Ensure access to nixos.org, github.com, and crates.io |
| 204 | +- **Behind corporate firewall**: May need to configure proxy settings for Nix |
| 205 | + |
| 206 | +### Performance Notes |
| 207 | +- **First-time setup**: 15-20 minutes for Nix to download dependencies |
| 208 | +- **Incremental builds**: 30 seconds to 2 minutes with `just watch` |
| 209 | +- **CI runs**: 15-30 minutes depending on system and cache availability |
| 210 | +- **Compilation without Nix environment**: Fails after 20-30 seconds with env var errors |
| 211 | + |
| 212 | +### Working in Network-Limited Environments |
| 213 | +When full Nix installation is not possible: |
| 214 | +1. **Read documentation thoroughly**: `cat README.md`, `cat justfile`, `find . -name "*.md"` |
| 215 | +2. **Explore codebase structure**: `find . -name "*.rs"`, `ls -la crates/` |
| 216 | +3. **Review configurations**: `cat flake.nix`, `cat om.yaml`, `cat Cargo.toml` |
| 217 | +4. **Test basic tooling**: `just --list` (works), `cargo check` (fails fast with clear error) |
| 218 | +5. **Document findings**: When network access is restored, validate all commands work |
| 219 | + |
| 220 | +## Validation Scenarios |
| 221 | + |
| 222 | +### **ESSENTIAL**: Verify Nix Environment First |
| 223 | +Before attempting any builds, validate the environment: |
| 224 | +```bash |
| 225 | +# Check if direnv is active (should show environment variables) |
| 226 | +env | grep -E "(FLAKE_|NIX_|TRUE_FLAKE|FALSE_FLAKE)" |
| 227 | + |
| 228 | +# Verify nix command is available |
| 229 | +nix --version |
| 230 | + |
| 231 | +# Test basic just functionality |
| 232 | +just --list |
| 233 | +``` |
| 234 | + |
| 235 | +### After Making Code Changes (Full Validation) |
| 236 | +**Only possible with complete Nix environment:** |
| 237 | +1. **Environment validation**: `env | grep FLAKE_` should show variables |
| 238 | +2. **Build validation**: `nix build --accept-flake-config` completes successfully |
| 239 | +3. **Basic functionality**: `nix run -- show .` displays project information |
| 240 | +4. **Health check**: `nix run -- health .` passes all checks |
| 241 | +5. **Live development**: `just watch` starts without compilation errors |
| 242 | +6. **Full test suite**: `just cargo-test` passes all tests |
| 243 | +7. **Linting**: `just clippy` shows no warnings |
| 244 | + |
| 245 | +### Before Committing (Mandatory Checks) |
| 246 | +**All require Nix environment:** |
| 247 | +1. **Format code**: `just pca` |
| 248 | +2. **Lint**: `just clippy` |
| 249 | +3. **Test**: `just cargo-test` |
| 250 | +4. **Build**: `nix build --accept-flake-config` |
| 251 | + |
| 252 | +### Manual Testing Scenarios (Post-Development) |
| 253 | +After changes, manually verify functionality: |
| 254 | +- **CLI help**: `nix run -- --help` shows current commands |
| 255 | +- **Show command**: `nix run -- show .` displays flake information correctly |
| 256 | +- **Health checks**: `nix run -- health .` reports system status |
| 257 | +- **Init functionality**: `nix run -- init --help` shows template options |
| 258 | + |
| 259 | +### Limited Validation (Network-Constrained Environments) |
| 260 | +When Nix is not available, you can still validate: |
| 261 | +1. **Project structure**: Verify files exist in expected locations |
| 262 | +2. **Documentation completeness**: `find . -name "*.md" -exec wc -l {} +` |
| 263 | +3. **Source code organization**: `find crates/ -name "*.rs" | wc -l` |
| 264 | +4. **Configuration validity**: `cat om.yaml` and `cat flake.nix` are parseable |
| 265 | +5. **Dependency analysis**: `grep -r "env!" crates/` shows compile-time env var usage |
| 266 | +6. **Build command syntax**: `just --show clippy` displays command correctly |
| 267 | + |
| 268 | +### Error Detection Patterns |
| 269 | +Learn to recognize these patterns: |
| 270 | +- **Missing Nix environment**: `environment variable 'FLAKE_ADDSTRINGCONTEXT' not defined` |
| 271 | +- **Network issues**: `curl: (6) Could not resolve host: nixos.org` |
| 272 | +- **direnv not activated**: `nix: command not found` in repository with .envrc |
| 273 | +- **Cache miss**: Builds taking > 15 minutes when they should be < 5 minutes |
| 274 | + |
| 275 | +## Time Expectations and Timeouts |
| 276 | + |
| 277 | +**CRITICAL**: Never cancel long-running operations. Use these timeout values: |
| 278 | + |
| 279 | +### Environment Setup Times |
| 280 | +- **Initial direnv setup**: 15-20 minutes (first time only, downloads ~1GB+) |
| 281 | +- **Subsequent direnv activation**: 5-10 seconds |
| 282 | +- **Tool installation (just, bacon)**: 1-3 minutes each |
| 283 | + |
| 284 | +### Build and Compilation Times |
| 285 | +- **Nix build (full)**: 10-15 minutes → Set timeout to 30+ minutes |
| 286 | +- **Nix build (with cache)**: 2-5 minutes → Set timeout to 15+ minutes |
| 287 | +- **Cargo compilation (with Nix env)**: 3-8 minutes → Set timeout to 20+ minutes |
| 288 | +- **Cargo compilation (without Nix env)**: Fails after 20-30 seconds with env var errors |
| 289 | + |
| 290 | +### Testing and Quality Assurance Times |
| 291 | +- **Full CI run (`just ci`)**: 15-30 minutes → Set timeout to 60+ minutes |
| 292 | +- **Cargo tests (`just cargo-test`)**: 5-10 minutes → Set timeout to 20+ minutes |
| 293 | +- **Clippy linting (`just clippy`)**: 2-3 minutes with Nix env → Set timeout to 10+ minutes |
| 294 | +- **Pre-commit hooks (`just pca`)**: 1-2 minutes → Set timeout to 5+ minutes |
| 295 | + |
| 296 | +### Development Workflow Times |
| 297 | +- **Live reloading (`just watch`)**: 30 seconds - 2 minutes per change |
| 298 | +- **Documentation build**: 2-5 minutes → Set timeout to 15+ minutes |
| 299 | +- **Single command execution**: 5-30 seconds depending on complexity |
| 300 | + |
| 301 | +### Network-Dependent Operations |
| 302 | +- **Package downloads**: Highly variable, 1-20 minutes depending on connection |
| 303 | +- **Cache fetching**: 30 seconds - 5 minutes from cache.nixos.asia |
| 304 | +- **Git operations**: Usually < 1 minute for this repository size |
| 305 | + |
| 306 | +### Fast Operations (< 1 minute) |
| 307 | +These should complete quickly and may indicate issues if they take longer: |
| 308 | +- `just --list` |
| 309 | +- `nix --version` |
| 310 | +- `cat` commands for documentation |
| 311 | +- Basic file system operations (`ls`, `find`, `grep`) |
| 312 | + |
| 313 | +## Network and Dependency Requirements |
| 314 | + |
| 315 | +### Required Network Access |
| 316 | +- `nixos.org` - Nix package downloads and documentation |
| 317 | +- `cache.nixos.org` - Default Nix binary cache |
| 318 | +- `cache.nixos.asia` - Custom project cache (oss channel) |
| 319 | +- `github.com` - Git dependencies and source repositories |
| 320 | +- `crates.io` - Rust dependencies (downloaded by Nix) |
| 321 | + |
| 322 | +### Network-Free Operations (Safe to Run Always) |
| 323 | +These commands work without network access and don't modify files: |
| 324 | +```bash |
| 325 | +# Repository exploration (always safe) |
| 326 | +ls -la # List repository contents |
| 327 | +find . -name "*.md" -exec wc -l {} + # Count documentation lines |
| 328 | +find crates/ -name "*.rs" | wc -l # Count Rust source files |
| 329 | +du -sh crates/* # Show crate sizes |
| 330 | + |
| 331 | +# Configuration inspection (always safe) |
| 332 | +cat justfile # View available commands |
| 333 | +cat README.md # Read project documentation |
| 334 | +cat om.yaml # View omnix configuration |
| 335 | +cat flake.nix # View Nix flake definition |
| 336 | +cat Cargo.toml # View Rust workspace setup |
| 337 | + |
| 338 | +# Tool verification (safe, may install tools) |
| 339 | +just --version # Check just installation |
| 340 | +just --list # Show available commands (works without Nix) |
| 341 | +bacon --help # Check bacon availability (if installed) |
| 342 | +cargo --version # Check Rust toolchain |
| 343 | + |
| 344 | +# Code analysis (safe, read-only) |
| 345 | +grep -r "env!" crates/ # Find compile-time environment variables |
| 346 | +find . -name "*.nix" | head # List Nix configuration files |
| 347 | +git log --oneline -5 # Recent commit history |
| 348 | +``` |
| 349 | + |
| 350 | +### Commands That Require Network (Use With Caution) |
| 351 | +These will fail in network-limited environments: |
| 352 | +```bash |
| 353 | +# Environment setup (requires network) |
| 354 | +direnv allow # Downloads Nix dependencies |
| 355 | +nix build # Requires Nix packages |
| 356 | +cargo install just # Downloads from crates.io |
| 357 | + |
| 358 | +# Any compilation (requires network for dependencies) |
| 359 | +cargo check # Will download crates if cache empty |
| 360 | +just clippy # Requires full environment |
| 361 | +just cargo-test # Requires full environment |
| 362 | +``` |
| 363 | + |
| 364 | +### Offline Development Workflow |
| 365 | +1. **With network**: Complete initial setup (`direnv allow`) |
| 366 | +2. **Offline**: Limited development is possible using cached dependencies |
| 367 | +3. **Validation**: Most build and test operations still require network for Nix evaluation |
| 368 | + |
| 369 | +### Cache and Storage Requirements |
| 370 | +- **Initial download**: ~1-2GB for complete development environment |
| 371 | +- **Build cache**: ~500MB-1GB for compiled artifacts in `target/` |
| 372 | +- **Nix store**: ~2-4GB for all dependencies and tools |
| 373 | +- **Repository**: ~200MB source code (plus build artifacts) |
0 commit comments