-
Notifications
You must be signed in to change notification settings - Fork 15
/
util.nix
45 lines (40 loc) · 1.4 KB
/
util.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{ writeScriptBin, runCommand, xterm }:
let
nixposition = writeScriptBin "nix-position" ''
nix-position () {
usage () {
echo "Usage: nix-position <attribute-path-under-pkgs>"
echo "Shows the Nix source file for a given attribute path."
}
if [ $# -ne 1 ]; then usage; return -1; fi
local EXPR="(import <nixpkgs> {}).pkgs.${1}.meta.position"
nix-instantiate --eval -E "''${EXPR}" | sed 's:"$::g' | sed 's:^"::g'
return 0
}
'';
in runCommand "util-1" {} ''
mkdir -pv $out/bin
cat << EOF > $out/bin/loginto
#!$SHELL
exec ${xterm}/bin/xterm -e ssh \$1 -t screen -xRRU
EOF
chmod +x $out/bin/loginto
cat << EOF > $out/bin/showsize
#!$SHELL
nix-store --query --tree "\$1" | sed 's,[-+| ]*/,/,' | awk '{print \$1}' | sort | uniq | xargs nix-store --query --size | paste -sd+ | ( echo -n '( ';sed 's,+, + ,g';echo ' ) / 1024 / 1024' ) | xargs expr
EOF
chmod +x $out/bin/showsize
cat << EOF > $out/bin/nix-lookup
#!$SHELL
local USAGE
USAGE="$USAGE Usage: nix-lookup <expression-path-under-pkgs>"
USAGE="$USAGE Shows the directory for the given attribute path."
if [ $# -ne 1 ]; then echo "$USAGE"; return -1; fi
nix-instantiate --eval -E "\"\''${(import <nixpkgs> {}).pkgs.$1}\"" | sed 's:"::g'
EOF
chmod +x $out/bin/nix-lookup
cat << EOF > $out/bin/nix-unpack
nix-shell --run 'phases=unpackPhase genericBuild' "$@"
EOF
chmod +x $out/bin/nix-unpack
''