base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12 (#356361)
[NixPkgs.git] / pkgs / tools / nix / info / info.sh
blob15bed4af74d4345d44897b2d871ee26b70058fcb
1 #!/bin/bash
3 PATH="@path@:$PATH"
4 IS_DARWIN="@is_darwin@"
6 set -eu
7 set -o pipefail
9 DEBUG=0
10 MARKDOWN=0
11 HOST_OS=0
12 SANDBOX=0
13 while true; do
14 case "${1:-}" in
15 "")
16 break
18 -d | --debug)
19 set -x
20 DEBUG=1
21 shift
23 -m | --markdown)
24 MARKDOWN=1
25 HOST_OS=1
26 SANDBOX=1
27 shift
29 --host-os)
30 HOST_OS=1
31 shift
33 --sandbox)
34 SANDBOX=1
35 shift
38 * )
39 cat <<EOF
40 nix-info - get high level info to help with debugging
42 Options:
44 -m, --markdown formatting for a GitHub issue
45 implies: --host-os, --sandbox
47 --sandbox include sandbox configuration
48 --host-os include host OS details
50 -h, --help show this message
51 -d, --debug debug mode
53 EOF
54 case "${1:-}" in
55 -h|--help)
56 exit 0
59 exit 1
61 esac
62 esac
63 done
65 debuglog() {
66 if [ $DEBUG -eq 1 ]; then
67 cat >&2
68 else
69 cat > /dev/null
73 nixev() {
74 nix-instantiate --eval --strict -E "$1"
77 desc_system() {
78 nixev 'builtins.currentSystem'
81 desc_host_os() {
82 printf "%s" "$(uname -sr)"
84 if [ "$IS_DARWIN" = "yes" ]; then
85 printf ", macOS %s" "$(sw_vers -productVersion)"
88 if [ -f /etc/os-release ]; then
90 # shellcheck disable=SC1091
91 . /etc/os-release
92 printf ", %s, %s, %s" "${NAME:-$(uname -v)}" "${VERSION:-noversion}" "${BUILD_ID:-nobuild}"
97 desc_multi_user() {
98 if nix-build --no-out-link @multiusertest@ 2>&1 | debuglog; then
99 printf "yes"
100 else
101 printf "no"
105 desc_nixpkgs_path() {
106 nixev '<nixpkgs>' 2>/dev/null || echo "not found"
109 channel_facts() {
110 find /nix/var/nix/profiles/per-user \
111 -mindepth 2 \
112 -maxdepth 2 \
113 -name channels \
114 -print0 \
116 while IFS= read -r -d '' userchannelset; do
117 manifest="$userchannelset/manifest.nix"
119 if [ -e "$manifest" ]; then
120 userchannels=$(nixev \
121 "builtins.concatStringsSep \", \"
122 (map (ch: ch.name)
123 (import \"$manifest\"))")
125 fact "channels($(echo "$manifest" | cut -d/ -f7))" \
126 "$userchannels"
128 done
131 desc_sandbox() {
132 if nix-build --no-out-link @sandboxtest@ 2>&1 | debuglog; then
133 printf "no"
134 elif nix-build --no-out-link @relaxedsandboxtest@ 2>&1 | debuglog; then
135 printf "relaxed"
136 else
137 printf "yes"
141 fact() {
142 name="${1:-0}"
143 value="${2:-0}"
144 last="${3:-1}"
145 if [ $MARKDOWN -eq 0 ]; then
146 printf "%s: %s" "$name" "$value"
147 if [ "$last" -eq 1 ]; then
148 printf ", "
150 else
151 printf " - %s: \`%s\`\\n" "$name" "$value"
154 if [ "$last" -eq 0 ]; then
155 echo ""
159 last_fact() {
160 fact "$1" "$2" 0
163 fact "system" "$(desc_system)"
164 if [ $HOST_OS -eq 1 ]; then
165 fact "host os" "$(desc_host_os)"
167 fact "multi-user?" "$(desc_multi_user)"
168 if [ $SANDBOX -eq 1 ]; then
169 fact "sandbox" "$(desc_sandbox)"
172 fact "version" "$(nix-env --version)"
173 channel_facts
174 last_fact "nixpkgs" "$(desc_nixpkgs_path)"