feat: add option to install tool

This commit is contained in:
eric
2026-03-07 06:54:30 +01:00
parent 80cc529de7
commit 53e498ca45
3 changed files with 42 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ env = devshell-lib.lib.mkDevShell {
inherit system;
src = ./.;
extraPackages = [ ];
preToolHook = "";
tools = [ ];
additionalHooks = { };
};
@@ -46,6 +47,30 @@ Expose it in `devShells` as `default` and run:
nix develop
```
Use `preToolHook` when a tool needs bootstrap work before the shell prints tool versions. This is useful for tools you install outside `nixpkgs`, as long as the hook is idempotent.
```nix
env = devshell-lib.lib.mkDevShell {
inherit system;
src = ./.;
# assumes `go` is already available in PATH, for example via `extraPackages`
preToolHook = ''
export GOBIN="$PWD/.tools/bin"
export PATH="$GOBIN:$PATH"
if ! command -v golangci-lint >/dev/null 2>&1; then
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
fi
'';
tools = [
{ name = "golangci-lint"; bin = "golangci-lint"; versionCmd = "version"; color = "YELLOW"; }
];
};
```
## Common commands
```bash