Created
November 7, 2025 06:57
-
-
Save luochen1990/bfe8f98e6a45ff943b9db40e54ccb96e to your computer and use it in GitHub Desktop.
简短打印 nixos-rebuild 报错栈。 谢谢 dram 提供的思路
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # 针对 error: Package ‘xxx’ in /nix/store/xxx is marked as insecure, refusing to evaluate. 的报错,打印它的依赖栈 | |
| # 由以下惯用命令得到启发: nixos-rebuild build --show-trace | rg 'while evaluating derivation' | |
| set -euo pipefail | |
| if [[ $# -gt 1 ]]; then | |
| echo "Usage: $(basename "$0") [hostname]" | |
| exit 1 | |
| fi | |
| if [[ $# -eq 1 ]]; then | |
| hostname="$1" | |
| else | |
| hostname="$(hostname -s)" # 获取当前主机短名 | |
| fi | |
| # 这里假定你在当前目录为 flake 根目录 or 你已经在合适的目录下 | |
| # 并假定你的 flake 输出包含 `nixosConfigurations` 并且属性名是 hostname | |
| expr=".#nixosConfigurations.${hostname}.config.system.build.toplevel" | |
| echo "Evaluating flake output for host '${hostname}': $expr" | |
| # 执行评估并过滤 | |
| nix eval ${expr} --show-trace 2>&1 | rg "error:|while evaluating derivation" | |
| # 返回 nix eval 的 exit code(rg 的 exit code 可能是 >0 如果没有匹配项) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使用效果示例:
