-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
116 lines (83 loc) · 2.83 KB
/
install.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
set -e
if [[ $EUID > 0 ]]
then
echo "please run as root"
exit
fi
RESET="\033[0m"
RED="\033[31m"
BLUE="\033[36m"
function err {
echo -e "${RED}$1${RESET}"
}
function info {
echo -e "${BLUE}$1${RESET}"
}
clear
info "Installing dependencies..."
nix-env -iA nixos.wget
nix-env -iA nixos.zfs
wget -qO- https://github.com/charmbracelet/gum/releases/download/v0.1.0/gum_0.1.0_linux_x86_64.tar.gz | tar xz -C /tmp gum
alias gum='/tmp/gum'
info "Evaluating flake..."
FLAKE=$(nix flake show . --json --extra-experimental-features "nix-command flakes")
info "Select which NixOS system to install"
SYSTEM=$(echo $FLAKE | grep -Po '\w*(?=":{"type":"nixos-configuration"})' | gum choose)
echo $SYSTEM
info "Select the device to install system"
DEVICE=$(lsblk -o name,size,type,mountpoints,label -p -n -d | gum filter | cut -d ' ' -f1)
if [ "$DEVICE" = "" ]
then
echo "invalid device"
exit
fi
echo $DEVICE
info "Choose the size of the swap partition in GiB"
SWAP=$(gum input --value=8 --placeholder "")
[ -n "$SWAP" ] && [ "$SWAP" -eq "$SWAP" ] 2>/dev/null
if [ $? -ne 0 ]; then
echo "invalid number"
exit
fi
echo ${SWAP}GiB
gum confirm "WARNING: This will wipe all data from $DEVICE. Continue?"
info "Partitioning..."
wipefs $DEVICE -a -f
parted $DEVICE -s -- mklabel gpt
parted $DEVICE -s -- mkpart primary 512MiB -${SWAP}GiB
parted $DEVICE -s -- mkpart primary linux-swap -${SWAP}GiB 100%
parted $DEVICE -s -- mkpart ESP fat32 1MiB 512MiB
parted $DEVICE -s -- set 3 esp on
info "Formatting..."
# zfs pool
zpool create -f nixos ${DEVICE}1
zfs set compression=on nixos
zfs create -p -o mountpoint=legacy nixos/local/root
zfs set xattr=sa nixos/local/root
zfs set acltype=posixacl nixos/local/root
zfs snapshot nixos/local/root@blank
zfs create -p -o mountpoint=legacy nixos/local/nix
zfs set atime=off nixos/local/nix
zfs create -p -o mountpoint=legacy nixos/safe/data
zfs create -p -o mountpoint=legacy nixos/safe/persist
# other
mkswap -L swap ${DEVICE}2
mkfs.fat -F 32 -n boot ${DEVICE}3
info "Mounting..."
mount -t zfs nixos/local/root /mnt
mkdir -p /mnt/boot
mount -t vfat /dev/disk/by-label/boot /mnt/boot
mkdir -p /mnt/nix
mount -t zfs nixos/local/nix /mnt/nix
mkdir -p /mnt/data
mount -t zfs nixos/safe/data /mnt/data
mkdir -p /mnt/persist
mount -t zfs nixos/safe/persist /mnt/persist
swapon /dev/disk/by-label/swap
info "Installing..."
mkdir /mnt/persist/root
nixos-install --flake .\#$SYSTEM --no-root-passwd
info "Running post-install scripts..."
nixos-enter -c 'postinstall'
systemctl reboot