-
Notifications
You must be signed in to change notification settings - Fork 0
/
conf
executable file
·64 lines (62 loc) · 1.99 KB
/
conf
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
#!/usr/bin/env bash
if ! [ -e deploy_key ] || ! [ -e secrets.nix ]
then
git crypt unlock
sudo chgrp nixbld deploy_key
chmod 640 deploy_key
fi
export NIX_PATH="ssh-id-file=$PWD/deploy_key":secrets=$PWD/secrets.nix:yori-nix=$PWD
function get_channel {
case $1 in
git)
echo "nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz"
;;
stable)
echo "nixpkgs=https://nixos.org/channels/nixos-18.03/nixexprs.tar.xz"
;;
checkout)
echo "nixpkgs=$PWD/../nixpkgs"
;;
channel)
echo "/nix/var/nix/profiles/per-user/root/channels/nixos"
;;
esac
}
case $1 in
cloc)
exec cloc --read-lang-def=deploy/nix_cloc .
;;
copy-keys)
$0 exec "$2" nix build -f "\\<nixpkgs/nixos\\>" config.deployment.keys-copy --out-link copy-keys
TARGET_HOST=$(jq -r ".$2.host"<servers.json)
./copy-keys/bin/copy-keys "$TARGET_HOST"
# rm ./copy-keys
;;
exec)
CHANNEL=$(jq -r ".$2.pkgs"<servers.json)
export NIX_PATH="$(get_channel "$CHANNEL"):nixos-config=$PWD/logical/$2.nix:$NIX_PATH"
eval "${@:3}"
;;
ssh)
TARGET_HOST=$(jq -r ".$2.host"<servers.json)
ssh root@"$TARGET_HOST"
;;
repl)
exec "$0" exec "$2" nix repl "\\<nixpkgs\\>" "\\<nixpkgs/nixos\\>"
;;
build)
exec "$0" exec "$2" nixos-rebuild build
;;
copy)
TARGET_HOST=$(jq -r ".$2.host"<servers.json)
exec "$0" exec "$2" nixos-rebuild build --build-host localhost --target-host root@"$TARGET_HOST"
;;
boot)
TARGET_HOST=$(jq -r ".$2.host"<servers.json)
exec "$0" exec "$2" nixos-rebuild --build-host localhost --target-host root@"$TARGET_HOST" boot
;;
switch)
TARGET_HOST=$(jq -r ".$2.host"<servers.json)
exec "$0" exec "$2" nixos-rebuild --build-host localhost --target-host root@"$TARGET_HOST" switch
;;
esac