Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00a9ab240a | ||
|
|
53e498ca45 | ||
|
|
80cc529de7 | ||
|
|
4d2579ae1e |
30
README.md
30
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.0#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.0#
|
||||
Add this flake input:
|
||||
|
||||
```nix
|
||||
inputs.devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.0.0";
|
||||
inputs.devshell-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v2.1.0";
|
||||
inputs.devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||
```
|
||||
|
||||
@@ -33,7 +33,9 @@ Create your shell from `mkDevShell`:
|
||||
```nix
|
||||
env = devshell-lib.lib.mkDevShell {
|
||||
inherit system;
|
||||
src = ./.;
|
||||
extraPackages = [ ];
|
||||
preToolHook = "";
|
||||
tools = [ ];
|
||||
additionalHooks = { };
|
||||
};
|
||||
@@ -45,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
|
||||
|
||||
@@ -32,13 +32,17 @@
|
||||
mkDevShell =
|
||||
{
|
||||
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; }
|
||||
@@ -78,7 +82,7 @@
|
||||
};
|
||||
|
||||
pre-commit-check = git-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
inherit src;
|
||||
hooks = {
|
||||
treefmt = {
|
||||
enable = true;
|
||||
@@ -143,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.0";
|
||||
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
|
||||
'';
|
||||
@@ -80,7 +92,13 @@
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
config = mkDevShellConfig pkgs;
|
||||
env = devshell-lib.lib.mkDevShell (
|
||||
({ inherit system; } // config)
|
||||
(
|
||||
{
|
||||
inherit system;
|
||||
src = ./.;
|
||||
}
|
||||
// config
|
||||
)
|
||||
// {
|
||||
extraPackages = config.extraPackages ++ [ self.packages.${system}.release ];
|
||||
}
|
||||
@@ -102,7 +120,13 @@
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
config = mkDevShellConfig pkgs;
|
||||
env = devshell-lib.lib.mkDevShell ({ inherit system; } // config);
|
||||
env = devshell-lib.lib.mkDevShell (
|
||||
{
|
||||
inherit system;
|
||||
src = ./.;
|
||||
}
|
||||
// config
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit (env) pre-commit-check;
|
||||
@@ -115,7 +139,13 @@
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
config = mkDevShellConfig pkgs;
|
||||
in
|
||||
(devshell-lib.lib.mkDevShell ({ inherit system; } // config)).formatter
|
||||
(devshell-lib.lib.mkDevShell (
|
||||
{
|
||||
inherit system;
|
||||
src = ./.;
|
||||
}
|
||||
// config
|
||||
)).formatter
|
||||
);
|
||||
|
||||
# Release command (`release`)
|
||||
|
||||
Reference in New Issue
Block a user