tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
lol
0
fork
atom
overview
issues
pulls
pipelines
nix-info: init
Graham Christensen
8 years ago
d9d2c4a4
534060e6
+242
6 changed files
expand all
collapse all
unified
split
pkgs
tools
nix
info
default.nix
info.sh
multiuser.nix
relaxedsandbox.nix
sandbox.nix
top-level
all-packages.nix
+37
pkgs/tools/nix/info/default.nix
···
1
1
+
{ stdenv, lib, coreutils, findutils, gnugrep, darwin, shellcheck }:
2
2
+
stdenv.mkDerivation {
3
3
+
name = "nix-info";
4
4
+
src = ./info.sh;
5
5
+
6
6
+
buildInputs = [
7
7
+
shellcheck
8
8
+
];
9
9
+
10
10
+
path = lib.makeBinPath ([
11
11
+
coreutils findutils gnugrep
12
12
+
] ++ (if stdenv.isDarwin then [ darwin.DarwinTools ] else []));
13
13
+
is_darwin = if stdenv.isDarwin then "yes" else "no";
14
14
+
15
15
+
sandboxtest = ./sandbox.nix;
16
16
+
relaxedsandboxtest = ./relaxedsandbox.nix;
17
17
+
multiusertest = ./multiuser.nix;
18
18
+
19
19
+
unpackCmd = ''
20
20
+
mkdir nix-info
21
21
+
cp $src ./nix-info/nix-info
22
22
+
'';
23
23
+
24
24
+
buildPhase = ''
25
25
+
substituteAllInPlace ./nix-info
26
26
+
'';
27
27
+
28
28
+
doCheck = true;
29
29
+
checkPhase = ''
30
30
+
shellcheck ./nix-info
31
31
+
'';
32
32
+
33
33
+
installPhase = ''
34
34
+
mkdir -p $out/bin
35
35
+
cp ./nix-info $out/bin/nix-info
36
36
+
'';
37
37
+
}
+169
pkgs/tools/nix/info/info.sh
···
1
1
+
#!/bin/bash
2
2
+
3
3
+
PATH="@path@:$PATH"
4
4
+
IS_DARWIN="@is_darwin@"
5
5
+
6
6
+
set -eu
7
7
+
set -o pipefail
8
8
+
9
9
+
DEBUG=0
10
10
+
MARKDOWN=0
11
11
+
HOST_OS=0
12
12
+
SANDBOX=0
13
13
+
while true; do
14
14
+
case "${1:-}" in
15
15
+
"")
16
16
+
break
17
17
+
;;
18
18
+
-d | --debug)
19
19
+
set -x
20
20
+
DEBUG=1
21
21
+
shift
22
22
+
;;
23
23
+
-m | --markdown)
24
24
+
MARKDOWN=1
25
25
+
HOST_OS=1
26
26
+
SANDBOX=1
27
27
+
shift
28
28
+
;;
29
29
+
--host-os)
30
30
+
HOST_OS=1
31
31
+
shift
32
32
+
;;
33
33
+
--sandbox)
34
34
+
SANDBOX=1
35
35
+
shift
36
36
+
;;
37
37
+
38
38
+
* )
39
39
+
cat <<EOF
40
40
+
nix-info - get high level info to help with debugging
41
41
+
42
42
+
Options:
43
43
+
44
44
+
-m, --markdown formatting for a GitHub issue
45
45
+
implies: --host-os, --sandbox
46
46
+
47
47
+
--sandbox include sandbox configuration
48
48
+
--host-os include host OS details
49
49
+
50
50
+
-h, --help show this message
51
51
+
-d, --debug debug mode
52
52
+
53
53
+
EOF
54
54
+
exit 1
55
55
+
;;
56
56
+
57
57
+
esac
58
58
+
done
59
59
+
60
60
+
debuglog() {
61
61
+
if [ $DEBUG -eq 1 ]; then
62
62
+
cat >&2
63
63
+
else
64
64
+
cat > /dev/null
65
65
+
fi
66
66
+
}
67
67
+
68
68
+
nixev() {
69
69
+
nix-instantiate --eval --strict -E "$1"
70
70
+
}
71
71
+
72
72
+
desc_system() {
73
73
+
nixev '(import <nixpkgs> {}).system'
74
74
+
}
75
75
+
76
76
+
desc_host_os() {
77
77
+
printf "%s" "$(uname -sr)"
78
78
+
79
79
+
if [ "$IS_DARWIN" = "yes" ]; then
80
80
+
printf ", macOS %s" "$(sw_vers -productVersion)"
81
81
+
fi
82
82
+
83
83
+
if [ -f /etc/os-release ]; then
84
84
+
(
85
85
+
# shellcheck disable=SC1091
86
86
+
. /etc/os-release
87
87
+
printf ", %s, %s" "${NAME:-$(uname -v)}" "${VERSION:-noversion}"
88
88
+
)
89
89
+
fi
90
90
+
}
91
91
+
92
92
+
desc_multi_user() {
93
93
+
if nix-build --no-out-link @multiusertest@ 2>&1 | debuglog; then
94
94
+
printf "yes"
95
95
+
else
96
96
+
printf "no"
97
97
+
fi
98
98
+
}
99
99
+
100
100
+
desc_nixpkgs_path() {
101
101
+
nixev '<nixpkgs>'
102
102
+
}
103
103
+
104
104
+
channel_facts() {
105
105
+
find /nix/var/nix/profiles/per-user \
106
106
+
-mindepth 2 \
107
107
+
-maxdepth 2 \
108
108
+
-name channels \
109
109
+
-print0 \
110
110
+
|\
111
111
+
while IFS= read -r -d '' userchannelset; do
112
112
+
manifest="$userchannelset/manifest.nix"
113
113
+
114
114
+
if [ -e "$manifest" ]; then
115
115
+
userchannels=$(nixev \
116
116
+
"builtins.concatStringsSep \", \"
117
117
+
(map (ch: ch.name)
118
118
+
(import \"$manifest\"))")
119
119
+
120
120
+
fact "channels($(echo "$manifest" | cut -d/ -f7))" \
121
121
+
"$userchannels"
122
122
+
fi
123
123
+
done
124
124
+
}
125
125
+
126
126
+
desc_sandbox() {
127
127
+
if nix-build --no-out-link @sandboxtest@ 2>&1 | debuglog; then
128
128
+
printf "no"
129
129
+
elif nix-build --no-out-link @relaxedsandboxtest@ 2>&1 | debuglog; then
130
130
+
printf "relaxed"
131
131
+
else
132
132
+
printf "yes"
133
133
+
fi
134
134
+
}
135
135
+
136
136
+
fact() {
137
137
+
name="${1:-0}"
138
138
+
value="${2:-0}"
139
139
+
last="${3:-1}"
140
140
+
if [ $MARKDOWN -eq 0 ]; then
141
141
+
printf "%s: %s" "$name" "$value"
142
142
+
if [ "$last" -eq 1 ]; then
143
143
+
printf ", "
144
144
+
fi
145
145
+
else
146
146
+
printf " - %s: \`%s\`\n" "$name" "$value"
147
147
+
fi
148
148
+
149
149
+
if [ "$last" -eq 0 ]; then
150
150
+
echo ""
151
151
+
fi
152
152
+
}
153
153
+
154
154
+
last_fact() {
155
155
+
fact "$1" "$2" 0
156
156
+
}
157
157
+
158
158
+
fact "system" "$(desc_system)"
159
159
+
if [ $HOST_OS -eq 1 ]; then
160
160
+
fact "host os" "$(desc_host_os)"
161
161
+
fi
162
162
+
fact "multi-user?" "$(desc_multi_user)"
163
163
+
if [ $SANDBOX -eq 1 ]; then
164
164
+
fact "sandbox" "$(desc_sandbox)"
165
165
+
fi
166
166
+
167
167
+
fact "version" "$(nix-env --version)"
168
168
+
channel_facts
169
169
+
last_fact "nixpkgs" "$(desc_nixpkgs_path)"
+12
pkgs/tools/nix/info/multiuser.nix
···
1
1
+
let
2
2
+
pkgs = import <nixpkgs> {};
3
3
+
in pkgs.runCommand "diagnostics-multiuser"
4
4
+
{ }
5
5
+
''
6
6
+
set -x
7
7
+
# no cache: ${toString builtins.currentTime}
8
8
+
# For reproducibility, nix always uses nixbld group:
9
9
+
# https://github.com/NixOS/nix/blob/1dd29d7aebae706f3e90a18bbfae727f2ed03c70/src/libstore/build.cc#L1896-L1908
10
10
+
test "$(groups)" == "nixbld"
11
11
+
touch $out
12
12
+
''
+12
pkgs/tools/nix/info/relaxedsandbox.nix
···
1
1
+
let
2
2
+
pkgs = import <nixpkgs> {};
3
3
+
in pkgs.runCommand "diagnostics-sandbox"
4
4
+
{
5
5
+
__noChroot = true;
6
6
+
}
7
7
+
''
8
8
+
set -x
9
9
+
# no cache: ${toString builtins.currentTime}
10
10
+
test -d "$(dirname "$out")/../var/nix"
11
11
+
touch $out
12
12
+
''
+10
pkgs/tools/nix/info/sandbox.nix
···
1
1
+
let
2
2
+
pkgs = import <nixpkgs> {};
3
3
+
in pkgs.runCommand "diagnostics-sandbox"
4
4
+
{ }
5
5
+
''
6
6
+
set -x
7
7
+
# no cache: ${toString builtins.currentTime}
8
8
+
test -d "$(dirname "$out")/../var/nix"
9
9
+
touch $out
10
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
19126
+
nix-info = callPackage ../tools/nix/info { };
19127
19127
+
19126
19128
nix-index = callPackage ../tools/package-management/nix-index { };
19127
19129
19128
19130
inherit (callPackages ../tools/package-management/nix-prefetch-scripts { })