|
| 1 | +--- |
| 2 | +title: Development Environment |
| 3 | +parent: Contributing |
| 4 | +nav_order: 1 |
| 5 | +--- |
| 6 | + |
| 7 | +This project provides two options for setting up a development environment with |
| 8 | +all the linting and development tools used in CI. |
| 9 | + |
| 10 | +## Option 1: Nix Flakes (Recommended) |
| 11 | + |
| 12 | +[Nix flakes](https://nixos.wiki/wiki/Flakes) provide a reproducible development |
| 13 | +environment that works on any Linux distribution. |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +- [Nix](https://nixos.org/download.html) with flakes enabled |
| 18 | +- Optionally [direnv](https://direnv.net/) for automatic shell activation |
| 19 | + |
| 20 | +#### Enabling Flakes |
| 21 | + |
| 22 | +If you haven't enabled flakes, add this to `~/.config/nix/nix.conf`: |
| 23 | + |
| 24 | +```ini |
| 25 | +experimental-features = nix-command flakes |
| 26 | +``` |
| 27 | + |
| 28 | +### Entering the Development Shell |
| 29 | + |
| 30 | +```bash |
| 31 | +# One-time use |
| 32 | +nix develop |
| 33 | + |
| 34 | +# Or with direnv (recommended) |
| 35 | +direnv allow |
| 36 | +``` |
| 37 | + |
| 38 | +### Available Tools |
| 39 | + |
| 40 | +The development shell includes all tools used in CI: |
| 41 | + |
| 42 | +| Tool | Purpose | |
| 43 | +|------|---------| |
| 44 | +| `shellcheck` | Bash script linting | |
| 45 | +| `shfmt` | Bash script formatting | |
| 46 | +| `nil` | Nix language diagnostics | |
| 47 | +| `nixfmt-rfc-style` | Nix code formatting | |
| 48 | +| `hadolint` | Dockerfile linting | |
| 49 | +| `markdownlint-cli2` | Markdown linting | |
| 50 | +| `cspell` | Spell checking | |
| 51 | +| `actionlint` | GitHub Actions workflow linting | |
| 52 | +| `yamllint` | YAML linting | |
| 53 | +| `podman` | Container runtime | |
| 54 | +| `gh` | GitHub CLI | |
| 55 | + |
| 56 | +## Option 2: VS Code Devcontainer |
| 57 | + |
| 58 | +If you use VS Code and prefer containers over Nix, a |
| 59 | +[devcontainer](https://containers.dev/) configuration is included. |
| 60 | + |
| 61 | +### Requirements |
| 62 | + |
| 63 | +- [VS Code](https://code.visualstudio.com/) |
| 64 | +- [Dev Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) |
| 65 | +- Docker or Podman |
| 66 | + |
| 67 | +### Getting Started |
| 68 | + |
| 69 | +1. Open the project in VS Code |
| 70 | +2. When prompted, click "Reopen in Container" |
| 71 | +3. Or use the command palette: `Dev Containers: Reopen in Container` |
| 72 | + |
| 73 | +The devcontainer includes: |
| 74 | + |
| 75 | +- Docker-in-docker for building images |
| 76 | +- Nix with `nil` language server |
| 77 | +- shellcheck and hadolint |
| 78 | +- VS Code extensions for real-time linting feedback |
| 79 | + |
| 80 | +## Running Linters Locally |
| 81 | + |
| 82 | +Run these before submitting a PR to catch issues early: |
| 83 | + |
| 84 | +```bash |
| 85 | +# Bash scripts |
| 86 | +shellcheck *.sh bin/*.sh |
| 87 | +shfmt -d *.sh bin/*.sh |
| 88 | + |
| 89 | +# Nix files |
| 90 | +nil diagnostics *.nix |
| 91 | +nixfmt-rfc-style --check *.nix |
| 92 | + |
| 93 | +# Dockerfile |
| 94 | +hadolint Dockerfile |
| 95 | + |
| 96 | +# Markdown |
| 97 | +markdownlint-cli2 "**/*.md" |
| 98 | +cspell "**/*.md" |
| 99 | + |
| 100 | +# GitHub Actions |
| 101 | +actionlint |
| 102 | + |
| 103 | +# YAML |
| 104 | +yamllint .github/workflows/ |
| 105 | +``` |
| 106 | + |
| 107 | +## Building the Documentation Locally |
| 108 | + |
| 109 | +The documentation uses Jekyll with the just-the-docs theme. |
| 110 | + |
| 111 | +```bash |
| 112 | +cd docs |
| 113 | +bundle install |
| 114 | +bundle exec jekyll serve |
| 115 | +``` |
| 116 | + |
| 117 | +Then open <http://localhost:4000> in your browser. |
| 118 | + |
| 119 | +## Building the Container Image |
| 120 | + |
| 121 | +```bash |
| 122 | +# Build the image |
| 123 | +podman build -t zwift:dev . |
| 124 | + |
| 125 | +# Or use the build script |
| 126 | +./bin/build-image.sh |
| 127 | +``` |
| 128 | + |
| 129 | +## Testing Changes |
| 130 | + |
| 131 | +```bash |
| 132 | +# Dry run to see what would be executed |
| 133 | +DRYRUN=1 ./zwift.sh |
| 134 | + |
| 135 | +# Run in foreground for debugging |
| 136 | +ZWIFT_FG=1 ./zwift.sh |
| 137 | + |
| 138 | +# Interactive mode (drops into container shell) |
| 139 | +INTERACTIVE=1 ./zwift.sh |
| 140 | +``` |
0 commit comments