Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 174 lines 3.5 kB view raw
1#!/bin/bash 2 3PATH="@path@:$PATH" 4IS_DARWIN="@is_darwin@" 5 6set -eu 7set -o pipefail 8 9DEBUG=0 10MARKDOWN=0 11HOST_OS=0 12SANDBOX=0 13while 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 40nix-info - get high level info to help with debugging 41 42Options: 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 53EOF 54 case "${1:-}" in 55 -h|--help) 56 exit 0 57 ;; 58 *) 59 exit 1 60 ;; 61 esac 62 esac 63done 64 65debuglog() { 66 if [ $DEBUG -eq 1 ]; then 67 cat >&2 68 else 69 cat > /dev/null 70 fi 71} 72 73nixev() { 74 nix-instantiate --eval --strict -E "$1" 75} 76 77desc_system() { 78 nixev 'builtins.currentSystem' 79} 80 81desc_host_os() { 82 printf "%s" "$(uname -sr)" 83 84 if [ "$IS_DARWIN" = "yes" ]; then 85 printf ", macOS %s" "$(sw_vers -productVersion)" 86 fi 87 88 if [ -f /etc/os-release ]; then 89 ( 90 # shellcheck disable=SC1091 91 . /etc/os-release 92 printf ", %s, %s, %s" "${NAME:-$(uname -v)}" "${VERSION:-noversion}" "${BUILD_ID:-nobuild}" 93 ) 94 fi 95} 96 97desc_multi_user() { 98 if nix-build --no-out-link @multiusertest@ 2>&1 | debuglog; then 99 printf "yes" 100 else 101 printf "no" 102 fi 103} 104 105desc_nixpkgs_path() { 106 nixev '<nixpkgs>' 2>/dev/null || echo "not found" 107} 108 109channel_facts() { 110 find /nix/var/nix/profiles/per-user \ 111 -mindepth 2 \ 112 -maxdepth 2 \ 113 -name channels \ 114 -print0 \ 115 |\ 116 while IFS= read -r -d '' userchannelset; do 117 manifest="$userchannelset/manifest.nix" 118 119 if [ -e "$manifest" ]; then 120 userchannels=$(nixev \ 121 "builtins.concatStringsSep \", \" 122 (map (ch: ch.name) 123 (import \"$manifest\"))") 124 125 fact "channels($(echo "$manifest" | cut -d/ -f7))" \ 126 "$userchannels" 127 fi 128 done 129} 130 131desc_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" 138 fi 139} 140 141fact() { 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 ", " 149 fi 150 else 151 printf " - %s: \`%s\`\\n" "$name" "$value" 152 fi 153 154 if [ "$last" -eq 0 ]; then 155 echo "" 156 fi 157} 158 159last_fact() { 160 fact "$1" "$2" 0 161} 162 163fact "system" "$(desc_system)" 164if [ $HOST_OS -eq 1 ]; then 165 fact "host os" "$(desc_host_os)" 166fi 167fact "multi-user?" "$(desc_multi_user)" 168if [ $SANDBOX -eq 1 ]; then 169 fact "sandbox" "$(desc_sandbox)" 170fi 171 172fact "version" "$(nix-env --version)" 173channel_facts 174last_fact "nixpkgs" "$(desc_nixpkgs_path)"