Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8658265ae | ||
|
|
c42899c89e | ||
|
|
00fb6ef297 | ||
|
|
dc475afcd1 |
20
README.md
20
README.md
@@ -15,7 +15,7 @@
|
|||||||
## Use the template
|
## Use the template
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=v3.0.0#default' --refresh
|
nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v3.1.0#default' --refresh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Use the library
|
## Use the library
|
||||||
@@ -23,7 +23,7 @@ nix flake new myapp -t 'git+https://git.dgren.dev/eric/nix-flake-lib?ref=v3.0.0#
|
|||||||
Add this flake input:
|
Add this flake input:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
inputs.repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v3.0.0";
|
inputs.repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v3.1.0";
|
||||||
inputs.repo-lib.inputs.nixpkgs.follows = "nixpkgs";
|
inputs.repo-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -49,10 +49,10 @@ outputs = { self, nixpkgs, repo-lib, ... }:
|
|||||||
|
|
||||||
perSystem = { pkgs, system, ... }: {
|
perSystem = { pkgs, system, ... }: {
|
||||||
tools = [
|
tools = [
|
||||||
(repo-lib.lib.tools.fromPackage {
|
(repo-lib.lib.tools.fromCommand {
|
||||||
name = "Nix";
|
name = "Nix";
|
||||||
package = pkgs.nix;
|
|
||||||
version.args = [ "--version" ];
|
version.args = [ "--version" ];
|
||||||
|
command = "nix";
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ outputs = { self, nixpkgs, repo-lib, ... }:
|
|||||||
|
|
||||||
## Tool banners
|
## Tool banners
|
||||||
|
|
||||||
Tools are declared once, from packages. They are added to the shell automatically and rendered in the startup banner.
|
Tools are declared once. Package-backed tools are added to the shell automatically, and both package-backed and command-backed tools are rendered in the startup banner.
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
(repo-lib.lib.tools.fromPackage {
|
(repo-lib.lib.tools.fromPackage {
|
||||||
@@ -86,6 +86,16 @@ Tools are declared once, from packages. They are added to the shell automaticall
|
|||||||
|
|
||||||
Required tools fail shell startup if their version probe fails. This keeps banner output honest instead of silently hiding misconfiguration.
|
Required tools fail shell startup if their version probe fails. This keeps banner output honest instead of silently hiding misconfiguration.
|
||||||
|
|
||||||
|
When a tool should come from the host environment instead of `nixpkgs`, use `fromCommand`:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
(repo-lib.lib.tools.fromCommand {
|
||||||
|
name = "Nix";
|
||||||
|
command = "nix";
|
||||||
|
version.args = [ "--version" ];
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Purity model
|
## Purity model
|
||||||
|
|
||||||
The default path is pure: declare tools and packages in Nix, then let `mkRepo` assemble the shell.
|
The default path is pure: declare tools and packages in Nix, then let `mkRepo` assemble the shell.
|
||||||
|
|||||||
21
flake.nix
21
flake.nix
@@ -36,21 +36,21 @@
|
|||||||
replace = {
|
replace = {
|
||||||
path = "template/flake.nix";
|
path = "template/flake.nix";
|
||||||
regex = ''^([[:space:]]*repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
regex = ''^([[:space:]]*repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
||||||
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/$FULL_TAG\2'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
replace = {
|
replace = {
|
||||||
path = "README.md";
|
path = "README.md";
|
||||||
regex = ''(nix flake new myapp -t ')git\+https://git\.dgren\.dev/eric/nix-flake-lib[^']*(#default' --refresh)'';
|
regex = ''(nix flake new myapp -t ')git\+https://git\.dgren\.dev/eric/nix-flake-lib[^']*(#default' --refresh)'';
|
||||||
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/$FULL_TAG\2'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
replace = {
|
replace = {
|
||||||
path = "README.md";
|
path = "README.md";
|
||||||
regex = ''^([[:space:]]*inputs\.repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
regex = ''^([[:space:]]*inputs\.repo-lib\.url = ")git\+https://git\.dgren\.dev/eric/nix-flake-lib[^"]*(";)'';
|
||||||
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=$FULL_TAG\2'';
|
replacement = ''\1git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/$FULL_TAG\2'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -64,10 +64,17 @@
|
|||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
tools = [
|
tools = [
|
||||||
(repoLib.tools.fromPackage {
|
(repoLib.tools.fromCommand {
|
||||||
name = "Nix";
|
name = "Nix";
|
||||||
package = pkgs.nix;
|
command = "nix";
|
||||||
version.args = [ "--version" ];
|
version = {
|
||||||
|
args = [ "--version" ];
|
||||||
|
group = 1;
|
||||||
|
};
|
||||||
|
banner = {
|
||||||
|
color = "BLUE";
|
||||||
|
icon = "";
|
||||||
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -90,7 +97,6 @@
|
|||||||
gnused
|
gnused
|
||||||
coreutils
|
coreutils
|
||||||
gnugrep
|
gnugrep
|
||||||
nix
|
|
||||||
perl
|
perl
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -98,7 +104,6 @@
|
|||||||
export REPO_LIB_ROOT=${./.}
|
export REPO_LIB_ROOT=${./.}
|
||||||
export NIXPKGS_FLAKE_PATH=${nixpkgs}
|
export NIXPKGS_FLAKE_PATH=${nixpkgs}
|
||||||
export HOME="$TMPDIR"
|
export HOME="$TMPDIR"
|
||||||
export NIX_CONFIG="experimental-features = nix-command flakes"
|
|
||||||
${pkgs.bash}/bin/bash ${./tests/release.sh}
|
${pkgs.bash}/bin/bash ${./tests/release.sh}
|
||||||
touch "$out"
|
touch "$out"
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ ROOT_DIR="$(git rev-parse --show-toplevel)"
|
|||||||
GITLINT_FILE="$ROOT_DIR/.gitlint"
|
GITLINT_FILE="$ROOT_DIR/.gitlint"
|
||||||
START_HEAD=""
|
START_HEAD=""
|
||||||
CREATED_TAG=""
|
CREATED_TAG=""
|
||||||
|
VERSION_META_LINES=()
|
||||||
|
VERSION_META_EXPORT_NAMES=()
|
||||||
|
|
||||||
# ── logging ────────────────────────────────────────────────────────────────
|
# ── logging ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -168,6 +170,119 @@ compute_full_version() {
|
|||||||
export BASE_VERSION CHANNEL PRERELEASE_NUM FULL_VERSION FULL_TAG
|
export BASE_VERSION CHANNEL PRERELEASE_NUM FULL_VERSION FULL_TAG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
meta_env_name() {
|
||||||
|
local key="$1"
|
||||||
|
key="${key//[^[:alnum:]]/_}"
|
||||||
|
key="$(printf '%s' "$key" | tr '[:lower:]' '[:upper:]')"
|
||||||
|
printf 'VERSION_META_%s\n' "$key"
|
||||||
|
}
|
||||||
|
|
||||||
|
clear_version_meta_exports() {
|
||||||
|
local export_name
|
||||||
|
for export_name in "${VERSION_META_EXPORT_NAMES[@]:-}"; do
|
||||||
|
unset "$export_name"
|
||||||
|
done
|
||||||
|
VERSION_META_EXPORT_NAMES=()
|
||||||
|
}
|
||||||
|
|
||||||
|
load_version_metadata() {
|
||||||
|
VERSION_META_LINES=()
|
||||||
|
[[ ! -f "$ROOT_DIR/VERSION" ]] && return 0
|
||||||
|
|
||||||
|
while IFS= read -r line || [[ -n $line ]]; do
|
||||||
|
VERSION_META_LINES+=("$line")
|
||||||
|
done < <(tail -n +4 "$ROOT_DIR/VERSION" 2>/dev/null || true)
|
||||||
|
}
|
||||||
|
|
||||||
|
export_version_metadata() {
|
||||||
|
clear_version_meta_exports
|
||||||
|
|
||||||
|
local line key value export_name
|
||||||
|
for line in "${VERSION_META_LINES[@]:-}"; do
|
||||||
|
[[ $line != *=* ]] && continue
|
||||||
|
key="${line%%=*}"
|
||||||
|
value="${line#*=}"
|
||||||
|
[[ -z $key ]] && continue
|
||||||
|
export_name="$(meta_env_name "$key")"
|
||||||
|
printf -v "$export_name" '%s' "$value"
|
||||||
|
export "${export_name?}=$value"
|
||||||
|
VERSION_META_EXPORT_NAMES+=("$export_name")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
write_version_file() {
|
||||||
|
local channel_to_write="$1"
|
||||||
|
local n_to_write="$2"
|
||||||
|
{
|
||||||
|
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write"
|
||||||
|
local line
|
||||||
|
for line in "${VERSION_META_LINES[@]:-}"; do
|
||||||
|
printf '%s\n' "$line"
|
||||||
|
done
|
||||||
|
} >"$ROOT_DIR/VERSION"
|
||||||
|
}
|
||||||
|
|
||||||
|
version_meta_get() {
|
||||||
|
local key="${1-}"
|
||||||
|
local line
|
||||||
|
for line in "${VERSION_META_LINES[@]:-}"; do
|
||||||
|
if [[ $line == "$key="* ]]; then
|
||||||
|
printf '%s\n' "${line#*=}"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
version_meta_set() {
|
||||||
|
local key="${1-}"
|
||||||
|
local value="${2-}"
|
||||||
|
[[ -z $key ]] && echo "Error: version_meta_set requires a key" >&2 && exit 1
|
||||||
|
|
||||||
|
local updated=0
|
||||||
|
local index
|
||||||
|
for index in "${!VERSION_META_LINES[@]}"; do
|
||||||
|
if [[ ${VERSION_META_LINES[index]} == "$key="* ]]; then
|
||||||
|
VERSION_META_LINES[index]="$key=$value"
|
||||||
|
updated=1
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ $updated -eq 0 ]]; then
|
||||||
|
VERSION_META_LINES+=("$key=$value")
|
||||||
|
fi
|
||||||
|
|
||||||
|
export_version_metadata
|
||||||
|
version_meta_write
|
||||||
|
}
|
||||||
|
|
||||||
|
version_meta_unset() {
|
||||||
|
local key="${1-}"
|
||||||
|
[[ -z $key ]] && echo "Error: version_meta_unset requires a key" >&2 && exit 1
|
||||||
|
|
||||||
|
local filtered=()
|
||||||
|
local line
|
||||||
|
for line in "${VERSION_META_LINES[@]:-}"; do
|
||||||
|
[[ $line == "$key="* ]] && continue
|
||||||
|
filtered+=("$line")
|
||||||
|
done
|
||||||
|
VERSION_META_LINES=("${filtered[@]}")
|
||||||
|
|
||||||
|
export_version_metadata
|
||||||
|
version_meta_write
|
||||||
|
}
|
||||||
|
|
||||||
|
version_meta_write() {
|
||||||
|
local channel_to_write="$CHANNEL"
|
||||||
|
local n_to_write="${PRERELEASE_NUM:-1}"
|
||||||
|
if [[ $channel_to_write == "stable" || -z $channel_to_write ]]; then
|
||||||
|
channel_to_write="stable"
|
||||||
|
n_to_write="0"
|
||||||
|
fi
|
||||||
|
write_version_file "$channel_to_write" "$n_to_write"
|
||||||
|
}
|
||||||
|
|
||||||
# ── gitlint ────────────────────────────────────────────────────────────────
|
# ── gitlint ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
get_gitlint_title_regex() {
|
get_gitlint_title_regex() {
|
||||||
@@ -205,6 +320,8 @@ run_release_steps() {
|
|||||||
# and never contaminates the stdout of do_read_version.
|
# and never contaminates the stdout of do_read_version.
|
||||||
init_version_file() {
|
init_version_file() {
|
||||||
if [[ -f "$ROOT_DIR/VERSION" ]]; then
|
if [[ -f "$ROOT_DIR/VERSION" ]]; then
|
||||||
|
load_version_metadata
|
||||||
|
export_version_metadata
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -233,11 +350,16 @@ init_version_file() {
|
|||||||
n_to_write="0"
|
n_to_write="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write" >"$ROOT_DIR/VERSION"
|
VERSION_META_LINES=()
|
||||||
|
write_version_file "$channel_to_write" "$n_to_write"
|
||||||
|
export_version_metadata
|
||||||
log "Initialized $ROOT_DIR/VERSION from highest tag: v$highest_tag"
|
log "Initialized $ROOT_DIR/VERSION from highest tag: v$highest_tag"
|
||||||
}
|
}
|
||||||
|
|
||||||
do_read_version() {
|
do_read_version() {
|
||||||
|
load_version_metadata
|
||||||
|
export_version_metadata
|
||||||
|
|
||||||
local base_line channel_line n_line
|
local base_line channel_line n_line
|
||||||
base_line="$(sed -n '1p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
base_line="$(sed -n '1p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
||||||
channel_line="$(sed -n '2p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
channel_line="$(sed -n '2p' "$ROOT_DIR/VERSION" | tr -d '\r')"
|
||||||
@@ -257,7 +379,8 @@ do_write_version() {
|
|||||||
channel_to_write="stable"
|
channel_to_write="stable"
|
||||||
n_to_write="0"
|
n_to_write="0"
|
||||||
fi
|
fi
|
||||||
printf '%s\n%s\n%s\n' "$BASE_VERSION" "$channel_to_write" "$n_to_write" >"$ROOT_DIR/VERSION"
|
write_version_file "$channel_to_write" "$n_to_write"
|
||||||
|
export_version_metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── user-provided hook ─────────────────────────────────────────────────────
|
# ── user-provided hook ─────────────────────────────────────────────────────
|
||||||
|
|||||||
@@ -44,11 +44,37 @@ let
|
|||||||
|
|
||||||
sanitizeName = name: lib.strings.sanitizeDerivationName name;
|
sanitizeName = name: lib.strings.sanitizeDerivationName name;
|
||||||
|
|
||||||
|
defaultShellBanner = {
|
||||||
|
style = "simple";
|
||||||
|
icon = "🚀";
|
||||||
|
title = "Dev shell ready";
|
||||||
|
titleColor = "GREEN";
|
||||||
|
subtitle = "";
|
||||||
|
subtitleColor = "GRAY";
|
||||||
|
borderColor = "BLUE";
|
||||||
|
};
|
||||||
|
|
||||||
|
normalizeShellBanner =
|
||||||
|
rawBanner:
|
||||||
|
let
|
||||||
|
banner = defaultShellBanner // rawBanner;
|
||||||
|
in
|
||||||
|
if
|
||||||
|
!(builtins.elem banner.style [
|
||||||
|
"simple"
|
||||||
|
"pretty"
|
||||||
|
])
|
||||||
|
then
|
||||||
|
throw "repo-lib: config.shell.banner.style must be one of simple or pretty"
|
||||||
|
else
|
||||||
|
banner;
|
||||||
|
|
||||||
normalizeStrictTool =
|
normalizeStrictTool =
|
||||||
pkgs: tool:
|
pkgs: tool:
|
||||||
let
|
let
|
||||||
version = {
|
version = {
|
||||||
args = [ "--version" ];
|
args = [ "--version" ];
|
||||||
|
match = null;
|
||||||
regex = null;
|
regex = null;
|
||||||
group = 0;
|
group = 0;
|
||||||
line = 1;
|
line = 1;
|
||||||
@@ -56,22 +82,26 @@ let
|
|||||||
// (tool.version or { });
|
// (tool.version or { });
|
||||||
banner = {
|
banner = {
|
||||||
color = "YELLOW";
|
color = "YELLOW";
|
||||||
|
icon = null;
|
||||||
|
iconColor = null;
|
||||||
}
|
}
|
||||||
// (tool.banner or { });
|
// (tool.banner or { });
|
||||||
executable =
|
executable =
|
||||||
if tool ? exe && tool.exe != null then
|
if tool ? command && tool.command != null then
|
||||||
|
tool.command
|
||||||
|
else if tool ? exe && tool.exe != null then
|
||||||
"${lib.getExe' tool.package tool.exe}"
|
"${lib.getExe' tool.package tool.exe}"
|
||||||
else
|
else
|
||||||
"${lib.getExe tool.package}";
|
"${lib.getExe tool.package}";
|
||||||
in
|
in
|
||||||
if !(tool ? package) then
|
if !(tool ? command && tool.command != null) && !(tool ? package) then
|
||||||
throw "repo-lib: tool '${tool.name or "<unnamed>"}' is missing 'package'"
|
throw "repo-lib: tool '${tool.name or "<unnamed>"}' is missing 'package' or 'command'"
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
kind = "strict";
|
kind = "strict";
|
||||||
inherit executable version banner;
|
inherit executable version banner;
|
||||||
name = tool.name;
|
name = tool.name;
|
||||||
package = tool.package;
|
package = tool.package or null;
|
||||||
required = tool.required or true;
|
required = tool.required or true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -87,6 +117,8 @@ let
|
|||||||
versionCommand = tool.versionCmd or "--version";
|
versionCommand = tool.versionCmd or "--version";
|
||||||
banner = {
|
banner = {
|
||||||
color = tool.color or "YELLOW";
|
color = tool.color or "YELLOW";
|
||||||
|
icon = tool.icon or null;
|
||||||
|
iconColor = tool.iconColor or null;
|
||||||
};
|
};
|
||||||
required = tool.required or false;
|
required = tool.required or false;
|
||||||
};
|
};
|
||||||
@@ -248,7 +280,7 @@ let
|
|||||||
preCommitShellHook,
|
preCommitShellHook,
|
||||||
shellEnvScript,
|
shellEnvScript,
|
||||||
bootstrap,
|
bootstrap,
|
||||||
toolBannerScript,
|
shellBannerScript,
|
||||||
extraShellText,
|
extraShellText,
|
||||||
toolLabelWidth,
|
toolLabelWidth,
|
||||||
}:
|
}:
|
||||||
@@ -261,7 +293,7 @@ let
|
|||||||
"@TOOL_LABEL_WIDTH@"
|
"@TOOL_LABEL_WIDTH@"
|
||||||
"@SHELL_ENV_SCRIPT@"
|
"@SHELL_ENV_SCRIPT@"
|
||||||
"@BOOTSTRAP@"
|
"@BOOTSTRAP@"
|
||||||
"@TOOL_BANNER_SCRIPT@"
|
"@SHELL_BANNER_SCRIPT@"
|
||||||
"@EXTRA_SHELL_TEXT@"
|
"@EXTRA_SHELL_TEXT@"
|
||||||
]
|
]
|
||||||
[
|
[
|
||||||
@@ -269,7 +301,7 @@ let
|
|||||||
(toString toolLabelWidth)
|
(toString toolLabelWidth)
|
||||||
shellEnvScript
|
shellEnvScript
|
||||||
bootstrap
|
bootstrap
|
||||||
toolBannerScript
|
shellBannerScript
|
||||||
extraShellText
|
extraShellText
|
||||||
]
|
]
|
||||||
template;
|
template;
|
||||||
@@ -286,6 +318,7 @@ let
|
|||||||
env = { };
|
env = { };
|
||||||
extraShellText = "";
|
extraShellText = "";
|
||||||
bootstrap = "";
|
bootstrap = "";
|
||||||
|
banner = defaultShellBanner;
|
||||||
},
|
},
|
||||||
checkSpecs ? { },
|
checkSpecs ? { },
|
||||||
rawHookEntries ? { },
|
rawHookEntries ? { },
|
||||||
@@ -345,30 +378,95 @@ let
|
|||||||
) shellConfig.env
|
) shellConfig.env
|
||||||
);
|
);
|
||||||
|
|
||||||
toolBannerScript = lib.concatMapStrings (
|
banner = normalizeShellBanner (shellConfig.banner or { });
|
||||||
tool:
|
|
||||||
if tool.kind == "strict" then
|
shellBannerScript =
|
||||||
|
if banner.style == "pretty" then
|
||||||
''
|
''
|
||||||
repo_lib_probe_tool \
|
repo_lib_print_pretty_header \
|
||||||
${lib.escapeShellArg tool.name} \
|
${lib.escapeShellArg banner.borderColor} \
|
||||||
${lib.escapeShellArg tool.banner.color} \
|
${lib.escapeShellArg banner.titleColor} \
|
||||||
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
${lib.escapeShellArg banner.icon} \
|
||||||
${lib.escapeShellArg (toString tool.version.line)} \
|
${lib.escapeShellArg banner.title} \
|
||||||
${lib.escapeShellArg (toString tool.version.group)} \
|
${lib.escapeShellArg banner.subtitleColor} \
|
||||||
${lib.escapeShellArg (tool.version.regex or "")} \
|
${lib.escapeShellArg banner.subtitle}
|
||||||
${lib.escapeShellArg tool.executable} \
|
''
|
||||||
${lib.escapeShellArgs tool.version.args}
|
+ lib.concatMapStrings (
|
||||||
|
tool:
|
||||||
|
if tool.kind == "strict" then
|
||||||
|
''
|
||||||
|
repo_lib_print_pretty_tool \
|
||||||
|
${lib.escapeShellArg banner.borderColor} \
|
||||||
|
${lib.escapeShellArg tool.name} \
|
||||||
|
${lib.escapeShellArg tool.banner.color} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.icon == null then "" else tool.banner.icon)} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.iconColor == null then "" else tool.banner.iconColor)} \
|
||||||
|
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
||||||
|
${lib.escapeShellArg (toString tool.version.line)} \
|
||||||
|
${lib.escapeShellArg (toString tool.version.group)} \
|
||||||
|
${lib.escapeShellArg (if tool.version.regex == null then "" else tool.version.regex)} \
|
||||||
|
${lib.escapeShellArg (if tool.version.match == null then "" else tool.version.match)} \
|
||||||
|
${lib.escapeShellArg tool.executable} \
|
||||||
|
${lib.escapeShellArgs tool.version.args}
|
||||||
|
''
|
||||||
|
else
|
||||||
|
''
|
||||||
|
repo_lib_print_pretty_legacy_tool \
|
||||||
|
${lib.escapeShellArg banner.borderColor} \
|
||||||
|
${lib.escapeShellArg tool.name} \
|
||||||
|
${lib.escapeShellArg tool.banner.color} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.icon == null then "" else tool.banner.icon)} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.iconColor == null then "" else tool.banner.iconColor)} \
|
||||||
|
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
||||||
|
${lib.escapeShellArg tool.command} \
|
||||||
|
${lib.escapeShellArg tool.versionCommand}
|
||||||
|
''
|
||||||
|
) tools
|
||||||
|
+ ''
|
||||||
|
repo_lib_print_pretty_footer \
|
||||||
|
${lib.escapeShellArg banner.borderColor}
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
''
|
''
|
||||||
repo_lib_probe_legacy_tool \
|
repo_lib_print_simple_header \
|
||||||
${lib.escapeShellArg tool.name} \
|
${lib.escapeShellArg banner.titleColor} \
|
||||||
${lib.escapeShellArg tool.banner.color} \
|
${lib.escapeShellArg banner.icon} \
|
||||||
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
${lib.escapeShellArg banner.title} \
|
||||||
${lib.escapeShellArg tool.command} \
|
${lib.escapeShellArg banner.subtitleColor} \
|
||||||
${lib.escapeShellArg tool.versionCommand}
|
${lib.escapeShellArg banner.subtitle}
|
||||||
''
|
''
|
||||||
) tools;
|
+ lib.concatMapStrings (
|
||||||
|
tool:
|
||||||
|
if tool.kind == "strict" then
|
||||||
|
''
|
||||||
|
repo_lib_print_simple_tool \
|
||||||
|
${lib.escapeShellArg tool.name} \
|
||||||
|
${lib.escapeShellArg tool.banner.color} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.icon == null then "" else tool.banner.icon)} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.iconColor == null then "" else tool.banner.iconColor)} \
|
||||||
|
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
||||||
|
${lib.escapeShellArg (toString tool.version.line)} \
|
||||||
|
${lib.escapeShellArg (toString tool.version.group)} \
|
||||||
|
${lib.escapeShellArg (if tool.version.regex == null then "" else tool.version.regex)} \
|
||||||
|
${lib.escapeShellArg (if tool.version.match == null then "" else tool.version.match)} \
|
||||||
|
${lib.escapeShellArg tool.executable} \
|
||||||
|
${lib.escapeShellArgs tool.version.args}
|
||||||
|
''
|
||||||
|
else
|
||||||
|
''
|
||||||
|
repo_lib_print_simple_legacy_tool \
|
||||||
|
${lib.escapeShellArg tool.name} \
|
||||||
|
${lib.escapeShellArg tool.banner.color} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.icon == null then "" else tool.banner.icon)} \
|
||||||
|
${lib.escapeShellArg (if tool.banner.iconColor == null then "" else tool.banner.iconColor)} \
|
||||||
|
${lib.escapeShellArg (if tool.required then "1" else "0")} \
|
||||||
|
${lib.escapeShellArg tool.command} \
|
||||||
|
${lib.escapeShellArg tool.versionCommand}
|
||||||
|
''
|
||||||
|
) tools
|
||||||
|
+ ''
|
||||||
|
printf "\n"
|
||||||
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit pre-commit-check;
|
inherit pre-commit-check;
|
||||||
@@ -378,7 +476,7 @@ let
|
|||||||
buildInputs = pre-commit-check.enabledPackages;
|
buildInputs = pre-commit-check.enabledPackages;
|
||||||
shellHook = buildShellHook {
|
shellHook = buildShellHook {
|
||||||
preCommitShellHook = pre-commit-check.shellHook;
|
preCommitShellHook = pre-commit-check.shellHook;
|
||||||
inherit toolLabelWidth shellEnvScript toolBannerScript;
|
inherit toolLabelWidth shellEnvScript shellBannerScript;
|
||||||
bootstrap = shellConfig.bootstrap;
|
bootstrap = shellConfig.bootstrap;
|
||||||
extraShellText = shellConfig.extraShellText;
|
extraShellText = shellConfig.extraShellText;
|
||||||
};
|
};
|
||||||
@@ -411,6 +509,24 @@ rec {
|
|||||||
;
|
;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fromCommand =
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
command,
|
||||||
|
version ? { },
|
||||||
|
banner ? { },
|
||||||
|
required ? true,
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
inherit
|
||||||
|
name
|
||||||
|
command
|
||||||
|
version
|
||||||
|
banner
|
||||||
|
required
|
||||||
|
;
|
||||||
|
};
|
||||||
|
|
||||||
simple =
|
simple =
|
||||||
name: package: args:
|
name: package: args:
|
||||||
fromPackage {
|
fromPackage {
|
||||||
@@ -429,6 +545,7 @@ rec {
|
|||||||
extraShellText = "";
|
extraShellText = "";
|
||||||
allowImpureBootstrap = false;
|
allowImpureBootstrap = false;
|
||||||
bootstrap = "";
|
bootstrap = "";
|
||||||
|
banner = { };
|
||||||
};
|
};
|
||||||
formatting = {
|
formatting = {
|
||||||
programs = { };
|
programs = { };
|
||||||
@@ -452,7 +569,13 @@ rec {
|
|||||||
if merged.shell.bootstrap != "" && !merged.shell.allowImpureBootstrap then
|
if merged.shell.bootstrap != "" && !merged.shell.allowImpureBootstrap then
|
||||||
throw "repo-lib: config.shell.bootstrap requires config.shell.allowImpureBootstrap = true"
|
throw "repo-lib: config.shell.bootstrap requires config.shell.allowImpureBootstrap = true"
|
||||||
else
|
else
|
||||||
merged // { inherit release; };
|
merged
|
||||||
|
// {
|
||||||
|
inherit release;
|
||||||
|
shell = merged.shell // {
|
||||||
|
banner = normalizeShellBanner merged.shell.banner;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
mkDevShell =
|
mkDevShell =
|
||||||
{
|
{
|
||||||
@@ -487,6 +610,7 @@ rec {
|
|||||||
extraShellText = extraShellHook;
|
extraShellText = extraShellHook;
|
||||||
allowImpureBootstrap = true;
|
allowImpureBootstrap = true;
|
||||||
bootstrap = preToolHook;
|
bootstrap = preToolHook;
|
||||||
|
banner = defaultShellBanner;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
if duplicateToolNames != [ ] then
|
if duplicateToolNames != [ ] then
|
||||||
|
|||||||
@@ -16,107 +16,326 @@ BOLD=$'\033[1m'
|
|||||||
UNDERLINE=$'\033[4m'
|
UNDERLINE=$'\033[4m'
|
||||||
RESET=$'\033[0m'
|
RESET=$'\033[0m'
|
||||||
|
|
||||||
repo_lib_probe_tool() {
|
REPO_LIB_TOOL_VERSION=""
|
||||||
local name="$1"
|
REPO_LIB_TOOL_ERROR=""
|
||||||
local color_name="$2"
|
|
||||||
local required="$3"
|
repo_lib_capture_tool() {
|
||||||
local line_no="$4"
|
local required="$1"
|
||||||
local group_no="$5"
|
local line_no="$2"
|
||||||
local regex="$6"
|
local group_no="$3"
|
||||||
local executable="$7"
|
local regex="$4"
|
||||||
shift 7
|
local match_regex="$5"
|
||||||
|
local executable="$6"
|
||||||
|
shift 6
|
||||||
|
|
||||||
local color="${!color_name:-$YELLOW}"
|
|
||||||
local output=""
|
local output=""
|
||||||
local selected=""
|
local selected=""
|
||||||
local version=""
|
local version=""
|
||||||
|
|
||||||
|
REPO_LIB_TOOL_VERSION=""
|
||||||
|
REPO_LIB_TOOL_ERROR=""
|
||||||
|
|
||||||
if ! output="$("$executable" "$@" 2>&1)"; then
|
if ! output="$("$executable" "$@" 2>&1)"; then
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "probe failed"
|
REPO_LIB_TOOL_ERROR="probe failed"
|
||||||
printf "%s\n" "$output" >&2
|
printf "%s\n" "$output" >&2
|
||||||
if [ "$required" = "1" ]; then
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
selected="$(printf '%s\n' "$output" | sed -n "${line_no}p")"
|
if [ -n "$match_regex" ]; then
|
||||||
|
selected="$(printf '%s\n' "$output" | grep -E -m 1 "$match_regex" || true)"
|
||||||
|
else
|
||||||
|
selected="$(printf '%s\n' "$output" | sed -n "${line_no}p")"
|
||||||
|
fi
|
||||||
selected="$(printf '%s' "$selected" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
selected="$(printf '%s' "$selected" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
||||||
|
|
||||||
if [ -n "$regex" ]; then
|
if [ -n "$regex" ]; then
|
||||||
if [[ "$selected" =~ $regex ]]; then
|
if [[ "$selected" =~ $regex ]]; then
|
||||||
version="${BASH_REMATCH[$group_no]}"
|
version="${BASH_REMATCH[$group_no]}"
|
||||||
else
|
else
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "version parse failed"
|
REPO_LIB_TOOL_ERROR="version parse failed"
|
||||||
printf "%s\n" "$output" >&2
|
printf "%s\n" "$output" >&2
|
||||||
if [ "$required" = "1" ]; then
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
version="$selected"
|
version="$selected"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$version" ]; then
|
if [ -z "$version" ]; then
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "empty version"
|
REPO_LIB_TOOL_ERROR="empty version"
|
||||||
printf "%s\n" "$output" >&2
|
printf "%s\n" "$output" >&2
|
||||||
if [ "$required" = "1" ]; then
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET %s%s$RESET\n" "${name}:" "$color" "$version"
|
REPO_LIB_TOOL_VERSION="$version"
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
repo_lib_probe_legacy_tool() {
|
repo_lib_capture_legacy_tool() {
|
||||||
local name="$1"
|
local required="$1"
|
||||||
local color_name="$2"
|
local command_name="$2"
|
||||||
local required="$3"
|
local version_command="$3"
|
||||||
local command_name="$4"
|
|
||||||
local version_command="$5"
|
|
||||||
|
|
||||||
local color="${!color_name:-$YELLOW}"
|
|
||||||
local output=""
|
local output=""
|
||||||
local version=""
|
local version=""
|
||||||
|
|
||||||
|
REPO_LIB_TOOL_VERSION=""
|
||||||
|
REPO_LIB_TOOL_ERROR=""
|
||||||
|
|
||||||
if ! command -v "$command_name" >/dev/null 2>&1; then
|
if ! command -v "$command_name" >/dev/null 2>&1; then
|
||||||
if [ "$required" = "1" ]; then
|
REPO_LIB_TOOL_ERROR="missing command"
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "missing command"
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! output="$(sh -c "$command_name $version_command" 2>&1)"; then
|
if ! output="$(sh -c "$command_name $version_command" 2>&1)"; then
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "probe failed"
|
REPO_LIB_TOOL_ERROR="probe failed"
|
||||||
printf "%s\n" "$output" >&2
|
printf "%s\n" "$output" >&2
|
||||||
if [ "$required" = "1" ]; then
|
return 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
version="$(printf '%s\n' "$output" | head -n 1 | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
version="$(printf '%s\n' "$output" | head -n 1 | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')"
|
||||||
if [ -z "$version" ]; then
|
if [ -z "$version" ]; then
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "empty version"
|
REPO_LIB_TOOL_ERROR="empty version"
|
||||||
printf "%s\n" "$output" >&2
|
printf "%s\n" "$output" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
REPO_LIB_TOOL_VERSION="$version"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_simple_header() {
|
||||||
|
local title_color_name="$1"
|
||||||
|
local icon="$2"
|
||||||
|
local title="$3"
|
||||||
|
local subtitle_color_name="$4"
|
||||||
|
local subtitle="$5"
|
||||||
|
|
||||||
|
local title_color="${!title_color_name:-$GREEN}"
|
||||||
|
local subtitle_color="${!subtitle_color_name:-$GRAY}"
|
||||||
|
|
||||||
|
printf "\n%s" "$title_color"
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s " "$icon"
|
||||||
|
fi
|
||||||
|
printf "%s%s" "$title" "$RESET"
|
||||||
|
if [ -n "$subtitle" ]; then
|
||||||
|
printf " %s%s%s" "$subtitle_color" "$subtitle" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "\n\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_simple_tool() {
|
||||||
|
local name="$1"
|
||||||
|
local color_name="$2"
|
||||||
|
local icon="$3"
|
||||||
|
local icon_color_name="$4"
|
||||||
|
local required="$5"
|
||||||
|
local line_no="$6"
|
||||||
|
local group_no="$7"
|
||||||
|
local regex="$8"
|
||||||
|
local match_regex="$9"
|
||||||
|
local executable="${10}"
|
||||||
|
shift 10
|
||||||
|
|
||||||
|
local color="${!color_name:-$YELLOW}"
|
||||||
|
local effective_icon_color_name="$icon_color_name"
|
||||||
|
local icon_color=""
|
||||||
|
|
||||||
|
if [ -z "$effective_icon_color_name" ]; then
|
||||||
|
effective_icon_color_name="$color_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if repo_lib_capture_tool "$required" "$line_no" "$group_no" "$regex" "$match_regex" "$executable" "$@"; then
|
||||||
|
icon_color="${!effective_icon_color_name:-$color}"
|
||||||
|
printf " "
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s%s%s " "$icon_color" "$icon" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "$CYAN %-@TOOL_LABEL_WIDTH@s$RESET %s%s$RESET\n" "${name}:" "$color" "$REPO_LIB_TOOL_VERSION"
|
||||||
|
else
|
||||||
|
printf " "
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s%s%s " "$RED" "$icon" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "$CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "$REPO_LIB_TOOL_ERROR"
|
||||||
if [ "$required" = "1" ]; then
|
if [ "$required" = "1" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
return 0
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_simple_legacy_tool() {
|
||||||
|
local name="$1"
|
||||||
|
local color_name="$2"
|
||||||
|
local icon="$3"
|
||||||
|
local icon_color_name="$4"
|
||||||
|
local required="$5"
|
||||||
|
local command_name="$6"
|
||||||
|
local version_command="$7"
|
||||||
|
|
||||||
|
local color="${!color_name:-$YELLOW}"
|
||||||
|
local effective_icon_color_name="$icon_color_name"
|
||||||
|
local icon_color=""
|
||||||
|
|
||||||
|
if [ -z "$effective_icon_color_name" ]; then
|
||||||
|
effective_icon_color_name="$color_name"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf " $CYAN %-@TOOL_LABEL_WIDTH@s$RESET %s%s$RESET\n" "${name}:" "$color" "$version"
|
if repo_lib_capture_legacy_tool "$required" "$command_name" "$version_command"; then
|
||||||
|
icon_color="${!effective_icon_color_name:-$color}"
|
||||||
|
printf " "
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s%s%s " "$icon_color" "$icon" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "$CYAN %-@TOOL_LABEL_WIDTH@s$RESET %s%s$RESET\n" "${name}:" "$color" "$REPO_LIB_TOOL_VERSION"
|
||||||
|
else
|
||||||
|
printf " "
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s%s%s " "$RED" "$icon" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "$CYAN %-@TOOL_LABEL_WIDTH@s$RESET $RED%s$RESET\n" "${name}:" "$REPO_LIB_TOOL_ERROR"
|
||||||
|
if [ "$required" = "1" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_pretty_header() {
|
||||||
|
local border_color_name="$1"
|
||||||
|
local title_color_name="$2"
|
||||||
|
local icon="$3"
|
||||||
|
local title="$4"
|
||||||
|
local subtitle_color_name="$5"
|
||||||
|
local subtitle="$6"
|
||||||
|
|
||||||
|
local border_color="${!border_color_name:-$BLUE}"
|
||||||
|
local title_color="${!title_color_name:-$GREEN}"
|
||||||
|
local subtitle_color="${!subtitle_color_name:-$GRAY}"
|
||||||
|
|
||||||
|
printf "\n%s╭─%s %s" "$border_color" "$RESET" "$title_color"
|
||||||
|
if [ -n "$icon" ]; then
|
||||||
|
printf "%s " "$icon"
|
||||||
|
fi
|
||||||
|
printf "%s%s" "$title" "$RESET"
|
||||||
|
if [ -n "$subtitle" ]; then
|
||||||
|
printf " %s%s%s" "$subtitle_color" "$subtitle" "$RESET"
|
||||||
|
fi
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_pretty_row() {
|
||||||
|
local border_color_name="$1"
|
||||||
|
local icon="$2"
|
||||||
|
local icon_color_name="$3"
|
||||||
|
local label="$4"
|
||||||
|
local value="$5"
|
||||||
|
local value_color_name="$6"
|
||||||
|
|
||||||
|
local border_color="${!border_color_name:-$BLUE}"
|
||||||
|
local icon_color="${!icon_color_name:-$WHITE}"
|
||||||
|
local value_color="${!value_color_name:-$YELLOW}"
|
||||||
|
|
||||||
|
if [ -z "$icon" ]; then
|
||||||
|
icon="•"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s│%s %s%s%s ${WHITE}%-@TOOL_LABEL_WIDTH@s${RESET} %s%s${RESET}\n" \
|
||||||
|
"$border_color" "$RESET" "$icon_color" "$icon" "$RESET" "$label" "$value_color" "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_pretty_tool() {
|
||||||
|
local border_color_name="$1"
|
||||||
|
local name="$2"
|
||||||
|
local color_name="$3"
|
||||||
|
local icon="$4"
|
||||||
|
local icon_color_name="$5"
|
||||||
|
local required="$6"
|
||||||
|
local line_no="$7"
|
||||||
|
local group_no="$8"
|
||||||
|
local regex="$9"
|
||||||
|
local match_regex="${10}"
|
||||||
|
local executable="${11}"
|
||||||
|
shift 11
|
||||||
|
|
||||||
|
local effective_icon_color_name="$icon_color_name"
|
||||||
|
local value_color_name="$color_name"
|
||||||
|
local value=""
|
||||||
|
|
||||||
|
if [ -z "$effective_icon_color_name" ]; then
|
||||||
|
effective_icon_color_name="$color_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if repo_lib_capture_tool "$required" "$line_no" "$group_no" "$regex" "$match_regex" "$executable" "$@"; then
|
||||||
|
value="$REPO_LIB_TOOL_VERSION"
|
||||||
|
else
|
||||||
|
value="$REPO_LIB_TOOL_ERROR"
|
||||||
|
effective_icon_color_name="RED"
|
||||||
|
value_color_name="RED"
|
||||||
|
fi
|
||||||
|
|
||||||
|
repo_lib_print_pretty_row \
|
||||||
|
"$border_color_name" \
|
||||||
|
"$icon" \
|
||||||
|
"$effective_icon_color_name" \
|
||||||
|
"$name" \
|
||||||
|
"$value" \
|
||||||
|
"$value_color_name"
|
||||||
|
|
||||||
|
if [ "$value_color_name" = "RED" ] && [ "$required" = "1" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_pretty_legacy_tool() {
|
||||||
|
local border_color_name="$1"
|
||||||
|
local name="$2"
|
||||||
|
local color_name="$3"
|
||||||
|
local icon="$4"
|
||||||
|
local icon_color_name="$5"
|
||||||
|
local required="$6"
|
||||||
|
local command_name="$7"
|
||||||
|
local version_command="$8"
|
||||||
|
|
||||||
|
local effective_icon_color_name="$icon_color_name"
|
||||||
|
local value_color_name="$color_name"
|
||||||
|
local value=""
|
||||||
|
|
||||||
|
if [ -z "$effective_icon_color_name" ]; then
|
||||||
|
effective_icon_color_name="$color_name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if repo_lib_capture_legacy_tool "$required" "$command_name" "$version_command"; then
|
||||||
|
value="$REPO_LIB_TOOL_VERSION"
|
||||||
|
else
|
||||||
|
value="$REPO_LIB_TOOL_ERROR"
|
||||||
|
effective_icon_color_name="RED"
|
||||||
|
value_color_name="RED"
|
||||||
|
fi
|
||||||
|
|
||||||
|
repo_lib_print_pretty_row \
|
||||||
|
"$border_color_name" \
|
||||||
|
"$icon" \
|
||||||
|
"$effective_icon_color_name" \
|
||||||
|
"$name" \
|
||||||
|
"$value" \
|
||||||
|
"$value_color_name"
|
||||||
|
|
||||||
|
if [ "$value_color_name" = "RED" ] && [ "$required" = "1" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
repo_lib_print_pretty_footer() {
|
||||||
|
local border_color_name="$1"
|
||||||
|
local border_color="${!border_color_name:-$BLUE}"
|
||||||
|
|
||||||
|
printf "%s╰─%s\n\n" "$border_color" "$RESET"
|
||||||
}
|
}
|
||||||
|
|
||||||
@SHELL_ENV_SCRIPT@
|
@SHELL_ENV_SCRIPT@
|
||||||
|
|
||||||
@BOOTSTRAP@
|
@BOOTSTRAP@
|
||||||
|
|
||||||
printf "\n$GREEN 🚀 Dev shell ready$RESET\n\n"
|
@SHELL_BANNER_SCRIPT@
|
||||||
@TOOL_BANNER_SCRIPT@
|
|
||||||
printf "\n"
|
|
||||||
|
|
||||||
@EXTRA_SHELL_TEXT@
|
@EXTRA_SHELL_TEXT@
|
||||||
|
|||||||
@@ -136,15 +136,26 @@ Preferred shape in `perSystem.tools`:
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For a tool that should come from the host `PATH` instead of `nixpkgs`:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
(repo-lib.lib.tools.fromCommand {
|
||||||
|
name = "Nix";
|
||||||
|
command = "nix";
|
||||||
|
version.args = [ "--version" ];
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
Helper:
|
Helper:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
repo-lib.lib.tools.simple "Nix" pkgs.nix [ "--version" ]
|
repo-lib.lib.tools.simple "Go" pkgs.go [ "version" ]
|
||||||
```
|
```
|
||||||
|
|
||||||
Tool behavior:
|
Tool behavior:
|
||||||
|
|
||||||
- Tool packages are added to the shell automatically.
|
- Tool packages are added to the shell automatically.
|
||||||
|
- Command-backed tools are probed from the existing `PATH` and are not added to the shell automatically.
|
||||||
- Banner probing uses absolute executable paths.
|
- Banner probing uses absolute executable paths.
|
||||||
- `required = true` by default.
|
- `required = true` by default.
|
||||||
- Required tool probe failure aborts shell startup.
|
- Required tool probe failure aborts shell startup.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v3.0.0";
|
repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v3.1.0";
|
||||||
repo-lib.inputs.nixpkgs.follows = "nixpkgs";
|
repo-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,10 +85,17 @@
|
|||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
tools = [
|
tools = [
|
||||||
(repo-lib.lib.tools.fromPackage {
|
(repo-lib.lib.tools.fromCommand {
|
||||||
name = "Nix";
|
name = "Nix";
|
||||||
package = pkgs.nix;
|
command = "nix";
|
||||||
version.args = [ "--version" ];
|
version = {
|
||||||
|
args = [ "--version" ];
|
||||||
|
group = 1;
|
||||||
|
};
|
||||||
|
banner = {
|
||||||
|
color = "BLUE";
|
||||||
|
icon = "";
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
# (repo-lib.lib.tools.fromPackage {
|
# (repo-lib.lib.tools.fromPackage {
|
||||||
|
|||||||
173
tests/release.sh
173
tests/release.sh
@@ -6,6 +6,11 @@ ROOT_DIR="${REPO_LIB_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
|
|||||||
RELEASE_TEMPLATE="$ROOT_DIR/packages/release/release.sh"
|
RELEASE_TEMPLATE="$ROOT_DIR/packages/release/release.sh"
|
||||||
NIXPKGS_FLAKE_PATH="${NIXPKGS_FLAKE_PATH:-}"
|
NIXPKGS_FLAKE_PATH="${NIXPKGS_FLAKE_PATH:-}"
|
||||||
CURRENT_LOG=""
|
CURRENT_LOG=""
|
||||||
|
QC_SEEN_TAGS=()
|
||||||
|
|
||||||
|
if [[ -z "$NIXPKGS_FLAKE_PATH" ]]; then
|
||||||
|
NIXPKGS_FLAKE_PATH="$(nix eval --raw --impure --expr "(builtins.getFlake (toString ${ROOT_DIR})).inputs.nixpkgs.outPath")"
|
||||||
|
fi
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
echo "[test] FAIL: $*" >&2
|
echo "[test] FAIL: $*" >&2
|
||||||
@@ -70,6 +75,8 @@ setup_repo() {
|
|||||||
run_capture_ok "setup_repo: git init failed" git -C "$repo_dir" init
|
run_capture_ok "setup_repo: git init failed" git -C "$repo_dir" init
|
||||||
run_capture_ok "setup_repo: git config user.name failed" git -C "$repo_dir" config user.name "Release Test"
|
run_capture_ok "setup_repo: git config user.name failed" git -C "$repo_dir" config user.name "Release Test"
|
||||||
run_capture_ok "setup_repo: git config user.email failed" git -C "$repo_dir" config user.email "release-test@example.com"
|
run_capture_ok "setup_repo: git config user.email failed" git -C "$repo_dir" config user.email "release-test@example.com"
|
||||||
|
run_capture_ok "setup_repo: git config commit.gpgsign failed" git -C "$repo_dir" config commit.gpgsign false
|
||||||
|
run_capture_ok "setup_repo: git config tag.gpgsign failed" git -C "$repo_dir" config tag.gpgsign false
|
||||||
|
|
||||||
cat >"$repo_dir/flake.nix" <<'EOF'
|
cat >"$repo_dir/flake.nix" <<'EOF'
|
||||||
{
|
{
|
||||||
@@ -213,6 +220,49 @@ write_mk_repo_flake() {
|
|||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
write_mk_repo_command_tool_flake() {
|
||||||
|
local repo_dir="$1"
|
||||||
|
cat >"$repo_dir/flake.nix" <<EOF
|
||||||
|
{
|
||||||
|
description = "mkRepo command-backed tool";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "path:${NIXPKGS_FLAKE_PATH}";
|
||||||
|
repo-lib.url = "path:${ROOT_DIR}";
|
||||||
|
repo-lib.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, repo-lib, ... }:
|
||||||
|
repo-lib.lib.mkRepo {
|
||||||
|
inherit self nixpkgs;
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
config.release = {
|
||||||
|
steps = [ ];
|
||||||
|
};
|
||||||
|
|
||||||
|
perSystem = { system, ... }: {
|
||||||
|
tools = [
|
||||||
|
(repo-lib.lib.tools.fromCommand {
|
||||||
|
name = "Nix";
|
||||||
|
command = "nix";
|
||||||
|
version.args = [ "--version" ];
|
||||||
|
banner = {
|
||||||
|
color = "BLUE";
|
||||||
|
icon = "";
|
||||||
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
shell.packages = [
|
||||||
|
self.packages.\${system}.release
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
write_tool_failure_flake() {
|
write_tool_failure_flake() {
|
||||||
local repo_dir="$1"
|
local repo_dir="$1"
|
||||||
cat >"$repo_dir/flake.nix" <<EOF
|
cat >"$repo_dir/flake.nix" <<EOF
|
||||||
@@ -297,7 +347,7 @@ write_release_replace_backref_flake() {
|
|||||||
replace = {
|
replace = {
|
||||||
path = "template/flake.nix";
|
path = "template/flake.nix";
|
||||||
regex = ''^([[:space:]]*repo-lib\.url = ")[^"]*(";)$'';
|
regex = ''^([[:space:]]*repo-lib\.url = ")[^"]*(";)$'';
|
||||||
replacement = ''\1git+https://example.invalid/repo-lib?ref=$FULL_TAG\2'';
|
replacement = ''\1git+https://example.invalid/repo-lib?ref=refs/tags/\$FULL_TAG\2'';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -392,7 +442,7 @@ EOF
|
|||||||
write_template_fixture() {
|
write_template_fixture() {
|
||||||
local repo_dir="$1"
|
local repo_dir="$1"
|
||||||
sed \
|
sed \
|
||||||
-e "s|git+https://git.dgren.dev/eric/nix-flake-lib?ref=v[0-9.]*|path:${ROOT_DIR}|" \
|
-e "s|git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v[0-9.]*|path:${ROOT_DIR}|" \
|
||||||
-e "s|github:nixos/nixpkgs?ref=nixos-unstable|path:${NIXPKGS_FLAKE_PATH}|" \
|
-e "s|github:nixos/nixpkgs?ref=nixos-unstable|path:${NIXPKGS_FLAKE_PATH}|" \
|
||||||
"$ROOT_DIR/template/flake.nix" >"$repo_dir/flake.nix"
|
"$ROOT_DIR/template/flake.nix" >"$repo_dir/flake.nix"
|
||||||
}
|
}
|
||||||
@@ -496,6 +546,18 @@ qc_oracle_init() {
|
|||||||
QC_STATE_BASE="1.0.0"
|
QC_STATE_BASE="1.0.0"
|
||||||
QC_STATE_CHANNEL="stable"
|
QC_STATE_CHANNEL="stable"
|
||||||
QC_STATE_PRE=""
|
QC_STATE_PRE=""
|
||||||
|
QC_SEEN_TAGS=()
|
||||||
|
}
|
||||||
|
|
||||||
|
qc_seen_tag() {
|
||||||
|
local tag="$1"
|
||||||
|
local existing
|
||||||
|
for existing in "${QC_SEEN_TAGS[@]:-}"; do
|
||||||
|
if [[ "$existing" == "$tag" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
qc_oracle_current_full() {
|
qc_oracle_current_full() {
|
||||||
@@ -576,12 +638,16 @@ qc_oracle_apply() {
|
|||||||
if [[ $cmp_status -eq 0 || $cmp_status -eq 2 ]]; then
|
if [[ $cmp_status -eq 0 || $cmp_status -eq 2 ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if qc_seen_tag "v$QC_FULL_VERSION"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
QC_STATE_BASE="$QC_BASE_VERSION"
|
QC_STATE_BASE="$QC_BASE_VERSION"
|
||||||
QC_STATE_CHANNEL="$QC_CHANNEL"
|
QC_STATE_CHANNEL="$QC_CHANNEL"
|
||||||
QC_STATE_PRE="$QC_PRERELEASE_NUM"
|
QC_STATE_PRE="$QC_PRERELEASE_NUM"
|
||||||
QC_EXPECT_SUCCESS=1
|
QC_EXPECT_SUCCESS=1
|
||||||
QC_EXPECT_VERSION="$QC_FULL_VERSION"
|
QC_EXPECT_VERSION="$QC_FULL_VERSION"
|
||||||
|
QC_SEEN_TAGS+=("v$QC_FULL_VERSION")
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -649,12 +715,16 @@ qc_oracle_apply() {
|
|||||||
if [[ $QC_FULL_VERSION == "$current_full" ]]; then
|
if [[ $QC_FULL_VERSION == "$current_full" ]]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if qc_seen_tag "v$QC_FULL_VERSION"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
QC_STATE_BASE="$QC_BASE_VERSION"
|
QC_STATE_BASE="$QC_BASE_VERSION"
|
||||||
QC_STATE_CHANNEL="$QC_CHANNEL"
|
QC_STATE_CHANNEL="$QC_CHANNEL"
|
||||||
QC_STATE_PRE="$QC_PRERELEASE_NUM"
|
QC_STATE_PRE="$QC_PRERELEASE_NUM"
|
||||||
QC_EXPECT_SUCCESS=1
|
QC_EXPECT_SUCCESS=1
|
||||||
QC_EXPECT_VERSION="$QC_FULL_VERSION"
|
QC_EXPECT_VERSION="$QC_FULL_VERSION"
|
||||||
|
QC_SEEN_TAGS+=("v$QC_FULL_VERSION")
|
||||||
}
|
}
|
||||||
|
|
||||||
run_randomized_quickcheck_cases() {
|
run_randomized_quickcheck_cases() {
|
||||||
@@ -985,6 +1055,65 @@ EOF
|
|||||||
echo "[test] PASS: $case_name" >&2
|
echo "[test] PASS: $case_name" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_version_metadata_case() {
|
||||||
|
local case_name="release metadata is preserved and exported"
|
||||||
|
local release_steps
|
||||||
|
|
||||||
|
read -r -d '' release_steps <<'EOF' || true
|
||||||
|
if [[ "$(version_meta_get desktop_backend_change_scope)" != "bindings" ]]; then
|
||||||
|
echo "metadata getter mismatch" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "${VERSION_META_DESKTOP_BACKEND_CHANGE_SCOPE:-}" != "bindings" ]]; then
|
||||||
|
echo "metadata export mismatch" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ "${VERSION_META_DESKTOP_RELEASE_MODE:-}" != "binary" ]]; then
|
||||||
|
echo "metadata export mismatch" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
version_meta_set desktop_release_mode codepush
|
||||||
|
version_meta_set desktop_binary_version_min 1.0.0
|
||||||
|
version_meta_set desktop_binary_version_max "$FULL_VERSION"
|
||||||
|
version_meta_set desktop_backend_compat_id compat-123
|
||||||
|
version_meta_unset desktop_unused
|
||||||
|
EOF
|
||||||
|
|
||||||
|
local workdir
|
||||||
|
workdir="$(mktemp -d)"
|
||||||
|
local repo_dir="$workdir/repo"
|
||||||
|
local remote_dir="$workdir/remote.git"
|
||||||
|
CURRENT_LOG="$workdir/case.log"
|
||||||
|
|
||||||
|
prepare_case_repo_with_release_script "$repo_dir" "$remote_dir" "$release_steps" ":"
|
||||||
|
cat >"$repo_dir/VERSION" <<'EOF'
|
||||||
|
1.0.0
|
||||||
|
stable
|
||||||
|
0
|
||||||
|
desktop_backend_change_scope=bindings
|
||||||
|
desktop_release_mode=binary
|
||||||
|
desktop_unused=temporary
|
||||||
|
EOF
|
||||||
|
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" add VERSION
|
||||||
|
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" commit -m "chore: seed metadata"
|
||||||
|
run_capture_ok "$case_name: release command failed" run_release "$repo_dir" patch
|
||||||
|
|
||||||
|
assert_eq "1.0.1" "$(version_from_file "$repo_dir")" "$case_name: VERSION mismatch"
|
||||||
|
assert_contains "desktop_backend_change_scope=bindings" "$repo_dir/VERSION" "$case_name: missing preserved scope"
|
||||||
|
assert_contains "desktop_release_mode=codepush" "$repo_dir/VERSION" "$case_name: missing updated mode"
|
||||||
|
assert_contains "desktop_binary_version_min=1.0.0" "$repo_dir/VERSION" "$case_name: missing min version"
|
||||||
|
assert_contains "desktop_binary_version_max=1.0.1" "$repo_dir/VERSION" "$case_name: missing max version"
|
||||||
|
assert_contains "desktop_backend_compat_id=compat-123" "$repo_dir/VERSION" "$case_name: missing compat id"
|
||||||
|
if grep -Fq "desktop_unused=temporary" "$repo_dir/VERSION"; then
|
||||||
|
fail "$case_name: unset metadata key was preserved"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$workdir"
|
||||||
|
CURRENT_LOG=""
|
||||||
|
echo "[test] PASS: $case_name" >&2
|
||||||
|
}
|
||||||
|
|
||||||
run_mk_repo_case() {
|
run_mk_repo_case() {
|
||||||
local case_name="mkRepo exposes outputs and auto-installs tools"
|
local case_name="mkRepo exposes outputs and auto-installs tools"
|
||||||
local workdir
|
local workdir
|
||||||
@@ -994,13 +1123,35 @@ run_mk_repo_case() {
|
|||||||
write_mk_repo_flake "$repo_dir"
|
write_mk_repo_flake "$repo_dir"
|
||||||
CURRENT_LOG="$workdir/mk-repo.log"
|
CURRENT_LOG="$workdir/mk-repo.log"
|
||||||
|
|
||||||
run_capture_ok "$case_name: flake show failed" nix flake show --json "$repo_dir"
|
run_capture_ok "$case_name: flake show failed" nix flake show --json --no-write-lock-file "$repo_dir"
|
||||||
assert_contains '"pre-commit-check"' "$CURRENT_LOG" "$case_name: missing pre-commit-check"
|
assert_contains '"pre-commit-check"' "$CURRENT_LOG" "$case_name: missing pre-commit-check"
|
||||||
assert_contains '"release"' "$CURRENT_LOG" "$case_name: missing release package"
|
assert_contains '"release"' "$CURRENT_LOG" "$case_name: missing release package"
|
||||||
assert_contains '"example"' "$CURRENT_LOG" "$case_name: missing merged package"
|
assert_contains '"example"' "$CURRENT_LOG" "$case_name: missing merged package"
|
||||||
|
|
||||||
run_capture_ok "$case_name: tool package should be available in shell" nix develop "$repo_dir" -c hello --version
|
run_capture_ok "$case_name: tool package should be available in shell" bash -c 'cd "$1" && nix develop --no-write-lock-file . -c hello --version' _ "$repo_dir"
|
||||||
run_capture_ok "$case_name: release package should be available in shell" nix develop "$repo_dir" -c sh -c 'command -v release >/dev/null'
|
run_capture_ok "$case_name: release package should be available in shell" bash -c 'cd "$1" && nix develop --no-write-lock-file . -c sh -c "command -v release >/dev/null"' _ "$repo_dir"
|
||||||
|
|
||||||
|
rm -rf "$workdir"
|
||||||
|
CURRENT_LOG=""
|
||||||
|
echo "[test] PASS: $case_name" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
run_mk_repo_command_tool_case() {
|
||||||
|
local case_name="mkRepo supports command-backed tools from PATH"
|
||||||
|
local workdir
|
||||||
|
workdir="$(mktemp -d)"
|
||||||
|
local repo_dir="$workdir/mk-repo-command-tool"
|
||||||
|
mkdir -p "$repo_dir"
|
||||||
|
write_mk_repo_command_tool_flake "$repo_dir"
|
||||||
|
CURRENT_LOG="$workdir/mk-repo-command-tool.log"
|
||||||
|
|
||||||
|
run_capture_ok "$case_name: flake show failed" nix flake show --json --no-write-lock-file "$repo_dir"
|
||||||
|
assert_contains '"pre-commit-check"' "$CURRENT_LOG" "$case_name: missing pre-commit-check"
|
||||||
|
assert_contains '"release"' "$CURRENT_LOG" "$case_name: missing release package"
|
||||||
|
|
||||||
|
run_capture_ok "$case_name: system nix should be available in shell" bash -c 'cd "$1" && nix develop --no-write-lock-file . -c nix --version' _ "$repo_dir"
|
||||||
|
assert_contains "" "$CURRENT_LOG" "$case_name: missing tool icon in banner"
|
||||||
|
run_capture_ok "$case_name: release package should be available in shell" bash -c 'cd "$1" && nix develop --no-write-lock-file . -c sh -c "command -v release >/dev/null"' _ "$repo_dir"
|
||||||
|
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
CURRENT_LOG=""
|
CURRENT_LOG=""
|
||||||
@@ -1016,7 +1167,7 @@ run_mk_repo_tool_failure_case() {
|
|||||||
write_tool_failure_flake "$repo_dir"
|
write_tool_failure_flake "$repo_dir"
|
||||||
CURRENT_LOG="$workdir/tool-failure.log"
|
CURRENT_LOG="$workdir/tool-failure.log"
|
||||||
|
|
||||||
run_expect_failure "$case_name: shell startup should fail" nix develop "$repo_dir" -c true
|
run_expect_failure "$case_name: shell startup should fail" bash -c 'cd "$1" && nix develop . -c true' _ "$repo_dir"
|
||||||
assert_contains "probe failed" "$CURRENT_LOG" "$case_name: failure reason missing"
|
assert_contains "probe failed" "$CURRENT_LOG" "$case_name: failure reason missing"
|
||||||
|
|
||||||
rm -rf "$workdir"
|
rm -rf "$workdir"
|
||||||
@@ -1090,7 +1241,7 @@ run_release_replace_backref_case() {
|
|||||||
cat >"$repo_dir/template/flake.nix" <<'EOF'
|
cat >"$repo_dir/template/flake.nix" <<'EOF'
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=v0.0.0";
|
repo-lib.url = "git+https://git.dgren.dev/eric/nix-flake-lib?ref=refs/tags/v0.0.0";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
@@ -1098,10 +1249,10 @@ EOF
|
|||||||
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" add flake.nix template/flake.nix
|
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" add flake.nix template/flake.nix
|
||||||
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" commit -m "chore: add replace fixture"
|
run_capture_ok "$case_name: setup commit failed" git -C "$repo_dir" commit -m "chore: add replace fixture"
|
||||||
|
|
||||||
run_capture_ok "$case_name: nix run release failed" bash -c 'cd "$1" && nix run .#release -- patch' _ "$repo_dir"
|
run_capture_ok "$case_name: nix run release failed" bash -c 'cd "$1" && nix run --no-write-lock-file .#release -- patch' _ "$repo_dir"
|
||||||
|
|
||||||
assert_contains 'repo-lib.url = "git+https://example.invalid/repo-lib?ref=v1.0.1";' "$repo_dir/template/flake.nix" "$case_name: replacement did not preserve captures"
|
assert_contains 'repo-lib.url = "git+https://example.invalid/repo-lib?ref=refs/tags/v1.0.1";' "$repo_dir/template/flake.nix" "$case_name: replacement did not preserve captures"
|
||||||
if grep -Fq '\1git+https://example.invalid/repo-lib?ref=v1.0.1\2' "$repo_dir/template/flake.nix"; then
|
if grep -Fq '\1git+https://example.invalid/repo-lib?ref=refs/tags/v1.0.1\2' "$repo_dir/template/flake.nix"; then
|
||||||
fail "$case_name: replacement left literal backreferences in output"
|
fail "$case_name: replacement left literal backreferences in output"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -1117,7 +1268,9 @@ run_set_stable_then_full_noop_case
|
|||||||
run_set_stable_from_prerelease_requires_full_case
|
run_set_stable_from_prerelease_requires_full_case
|
||||||
run_patch_stable_from_prerelease_requires_full_case
|
run_patch_stable_from_prerelease_requires_full_case
|
||||||
run_structured_release_steps_case
|
run_structured_release_steps_case
|
||||||
|
run_version_metadata_case
|
||||||
run_mk_repo_case
|
run_mk_repo_case
|
||||||
|
run_mk_repo_command_tool_case
|
||||||
run_mk_repo_tool_failure_case
|
run_mk_repo_tool_failure_case
|
||||||
run_impure_bootstrap_validation_case
|
run_impure_bootstrap_validation_case
|
||||||
run_legacy_api_eval_case
|
run_legacy_api_eval_case
|
||||||
|
|||||||
Reference in New Issue
Block a user