Skip to content

Commit 0c2c43c

Browse files
committed
refactor(devshell): improve devshell experience
The current development shell include a large number of packages which leads to a very large closure size (5 Gb) and slow startup times. To improve the situation we defer installing large packages to devshell commands which only get installed when needed. We introduce the use of devshell to define the commands in a declarative way as well as to improve the overall developer experience. Included changes: - Add organized command menu with categories (check, ami, extension, postgres) - Add watch command using watchexec + nix-fast-build for continuous checking - Expose common tasks as named commands: fmt, check, lint, watch - Add aws-vault to development tools
1 parent 328f4db commit 0c2c43c

File tree

5 files changed

+115
-18
lines changed

5 files changed

+115
-18
lines changed

flake.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
];
88
};
99
inputs = {
10+
devshell.url = "github:numtide/devshell";
11+
devshell.inputs.nixpkgs.follows = "nixpkgs";
1012
flake-parts.url = "github:hercules-ci/flake-parts";
1113
flake-utils.url = "github:numtide/flake-utils";
1214
git-hooks.inputs.nixpkgs.follows = "nixpkgs";

nix/checks.nix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
perSystem =
44
{
55
self',
6-
system,
76
pkgs,
87
lib,
98
...
@@ -394,6 +393,7 @@
394393
packer
395394
pg_regress
396395
;
396+
devShell = self'.devShells.default;
397397
}
398398
// pkgs.lib.optionalAttrs (pkgs.stdenv.isLinux) (
399399
{
@@ -410,7 +410,6 @@
410410
inherit self;
411411
inherit pkgs;
412412
})
413-
)
414-
// pkgs.lib.optionalAttrs (system == "x86_64-linux") ({ devShell = self'.devShells.default; });
413+
);
415414
};
416415
}

nix/devShells.nix

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pkgs,
66
self',
77
config,
8+
lib,
89
...
910
}:
1011
let
@@ -34,7 +35,7 @@
3435
in
3536
{
3637
devShells = {
37-
default = pkgs.mkShell {
38+
default = pkgs.devshell.mkShell {
3839
packages =
3940
with pkgs;
4041
[
@@ -45,26 +46,99 @@
4546
shellcheck
4647
ansible
4748
ansible-lint
48-
self'.packages.packer
49-
50-
self'.packages.start-server
51-
self'.packages.start-client
52-
self'.packages.start-replica
53-
self'.packages.migrate-tool
54-
self'.packages.sync-exts-versions
55-
self'.packages.build-test-ami
56-
self'.packages.run-testinfra
57-
self'.packages.cleanup-ami
49+
aws-vault
50+
packer
5851
dbmate
5952
nushell
6053
pythonEnv
6154
config.treefmt.build.wrapper
6255
]
6356
++ self'.packages.docs.nativeBuildInputs;
64-
shellHook = ''
65-
export HISTFILE=.history
66-
${config.pre-commit.installationScript}
67-
'';
57+
devshell.startup.pre-commit.text = config.pre-commit.installationScript;
58+
commands = [
59+
{
60+
name = "fmt";
61+
help = "Format code";
62+
command = "nix fmt";
63+
category = "check";
64+
}
65+
{
66+
name = "check";
67+
help = "Run all checks";
68+
command = "nix flake -L check -v";
69+
category = "check";
70+
}
71+
{
72+
name = "lint";
73+
help = "Lint code";
74+
command = "pre-commit run --all-files";
75+
category = "check";
76+
}
77+
{
78+
name = "watch";
79+
help = "Watch for file changes and run all checks";
80+
command =
81+
let
82+
watchExec = lib.getExe pkgs.watchexec;
83+
nixFastBuild = ''
84+
${lib.getExe pkgs.nix} run github:Mic92/nix-fast-build -- \
85+
--skip-cached --retries=2 --no-download --option warn-dirty false \
86+
--option accept-flake-config true --no-link \
87+
--flake ".#checks.${pkgs.stdenv.hostPlatform.system}"
88+
'';
89+
in
90+
"${watchExec} --on-busy-update=queue -w . --ignore '.jj/*' --timings -- ${nixFastBuild}";
91+
category = "check";
92+
}
93+
{
94+
name = "cleanup-ami";
95+
help = "Deregister AMIs by name";
96+
command = "${lib.getExe self'.packages.cleanup-ami} $@";
97+
category = "ami";
98+
}
99+
{
100+
name = "build-test-ami";
101+
help = "Build AMI images for PostgreSQL testing";
102+
command = "${lib.getExe self'.packages.build-test-ami} $@";
103+
category = "ami";
104+
}
105+
{
106+
name = "sync-exts-versions";
107+
help = "Update extensions versions";
108+
command = "${lib.getExe self'.packages.sync-exts-versions}";
109+
category = "extension";
110+
}
111+
{
112+
name = "start-postgres-server";
113+
help = "Start a local Postgres server";
114+
command = "${lib.getExe pkgs.nix} run .#start-server -- $@";
115+
category = "postgres";
116+
}
117+
{
118+
name = "start-postgres-client";
119+
help = "Start an interactive psql with the specified Postgres version";
120+
command = "${lib.getExe pkgs.nix} run .#start-client -- $@";
121+
category = "postgres";
122+
}
123+
{
124+
name = "start-postgres-replica";
125+
help = "Start a local Postgres replica server";
126+
command = "${lib.getExe pkgs.nix} run .#start-replica -- $@";
127+
category = "postgres";
128+
}
129+
{
130+
name = "migrate-postgres";
131+
help = "Run database migrations";
132+
command = "${lib.getExe pkgs.nix} run .#migrate-tool -- $@";
133+
category = "postgres";
134+
}
135+
{
136+
name = "dbmate-tool";
137+
help = "Run dbmate against specified local Postgres database";
138+
command = "${lib.getExe pkgs.nix} run .#dbmate-tool -- $@";
139+
category = "postgres";
140+
}
141+
];
68142
};
69143
cargo-pgrx_0_11_3 = mkCargoPgrxDevShell {
70144
pgrxVersion = "0_11_3";

nix/nixpkgs.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
v8_oldstable = oldstable.v8;
2424
}
2525
)
26+
inputs.devshell.overlays.default
2627
];
2728
};
2829
};

0 commit comments

Comments
 (0)