Skip to content

Commit 9a7feff

Browse files
floatdropclaude
andauthored
chore: add devenv development environment (#38)
Add a devenv (devenv.sh) config pinning the Go toolchain to match go.mod along with golangci-lint, golines, goimports, gopls, and dlv, so the dev environment is reproducible across machines. Includes convenience scripts (build/test/test-race/lint/bench/modernize) wrapping the canonical commands. Wire up direnv auto-activation via .envrc, ignore devenv's generated state in .gitignore (keeping devenv.lock tracked), and document the optional setup in the README. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c882b5a commit 9a7feff

6 files changed

Lines changed: 166 additions & 0 deletions

File tree

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Auto-load the devenv shell via direnv — https://devenv.sh/automatic-shell-activation/
2+
# Run `direnv allow` once to trust this file.
3+
source_url "https://raw.githubusercontent.com/cachix/devenv/82c0147677e510b247d8b9165c54f73d32dfd899/direnvrc" "sha256-7u4iDd1nZpxL4tCzmPG0dQgC5V+/44Ba+tHkPob1v2k="
4+
5+
use devenv

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ interop/certs/
4343

4444
# Local custom prompts
4545
CLAUDE.local.md
46+
47+
# devenv (https://devenv.sh) — generated state; devenv.lock is committed
48+
.devenv*
49+
devenv.local.nix
50+
.direnv/

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ golangci-lint run # lint + format check (.golangci.yml)
178178
For the benchmark suite and the `benchstat` regression-comparison workflow, see
179179
[`benchmarks/README.md`](benchmarks/README.md).
180180

181+
### Development environment (devenv + direnv)
182+
183+
The repo ships a [devenv](https://devenv.sh) config (`devenv.nix`) that pins the
184+
Go toolchain (matching `go.mod`) plus `golangci-lint`, `golines`, `goimports`,
185+
`gopls`, and `dlv` — so everyone builds against the same versions. It is
186+
optional: a plain `go` install works fine. With [Nix](https://nixos.org)
187+
installed:
188+
189+
```sh
190+
# One-time: install devenv and direnv.
191+
nix profile add nixpkgs#devenv nixpkgs#direnv
192+
```
193+
194+
Then either enter the shell on demand:
195+
196+
```sh
197+
devenv shell # drops you into a shell with the full toolchain on PATH
198+
devenv test # sanity-check the toolchain wiring
199+
```
200+
201+
…or let [direnv](https://direnv.net) load it automatically on `cd` (recommended).
202+
Hook direnv into your shell once (see the
203+
[direnv setup guide](https://direnv.net/docs/hook.html)), e.g. for zsh:
204+
205+
```sh
206+
echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc
207+
```
208+
209+
then trust this repo's `.envrc` once:
210+
211+
```sh
212+
direnv allow # run from the repo root; re-run if .envrc changes
213+
```
214+
215+
After that the environment activates whenever you enter the directory. Inside
216+
the shell, convenience scripts wrap the canonical commands: `build`, `test`,
217+
`test-race`, `lint`, `bench`, and `modernize`.
218+
181219
### Interoperability tests
182220

183221
This implementation is registered (as `moq-go`) in the

devenv.lock

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"nodes": {
3+
"devenv": {
4+
"locked": {
5+
"dir": "src/modules",
6+
"lastModified": 1782824668,
7+
"narHash": "sha256-/fWk/eiw0PzFSxO2XsPBmiGEe7fB04jC6fro1mn+8+o=",
8+
"owner": "cachix",
9+
"repo": "devenv",
10+
"rev": "a247a920e43d7633e48e9fc0cd95bab53514a72f",
11+
"type": "github"
12+
},
13+
"original": {
14+
"dir": "src/modules",
15+
"owner": "cachix",
16+
"repo": "devenv",
17+
"type": "github"
18+
}
19+
},
20+
"nixpkgs": {
21+
"inputs": {
22+
"nixpkgs-src": "nixpkgs-src"
23+
},
24+
"locked": {
25+
"lastModified": 1782132010,
26+
"narHash": "sha256-ZnAVHdVrotp80iIMm5CSR1fdxPlw7Uwmwxb+O/wsgZ8=",
27+
"owner": "cachix",
28+
"repo": "devenv-nixpkgs",
29+
"rev": "12866ae2dddbc0ab8b329915f8072bb9c75bde89",
30+
"type": "github"
31+
},
32+
"original": {
33+
"owner": "cachix",
34+
"ref": "rolling",
35+
"repo": "devenv-nixpkgs",
36+
"type": "github"
37+
}
38+
},
39+
"nixpkgs-src": {
40+
"flake": false,
41+
"locked": {
42+
"lastModified": 1781607440,
43+
"narHash": "sha256-rxO+uc/KFbSJp+pgyXRuAX6QlG9hJdnt0BXpEQRXY+U=",
44+
"owner": "NixOS",
45+
"repo": "nixpkgs",
46+
"rev": "3e41b24abd260e8f71dbe2f5737d24122f972158",
47+
"type": "github"
48+
},
49+
"original": {
50+
"owner": "NixOS",
51+
"ref": "nixpkgs-unstable",
52+
"repo": "nixpkgs",
53+
"type": "github"
54+
}
55+
},
56+
"root": {
57+
"inputs": {
58+
"devenv": "devenv",
59+
"nixpkgs": "nixpkgs"
60+
}
61+
}
62+
},
63+
"root": "root",
64+
"version": 7
65+
}

devenv.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{ pkgs, lib, config, ... }:
2+
3+
{
4+
# https://devenv.sh/basics/
5+
# A reproducible Go development environment for moq-go.
6+
7+
# https://devenv.sh/languages/
8+
# Provides the Go toolchain (matching go.mod's `go 1.26`) plus go env wiring.
9+
languages.go.enable = true;
10+
11+
# https://devenv.sh/packages/
12+
# Tooling the repo expects on PATH. The lint config (.golangci.yml) enables the
13+
# `goimports` and `golines` formatters, so both must be available.
14+
packages = with pkgs; [
15+
golangci-lint # `golangci-lint run` — see .golangci.yml
16+
golines # long-line formatter enabled in .golangci.yml
17+
gotools # provides goimports
18+
gopls # language server
19+
delve # `dlv` debugger
20+
gnumake # the Makefile drives build/test/interop targets
21+
];
22+
23+
# https://devenv.sh/scripts/
24+
# Thin wrappers around the canonical commands from CLAUDE.md / the Makefile.
25+
scripts.build.exec = "go build ./...";
26+
scripts.test.exec = "go test ./...";
27+
scripts.test-race.exec = "go test -race ./...";
28+
scripts.lint.exec = "golangci-lint run";
29+
scripts.bench.exec = "go test -run='^$' -bench=. -benchmem ./...";
30+
# modernize check (errorsastype) — see CLAUDE.md; run standalone until
31+
# golangci-lint bundles the analyzer. Pass -fix to apply.
32+
scripts.modernize.exec = ''
33+
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest \
34+
-errorsastype "$@" ./...
35+
'';
36+
37+
enterShell = ''
38+
echo "moq-go devenv — go $(go version | cut -d' ' -f3 | sed 's/go//')"
39+
echo " scripts: build | test | test-race | lint | bench | modernize"
40+
'';
41+
42+
# https://devenv.sh/tests/
43+
# `devenv test` sanity-checks the toolchain wiring.
44+
enterTest = ''
45+
go version
46+
golangci-lint version
47+
'';
48+
}

devenv.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# devenv inputs — https://devenv.sh/inputs/
2+
# `rolling` tracks a recent nixpkgs so the Go toolchain matches go.mod (go 1.26).
3+
inputs:
4+
nixpkgs:
5+
url: github:cachix/devenv-nixpkgs/rolling

0 commit comments

Comments
 (0)