-
Notifications
You must be signed in to change notification settings - Fork 1
/
env
executable file
·118 lines (95 loc) · 2.71 KB
/
env
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
export MY_NIX_ROOT=/home/ierton/proj/nix
export NIX_PATH="nixpkgs=$MY_NIX_ROOT/nixpkgs:nixos=$MY_NIX_ROOT/nixos:nixos-config=$MY_NIX_ROOT/nixos-config:services=/etc/nixos/services"
cde() { cd $MY_NIX_ROOT; }
cdp() { cd $MY_NIX_ROOT/nixpkgs; }
cdn() { cd $MY_NIX_ROOT/nixos; }
vimconf() { (cde && vim nixos-config ; ); }
vimallp() { (cdp && vim pkgs/top-level/all-packages.nix; ); }
vime() { (cde && vim .; ); }
asroot() {
case `whoami` in
root)
echo "" ;;
*)
echo "sudo -H " ;;
esac
}
tofull() {
case $1 in
/*) echo "$1" ;;
*) echo "`pwd`/$1" ;;
esac
}
tfetch() {
( cdp && git fetch origin ; )
( cdn && git fetch origin ; )
}
ttest() { # Runs nixos-rebuil dry-run
nixos-rebuild -I $MY_NIX_ROOT "$@" dry-run
}
tswitch() { # Runs nixos-rebuild switch
`asroot` nixos-rebuild -I $MY_NIX_ROOT switch
}
trev() { # Pulls revision from nixos channel
REVFILE=/nix/var/nix/profiles/per-user/root/channels/nixos/nixos/svn-revision
REV_INFO=`cut -d'_' -f2 < $REVFILE`
case $1 in
nixpkgs) echo $REV_INFO | cut -d'-' -f2 ;;
nixos) echo $REV_INFO | cut -d'-' -f1 ;;
*) printf "usage: trev nixos|nixpkgs\n" >&2
printf "revision file contents: %s\n" `cat $REVFILE` >&2
return 1
;;
esac
}
tgitpull() { # Pull git trees
(cd $MY_NIX_ROOT/nixpkgs && git tag -f `trev nixpkgs` `trev nixpkgs` ; )
(cd $MY_NIX_ROOT/nixos && git tag -f `trev nixos` `trev nixos` ; )
tfetch &&
(`asroot` nix-channel --update nixos) &&
(cd $MY_NIX_ROOT/nixpkgs && git checkout local && git rebase `trev nixpkgs` ; ) &&
(cd $MY_NIX_ROOT/nixos && git checkout local && git rebase `trev nixos` ; )
}
pfetch() { # Fetches a package by name (as written in all-packages.nix)
nix-build --no-out-link $MY_NIX_ROOT/nixpkgs/pkgs/top-level/all-packages.nix -A $1.src --show-trace
}
punpack() { # Unpacks the tarball to the current dir
aunpack `pfetch $1`
}
penv() { # Sets up build environment (needs aunpack package)
A=`pfetch "$1"`
test -n "$A" || return 1
T=`mktemp -d`
test -n "$T" || return 1
cd "$T" &&
aunpack $A &&
cd `ls -1 .` &&
nix-build $MY_NIX_ROOT/nixpkgs --run-env -A "$1"
echo "Deleting $T" >&2
rm -rf "$T"
}
help() {
cat $MY_ESRC | sed -n 's/^\([a-zA-Z0-9]\+\)(.*#\(.*\)/\1\t\t\2/g p'
}
alias nix-env="nix-env -f '<nixpkgs>'"
if test -n "$MY_SET_PS1" ; then
SC="\e[1;32m"
SC2="\e[0;31m"
EC="\e[0m"
export PS1="\n$SC[\u@\h] $SC2(nix)$SC \w \$ $EC"
fi
###end-of-rc###
rc=`mktemp`
(
cat $HOME/.bashrc
printf "export SHELL=%s\n" $SHELL
printf "export MY_ESRC=%s\n" $rc
printf "export MY_SET_PS1=y\n"
cat $0 | sed -n '/#!\/bin\/sh/,/###end-of-rc###/p'
) >$rc
case $1 in
screen) screen -s $0 ;;
*) bash --rcfile $rc "$@" ;;
esac
rm $rc