Repository navigation
Expand file tree
/
Copy pathdevenv.nix
More file actions
208 lines (193 loc) · 5.21 KB
/
Copy pathdevenv.nix
File metadata and controls
208 lines (193 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{
pkgs,
config,
...
}:
let
appleContainerCliPresent =
pkgs.stdenv.isDarwin
&& (
builtins.pathExists /usr/local/bin/container || builtins.pathExists /opt/homebrew/bin/container
);
in
{
cachix.pull = [ "mostlyobvious" ];
languages.ruby.enable = true;
languages.ruby.version = "4.0.5";
languages.ruby.bundler.package =
(pkgs.bundler.override { ruby = config.languages.ruby.package; }).overrideAttrs
(_: rec {
version = "4.0.15";
src = pkgs.fetchurl {
url = "https://rubygems.org/gems/bundler-${version}.gem";
hash = "sha256-pM64gv6UoOCsY80IE5Mrv9YxoU5awLeXUYmxmk0o2ec=";
};
});
packages = [
pkgs.postgresql_18
pkgs.postgresql_18.pg_config
pkgs.sqlfluff
pkgs.rubyPackages.syntax_tree
pkgs.jq
pkgs.libyaml
pkgs.pi-coding-agent
pkgs.claude-code
pkgs.nodejs
];
enterShell = ''
export MUTANT_SINCE="''${MUTANT_SINCE:-HEAD}"
'';
enterTest = ''
devenv tasks run test
'';
env = pkgs.lib.optionalAttrs appleContainerCliPresent {
OCIMAN_BACKEND = "docker";
};
services.postgres = {
enable = true;
package = pkgs.postgresql_18;
initialDatabases =
let
seededSchema = pkgs.concatText "golden-en57-seeded.sql" [
./db/schema/0.1.0.sql
./db/seeds/concurrent_append_non_conflicting_tags_seeded.sql
];
in
[
{
name = "golden_en57";
schema = ./db/schema/0.1.0.sql;
}
{
name = "golden_res";
schema = ./db/seeds/res.sql;
}
{
name = "golden_en57_seeded";
schema = seededSchema;
}
];
};
files = {
".pi/settings.json".json = {
packages = [ "npm:pi-edit-hooks@0.2.1" ];
};
".pi/edit-hooks.json".json = {
onEdit = {
"*" = "treefmt {file}";
};
onStop = {
"*" = "devenv tasks run test";
};
};
};
tasks =
let
minitest = filter: ''
ruby -Itest -Ilib <<'RUBY'
require "bundler/setup"
Dir["test/test_*.rb"].sort.each { require File.expand_path(it) }
Minitest::Runnable.runnables.reject! { ${filter} }
RUBY
'';
in
{
"devenv:enterShell".after = [ "dev:setup" ];
"dev:setup".exec = "bundle install --quiet";
"dev:format".exec = "treefmt";
"test:unit" = {
exec = minitest "it.superclass != Minitest::Test || it == En57::IntegrationTest";
after = [ "dev:setup" ];
};
"test:integration" = {
exec = minitest "it.superclass != En57::IntegrationTest";
after = [ "dev:setup" ];
};
"test:mutate" = {
exec = ''bin/mutant run --since "''${MUTANT_SINCE:-HEAD}"'';
after = [ "dev:setup" ];
};
"test:pg" = {
exec = "pg-regress";
after = [ "dev:setup" ];
};
};
treefmt.enable = true;
treefmt.config = {
programs = {
nixfmt.enable = true;
};
settings.formatter = {
ruby = {
command = "${pkgs.rubyPackages.syntax_tree}/bin/stree";
options = [ "write" ];
includes = [ "*.rb" ];
};
sql = {
command = "sqlfluff";
options = [
"format"
"--dialect"
"postgres"
"--exclude-rules"
"LT05"
];
includes = [ "db/**/*.sql" ];
};
};
};
scripts = {
pg-regress.exec = ''
set -euo pipefail
cd "$DEVENV_ROOT"
rm -rf test/pg_regress/results
mkdir -p test/pg_regress/results
ruby -r bundler/setup -r pg_ephemeral <<'RUBY'
exit(
PgEphemeral.with_server do |server|
system(
"${pkgs.postgresql_18.dev}/lib/pgxs/src/test/regress/pg_regress",
"--use-existing",
"--dbname=#{server.url}",
"--inputdir=test/pg_regress",
"--outputdir=test/pg_regress/results",
"--expecteddir=test/pg_regress",
"--bindir=${pkgs.postgresql_18}/bin",
"--schedule=test/pg_regress/schedule_existing",
) ? 0 : 1
end,
)
RUBY
'';
}
// pkgs.lib.optionalAttrs appleContainerCliPresent {
docker.exec = builtins.readFile (
pkgs.fetchurl {
url = "https://raw.githubusercontent.com/mostlyobvious/apple-container-docker-shim/refs/heads/main/bin/docker";
hash = "sha256-lg9Z5sMwthWUd9cogJpqkdWfacIl5ji4R/lLl4GdbGg=";
}
);
};
claude.code.enable = true;
claude.code.hooks = {
format = {
name = "Format edited files with treefmt";
hookType = "PostToolUse";
matcher = "Write|Edit";
command = ''
jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; treefmt "$f"; } 2>/dev/null || true
'';
};
test = {
name = "Run devenv tasks run test on stop";
hookType = "Stop";
command = ''
input=$(cat)
cd "''${DEVENV_ROOT:-.}" || exit 0
devenv tasks run test 1>&2 && exit 0
[ "$(printf '%s' "$input" | jq -r '.stop_hook_active // false')" = "true" ] && exit 0
exit 2
'';
};
};
}