@@ -0,0 +1,169 @@
1+#!/bin/bash
2+
3+PATH="@path@:$PATH"
4+IS_DARWIN="@is_darwin@"
5+
6+set -eu
7+set -o pipefail
8+
9+DEBUG=0
10+MARKDOWN=0
11+HOST_OS=0
12+SANDBOX=0
13+while true; do
14+ case "${1:-}" in
15+ "")
16+ break
17+ ;;
18+ -d | --debug)
19+ set -x
20+ DEBUG=1
21+ shift
22+ ;;
23+ -m | --markdown)
24+ MARKDOWN=1
25+ HOST_OS=1
26+ SANDBOX=1
27+ shift
28+ ;;
29+ --host-os)
30+ HOST_OS=1
31+ shift
32+ ;;
33+ --sandbox)
34+ SANDBOX=1
35+ shift
36+ ;;
37+
38+ * )
39+ cat <<EOF
40+nix-info - get high level info to help with debugging
41+
42+Options:
43+
44+ -m, --markdown formatting for a GitHub issue
45+ implies: --host-os, --sandbox
46+
47+ --sandbox include sandbox configuration
48+ --host-os include host OS details
49+
50+ -h, --help show this message
51+ -d, --debug debug mode
52+
53+EOF
54+ exit 1
55+ ;;
56+
57+ esac
58+done
59+
60+debuglog() {
61+ if [ $DEBUG -eq 1 ]; then
62+ cat >&2
63+ else
64+ cat > /dev/null
65+ fi
66+}
67+
68+nixev() {
69+ nix-instantiate --eval --strict -E "$1"
70+}
71+
72+desc_system() {
73+ nixev '(import <nixpkgs> {}).system'
74+}
75+
76+desc_host_os() {
77+ printf "%s" "$(uname -sr)"
78+
79+ if [ "$IS_DARWIN" = "yes" ]; then
80+ printf ", macOS %s" "$(sw_vers -productVersion)"
81+ fi
82+
83+ if [ -f /etc/os-release ]; then
84+ (
85+ # shellcheck disable=SC1091
86+ . /etc/os-release
87+ printf ", %s, %s" "${NAME:-$(uname -v)}" "${VERSION:-noversion}"
88+ )
89+ fi
90+}
91+
92+desc_multi_user() {
93+ if nix-build --no-out-link @multiusertest@ 2>&1 | debuglog; then
94+ printf "yes"
95+ else
96+ printf "no"
97+ fi
98+}
99+
100+desc_nixpkgs_path() {
101+ nixev '<nixpkgs>'
102+}
103+
104+channel_facts() {
105+ find /nix/var/nix/profiles/per-user \
106+ -mindepth 2 \
107+ -maxdepth 2 \
108+ -name channels \
109+ -print0 \
110+ |\
111+ while IFS= read -r -d '' userchannelset; do
112+ manifest="$userchannelset/manifest.nix"
113+
114+ if [ -e "$manifest" ]; then
115+ userchannels=$(nixev \
116+ "builtins.concatStringsSep \", \"
117+ (map (ch: ch.name)
118+ (import \"$manifest\"))")
119+
120+ fact "channels($(echo "$manifest" | cut -d/ -f7))" \
121+ "$userchannels"
122+ fi
123+ done
124+}
125+
126+desc_sandbox() {
127+ if nix-build --no-out-link @sandboxtest@ 2>&1 | debuglog; then
128+ printf "no"
129+ elif nix-build --no-out-link @relaxedsandboxtest@ 2>&1 | debuglog; then
130+ printf "relaxed"
131+ else
132+ printf "yes"
133+ fi
134+}
135+
136+fact() {
137+ name="${1:-0}"
138+ value="${2:-0}"
139+ last="${3:-1}"
140+ if [ $MARKDOWN -eq 0 ]; then
141+ printf "%s: %s" "$name" "$value"
142+ if [ "$last" -eq 1 ]; then
143+ printf ", "
144+ fi
145+ else
146+ printf " - %s: \`%s\`\n" "$name" "$value"
147+ fi
148+
149+ if [ "$last" -eq 0 ]; then
150+ echo ""
151+ fi
152+}
153+
154+last_fact() {
155+ fact "$1" "$2" 0
156+}
157+
158+fact "system" "$(desc_system)"
159+if [ $HOST_OS -eq 1 ]; then
160+ fact "host os" "$(desc_host_os)"
161+fi
162+fact "multi-user?" "$(desc_multi_user)"
163+if [ $SANDBOX -eq 1 ]; then
164+ fact "sandbox" "$(desc_sandbox)"
165+fi
166+
167+fact "version" "$(nix-env --version)"
168+channel_facts
169+last_fact "nixpkgs" "$(desc_nixpkgs_path)"