git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #30397 from grahamc/nix-help

nix-info: init

commitab8b14cf9204c3084c509d3f07bd21e3b3aae483 authorGraham Christensen <graham@grahamc.com> dateMon 16 Oct 2017, 21:37 (9 years ago) parentbd87a3bb16f3b2
8 files changed+247
nixos/modules/config/system-path.nix+1 pkgs/tools/nix/info/default.nix+37 pkgs/tools/nix/info/info.sh+169 pkgs/tools/nix/info/multiuser.nix+12 pkgs/tools/nix/info/relaxedsandbox.nix+12 pkgs/tools/nix/info/sandbox.nix+10 pkgs/top-level/all-packages.nix+2 pkgs/top-level/release.nix+4
nixos/modules/config/system-path.nix+1
@@ -31,6 +31,7 @@ let
3131 pkgs.nano
3232 pkgs.ncurses
3333 pkgs.netcat
34+ pkgs.nix-info
3435 config.programs.ssh.package
3536 pkgs.perl
3637 pkgs.procps
pkgs/tools/nix/info/default.nixnew file+37
@@ -0,0 +1,37 @@
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+}
pkgs/tools/nix/info/info.shnew file+169
@@ -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)"
pkgs/tools/nix/info/multiuser.nixnew file+12
@@ -0,0 +1,12 @@
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+ ''
pkgs/tools/nix/info/relaxedsandbox.nixnew file+12
@@ -0,0 +1,12 @@
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+ ''
pkgs/tools/nix/info/sandbox.nixnew file+10
@@ -0,0 +1,10 @@
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+ ''
pkgs/top-level/all-packages.nix+2
@@ -19154,6 +19154,8 @@ with pkgs;
1915419154
1915519155 nix-bundle = callPackage ../tools/package-management/nix-bundle { nix = nixUnstable; };
1915619156
19157+ nix-info = callPackage ../tools/nix/info { };
19158+
1915719159 nix-index = callPackage ../tools/package-management/nix-index { };
1915819160
1915919161 inherit (callPackages ../tools/package-management/nix-prefetch-scripts { })
pkgs/top-level/release.nix+4
@@ -47,6 +47,7 @@ let
4747 jobs.nix-repl.x86_64-darwin
4848 jobs.nix.x86_64-darwin
4949 jobs.nox.x86_64-darwin
50+ jobs.nix-info.x86_64-darwin
5051 jobs.openssh.x86_64-darwin
5152 jobs.openssl.x86_64-darwin
5253 jobs.postgresql.x86_64-darwin
@@ -88,6 +89,9 @@ let
8889 # Needed by travis-ci to test PRs
8990 jobs.nox.x86_64-linux
9091 jobs.nox.x86_64-darwin
92+ # Needed for support
93+ jobs.nix-info.x86_64-linux
94+ jobs.nix-info.x86_64-darwin
9195 # Ensure that X11/GTK+ are in order.
9296 jobs.thunderbird.x86_64-linux
9397 # Ensure that basic stuff works on darwin