Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00a9ab240a | ||
|
|
53e498ca45 |
29
README.md
29
README.md
@@ -16,7 +16,7 @@ Simple Nix flake library for:
|
||||
From your new project folder:
|
||||
|
||||
```bash
|
||||
nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1#default' --refresh
|
||||
nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.1.0#default' --refresh
|
||||
```
|
||||
|
||||
## Use the library (existing repo)
|
||||
@@ -24,7 +24,7 @@ nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1#
|
||||
Add this flake input:
|
||||
|
||||
```nix
|
||||
inputs.devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1";
|
||||
inputs.devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.1.0";
|
||||
inputs.devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||
```
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.1";
|
||||
devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.1.0";
|
||||
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
@@ -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
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user