diff --git a/README.md b/README.md index 30b8cec..65da2ad 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flake.nix b/flake.nix index 8e2d91a..ae5269a 100644 --- a/flake.nix +++ b/flake.nix @@ -34,12 +34,15 @@ system, src ? ./., extraPackages ? [ ], + preToolHook ? "", extraShellHook ? "", additionalHooks ? { }, tools ? [ ], includeStandardPackages ? true, # tools = list of { name, bin, versionCmd, color? } # e.g. { name = "Bun"; bin = "${pkgs.bun}/bin/bun"; versionCmd = "--version"; color = "YELLOW"; } + # preToolHook = shell snippet that runs before the ready banner and tool logs + # e.g. install tools outside nixpkgs, export PATH updates, warm caches formatters ? { }, # formatters = treefmt-nix programs attrset, merged over { nixfmt.enable = true; } # e.g. { gofmt.enable = true; shfmt.enable = true; } @@ -144,6 +147,8 @@ UNDERLINE='\033[4m' RESET='\033[0m' + ${preToolHook} + printf "\n$GREEN 🚀 Dev shell ready$RESET\n\n" ${toolBannerScript} printf "\n" diff --git a/template/flake.nix b/template/flake.nix index 4b083c4..1c17b3c 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -66,8 +66,20 @@ # { name = "Bun"; bin = "${pkgs.bun}/bin/bun"; versionCmd = "--version"; color = "YELLOW"; } # { name = "Go"; bin = "${pkgs.go}/bin/go"; versionCmd = "version"; color = "CYAN"; } # { name = "Rust"; bin = "${pkgs.rustc}/bin/rustc"; versionCmd = "--version"; color = "YELLOW"; } + # { name = "golangci-lint"; bin = "golangci-lint"; versionCmd = "version"; color = "YELLOW"; } ]; + preToolHook = '' + # runs before the ready banner + tool version logs + # useful for installing tools outside nixpkgs and updating PATH first + # + # 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 + ''; + extraShellHook = '' # any repo-specific shell setup here '';