nix-info: init

+242
+37
pkgs/tools/nix/info/default.nix
··· 1 + { stdenv, lib, coreutils, findutils, gnugrep, darwin, shellcheck }: 2 + stdenv.mkDerivation { 3 + name = "nix-info"; 4 + src = ./info.sh; 5 + 6 + buildInputs = [ 7 + shellcheck 8 + ]; 9 + 10 + path = lib.makeBinPath ([ 11 + coreutils findutils gnugrep 12 + ] ++ (if stdenv.isDarwin then [ darwin.DarwinTools ] else [])); 13 + is_darwin = if stdenv.isDarwin then "yes" else "no"; 14 + 15 + sandboxtest = ./sandbox.nix; 16 + relaxedsandboxtest = ./relaxedsandbox.nix; 17 + multiusertest = ./multiuser.nix; 18 + 19 + unpackCmd = '' 20 + mkdir nix-info 21 + cp $src ./nix-info/nix-info 22 + ''; 23 + 24 + buildPhase = '' 25 + substituteAllInPlace ./nix-info 26 + ''; 27 + 28 + doCheck = true; 29 + checkPhase = '' 30 + shellcheck ./nix-info 31 + ''; 32 + 33 + installPhase = '' 34 + mkdir -p $out/bin 35 + cp ./nix-info $out/bin/nix-info 36 + ''; 37 + }
+169
pkgs/tools/nix/info/info.sh
··· 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)"
+12
pkgs/tools/nix/info/multiuser.nix
··· 1 + let 2 + pkgs = import <nixpkgs> {}; 3 + in pkgs.runCommand "diagnostics-multiuser" 4 + { } 5 + '' 6 + set -x 7 + # no cache: ${toString builtins.currentTime} 8 + # For reproducibility, nix always uses nixbld group: 9 + # https://github.com/NixOS/nix/blob/1dd29d7aebae706f3e90a18bbfae727f2ed03c70/src/libstore/build.cc#L1896-L1908 10 + test "$(groups)" == "nixbld" 11 + touch $out 12 + ''
+12
pkgs/tools/nix/info/relaxedsandbox.nix
··· 1 + let 2 + pkgs = import <nixpkgs> {}; 3 + in pkgs.runCommand "diagnostics-sandbox" 4 + { 5 + __noChroot = true; 6 + } 7 + '' 8 + set -x 9 + # no cache: ${toString builtins.currentTime} 10 + test -d "$(dirname "$out")/../var/nix" 11 + touch $out 12 + ''
+10
pkgs/tools/nix/info/sandbox.nix
··· 1 + let 2 + pkgs = import <nixpkgs> {}; 3 + in pkgs.runCommand "diagnostics-sandbox" 4 + { } 5 + '' 6 + set -x 7 + # no cache: ${toString builtins.currentTime} 8 + test -d "$(dirname "$out")/../var/nix" 9 + touch $out 10 + ''
+2
pkgs/top-level/all-packages.nix
··· 19123 19123 19124 19124 nix-bundle = callPackage ../tools/package-management/nix-bundle { nix = nixUnstable; }; 19125 19125 19126 + nix-info = callPackage ../tools/nix/info { }; 19127 + 19126 19128 nix-index = callPackage ../tools/package-management/nix-index { }; 19127 19129 19128 19130 inherit (callPackages ../tools/package-management/nix-prefetch-scripts { })