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:
|
From your new project folder:
|
||||||
|
|
||||||
```bash
|
```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)
|
## 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:
|
Add this flake input:
|
||||||
|
|
||||||
```nix
|
```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";
|
inputs.devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -33,7 +33,9 @@ Create your shell from `mkDevShell`:
|
|||||||
```nix
|
```nix
|
||||||
env = devshell-lib.lib.mkDevShell {
|
env = devshell-lib.lib.mkDevShell {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
src = ./.;
|
||||||
extraPackages = [ ];
|
extraPackages = [ ];
|
||||||
|
preToolHook = "";
|
||||||
tools = [ ];
|
tools = [ ];
|
||||||
additionalHooks = { };
|
additionalHooks = { };
|
||||||
};
|
};
|
||||||
@@ -45,6 +47,30 @@ Expose it in `devShells` as `default` and run:
|
|||||||
nix develop
|
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
|
## Common commands
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -32,13 +32,17 @@
|
|||||||
mkDevShell =
|
mkDevShell =
|
||||||
{
|
{
|
||||||
system,
|
system,
|
||||||
|
src ? ./.,
|
||||||
extraPackages ? [ ],
|
extraPackages ? [ ],
|
||||||
|
preToolHook ? "",
|
||||||
extraShellHook ? "",
|
extraShellHook ? "",
|
||||||
additionalHooks ? { },
|
additionalHooks ? { },
|
||||||
tools ? [ ],
|
tools ? [ ],
|
||||||
includeStandardPackages ? true,
|
includeStandardPackages ? true,
|
||||||
# tools = list of { name, bin, versionCmd, color? }
|
# tools = list of { name, bin, versionCmd, color? }
|
||||||
# e.g. { name = "Bun"; bin = "${pkgs.bun}/bin/bun"; versionCmd = "--version"; color = "YELLOW"; }
|
# 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 ? { },
|
||||||
# formatters = treefmt-nix programs attrset, merged over { nixfmt.enable = true; }
|
# formatters = treefmt-nix programs attrset, merged over { nixfmt.enable = true; }
|
||||||
# e.g. { gofmt.enable = true; shfmt.enable = true; }
|
# e.g. { gofmt.enable = true; shfmt.enable = true; }
|
||||||
@@ -78,7 +82,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
pre-commit-check = git-hooks.lib.${system}.run {
|
pre-commit-check = git-hooks.lib.${system}.run {
|
||||||
src = ./.;
|
inherit src;
|
||||||
hooks = {
|
hooks = {
|
||||||
treefmt = {
|
treefmt = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -143,6 +147,8 @@
|
|||||||
UNDERLINE='\033[4m'
|
UNDERLINE='\033[4m'
|
||||||
RESET='\033[0m'
|
RESET='\033[0m'
|
||||||
|
|
||||||
|
${preToolHook}
|
||||||
|
|
||||||
printf "\n$GREEN 🚀 Dev shell ready$RESET\n\n"
|
printf "\n$GREEN 🚀 Dev shell ready$RESET\n\n"
|
||||||
${toolBannerScript}
|
${toolBannerScript}
|
||||||
printf "\n"
|
printf "\n"
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
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";
|
devshell-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,8 +66,20 @@
|
|||||||
# { name = "Bun"; bin = "${pkgs.bun}/bin/bun"; versionCmd = "--version"; color = "YELLOW"; }
|
# { name = "Bun"; bin = "${pkgs.bun}/bin/bun"; versionCmd = "--version"; color = "YELLOW"; }
|
||||||
# { name = "Go"; bin = "${pkgs.go}/bin/go"; versionCmd = "version"; color = "CYAN"; }
|
# { name = "Go"; bin = "${pkgs.go}/bin/go"; versionCmd = "version"; color = "CYAN"; }
|
||||||
# { name = "Rust"; bin = "${pkgs.rustc}/bin/rustc"; versionCmd = "--version"; color = "YELLOW"; }
|
# { 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 = ''
|
extraShellHook = ''
|
||||||
# any repo-specific shell setup here
|
# any repo-specific shell setup here
|
||||||
'';
|
'';
|
||||||
@@ -80,7 +92,13 @@
|
|||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
config = mkDevShellConfig pkgs;
|
config = mkDevShellConfig pkgs;
|
||||||
env = devshell-lib.lib.mkDevShell (
|
env = devshell-lib.lib.mkDevShell (
|
||||||
({ inherit system; } // config)
|
(
|
||||||
|
{
|
||||||
|
inherit system;
|
||||||
|
src = ./.;
|
||||||
|
}
|
||||||
|
// config
|
||||||
|
)
|
||||||
// {
|
// {
|
||||||
extraPackages = config.extraPackages ++ [ self.packages.${system}.release ];
|
extraPackages = config.extraPackages ++ [ self.packages.${system}.release ];
|
||||||
}
|
}
|
||||||
@@ -102,7 +120,13 @@
|
|||||||
let
|
let
|
||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
config = mkDevShellConfig pkgs;
|
config = mkDevShellConfig pkgs;
|
||||||
env = devshell-lib.lib.mkDevShell ({ inherit system; } // config);
|
env = devshell-lib.lib.mkDevShell (
|
||||||
|
{
|
||||||
|
inherit system;
|
||||||
|
src = ./.;
|
||||||
|
}
|
||||||
|
// config
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (env) pre-commit-check;
|
inherit (env) pre-commit-check;
|
||||||
@@ -115,7 +139,13 @@
|
|||||||
pkgs = import nixpkgs { inherit system; };
|
pkgs = import nixpkgs { inherit system; };
|
||||||
config = mkDevShellConfig pkgs;
|
config = mkDevShellConfig pkgs;
|
||||||
in
|
in
|
||||||
(devshell-lib.lib.mkDevShell ({ inherit system; } // config)).formatter
|
(devshell-lib.lib.mkDevShell (
|
||||||
|
{
|
||||||
|
inherit system;
|
||||||
|
src = ./.;
|
||||||
|
}
|
||||||
|
// config
|
||||||
|
)).formatter
|
||||||
);
|
);
|
||||||
|
|
||||||
# Release command (`release`)
|
# Release command (`release`)
|
||||||
|
|||||||
Reference in New Issue
Block a user