-
Notifications
You must be signed in to change notification settings - Fork 2
/
nixez.sh
93 lines (88 loc) · 2.63 KB
/
nixez.sh
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
#!/usr/bin/env bash
# Better Nix UI
# Usage: source ./nixez.sh
function docker-load-nix() {
if grep -q -s Microsoft /proc/version; then
DIR=$(pwd | sed 's|/mnt/\(.\)|\1:|' | sed 's|/|\\|g')
else
DIR=$(pwd)
fi
IMAGE=$(docker load < result | awk '{print $3}')
if [[ $1 == "interactive" ]]; then
ARGS="-ti --rm"
else
ARGS=""
fi
# docker run $ARGS -v "$DIR:/data" "$IMAGE"
}
function nixez() {
case $1 in
shell) nix-shell ;;
search) nix-env -qaP ".*$2.*" ;;
install) nix-env -f "$(pwd)" -iA "$2" ;;
remove) nix-env -e "$2" ;;
list) nix-env -q;;
build) nix-build "$(pwd)" -A "$2" ;;
nodejs)
cd pkgs/development/node-packages
node2nix -6 -i node-packages-v6.json -o node-packages-v6.nix -c composition-v6.nix
cd ../../..
;;
docker)
if [ "$(uname)" == "Darwin" ]; then
sudo $(cat ~/.nixpkgs/linuxkit-builder/env) \
NIX_PATH="nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs" \
nix-build "$(pwd)" -A dockerTar --argstr pkg "$2" \
--argstr timestamp $(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--argstr system "x86_64-linux"
else
nix-build "$(pwd)" -A dockerTar --argstr pkg "$2" \
--argstr timestamp $(date -u +"%Y-%m-%dT%H:%M:%SZ")
fi
if [ -t 0 ]; then
docker-load-nix interactive
else
docker-load-nix
fi
;;
docker-push)
nix-build "$(pwd)" -A dockerTar --argstr pkg "$2" &&
docker-load-nix
;;
singularity)
nix-build "$(pwd)" -A dockerTar --argstr pkg "$2" &&
docker-load-nix &&
NAME=$(docker ps -l --format "{{.Image}}" | sed 's|:|_|')
docker export "$(docker ps -lq)" | gzip > "$NAME.tar.gz"
;;
setup)
read -r -p "This will install Nix, are you sure? [y/N]" response
case "$response" in
[yY][eE][sS]|[yY])
curl -o install-nix-1.11.15 https://nixos.org/nix/install
curl -o install-nix-1.11.15.sig https://nixos.org/nix/install.sig
gpg --recv-keys B541D55301270E0BCF15CA5D8170B4726D7198DE
gpg --verify ./install-nix-1.11.15.sig && sh ./install-nix-1.11.15
;;
*)
echo "Canceled"
;;
esac
;;
unsafe-setup)
read -r -p "This will install Nix without checking signature, are you sure? [y/N]" response
case "$response" in
[yY][eE][sS]|[yY])
curl https://nixos.org/nix/install | sh
;;
*)
echo "Canceled"
;;
esac
;;
repair)
nix-store --verify --check-contents
;;
* ) echo "Options: shell, search, install, remove, list, build, docker, singularity" ;;
esac
}