If you use Nix and want a reproducible Go development environment with VSCodium as your editor, a shell.nix file is the cleanest way to get there. The configuration below sets up a full Go toolchain — including the gopls language server, the delve debugger, linters, and code-generation utilities — alongside VSCodium pre-loaded with the official Go extension, GitLens, error highlighting, and a REST client. CGO is enabled together with gcc and sqlite, so packages like go-sqlite3 that rely on C bindings compile without issues. A step-by-step status log is printed during initialisation so you always know what the shell is doing while it loads. All dependencies are pinned to your nixpkgs channel, so every team member or machine gets an identical environment simply by running nix-shell. Once inside the shell, open your project with codium . and everything is ready to go.
{ pkgs ? import <nixpkgs> {
# Required to allow extensions with non-free licenses (e.g. gitlens)
config.allowUnfree = true;
}
}:
let
vscodiumWithExtensions = pkgs.vscode-with-extensions.override {
vscode = pkgs.vscodium;
vscodeExtensions = with pkgs.vscode-extensions; [
# Go language support (official Go team extension)
golang.go
# Git integration
# Note: mhutchie.git-graph is unfree and has been intentionally removed.
# Use VSCodium's built-in git view or install git-graph manually.
eamodio.gitlens
# General productivity
streetsidesoftware.code-spell-checker
usernamehw.errorlens
# REST client for API testing
humao.rest-client
];
};
in pkgs.mkShell {
name = "golang-dev";
buildInputs = [
# ── Go toolchain ──────────────────────────────────────────────────────────
pkgs.go # Go compiler & standard tooling (go build, go test…)
pkgs.gopls # Official Go language server (used by the extension)
pkgs.delve # Go debugger
pkgs.gotools # Extra tools: goimports, godoc, etc.
pkgs.golangci-lint # Fast, multi-linter runner
pkgs.gomodifytags # Struct tag editor (used by vscode-go)
pkgs.gotests # Auto-generate table-driven tests
pkgs.impl # Generate method stubs for interfaces
pkgs.go-outline # JSON representation of Go file outline
pkgs.gotestsum # Prettier `go test` output
# ── Editor ────────────────────────────────────────────────────────────────
vscodiumWithExtensions
# ── C toolchain (required for CGO / go-sqlite3) ───────────────────────────
pkgs.gcc
pkgs.sqlite
# ── Shell / system utilities ──────────────────────────────────────────────
pkgs.git
pkgs.curl
pkgs.jq # Handy for JSON output while developing APIs
];
# ── Environment variables ─────────────────────────────────────────────────
shellHook = ''
echo ""
echo "● Initialising golang-dev shell…"
echo ""
# ── Environment ───────────────────────────────────────────────────────────
echo " [1/4] Setting up environment variables…"
export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
export GOTELEMETRY=off
export CGO_ENABLED=1
echo " GOPATH=$GOPATH"
echo " CGO_ENABLED=$CGO_ENABLED (sqlite3 / cgo support)"
echo " GOTELEMETRY=$GOTELEMETRY"
# ── Go toolchain ──────────────────────────────────────────────────────────
echo ""
echo " [2/4] Verifying Go toolchain…"
echo " go $(go version 2>/dev/null | awk '{print $3, $4}')"
echo " gopls $(gopls version 2>/dev/null | head -1 || echo 'not found')"
echo " delve $(dlv version 2>/dev/null | head -1 || echo 'not found')"
echo " golangci $(golangci-lint --version 2>/dev/null | head -1 || echo 'not found')"
echo " gcc $(gcc --version 2>/dev/null | head -1 || echo 'not found')"
echo " sqlite3 $(sqlite3 --version 2>/dev/null | head -1 || echo 'not found')"
# ── GOPATH bin ────────────────────────────────────────────────────────────
echo ""
echo " [3/4] Checking GOPATH bin directory…"
if [ -d "$GOPATH/bin" ]; then
BIN_COUNT=$(ls "$GOPATH/bin" 2>/dev/null | wc -l | tr -d ' ')
echo " $GOPATH/bin ($BIN_COUNT tools installed)"
else
mkdir -p "$GOPATH/bin"
echo " $GOPATH/bin created (empty — tools will appear after go install)"
fi
# ── Editor ────────────────────────────────────────────────────────────────
echo ""
echo " [4/4] Checking VSCodium…"
if command -v codium &>/dev/null; then
echo " $(codium --version 2>/dev/null | head -1 | sed 's/^/codium /')"
else
echo " codium not found in PATH"
fi
# ── Ready ─────────────────────────────────────────────────────────────────
echo ""
echo "┌─────────────────────────────────────────┐"
echo "│ golang-dev shell ready ✓ │"
echo "│ │"
echo "│ Run 'codium .' to open VSCodium │"
echo "└─────────────────────────────────────────┘"
echo ""
'';
}