blob: a9e6f99ae2c854fb6727c538f693401dfd72752a (
plain) (
blame)
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
|
#! /usr/bin/env dash
# shellcheck disable=SC2086
# shellcheck source=/dev/null
. %SHELL_LIBRARY_PATH
export LIB_TEMP_DIR_FOR_SCRIPT="$(mktemp -d)"
mne() {
mount --mkdir --options compress-force=zstd:15,subvol="$1" $DISK_ROOT "$2" || dien "Mounting of $1";
}
available_disks="$(mktmp)";
lsblk -J | jq '.[] | map(.name) | [foreach .[] as $item ({item: null, index: -1}; {$item, index: (.index + 1)})]' > $available_disks;
[ "$(jq '.[]' "$available_disks" | wc -l)" -eq 0 ] && die "No disks found"
msg "Select where your system is installed:\n"
i=9999; # nobody will have so many disks attached
while ! jq -e --argjson i "$i" '.[$i]' "$available_disks" > /dev/null 2>&1; do
for disk in $(jq -c '.[]' "$available_disks" ); do
printf "%4s) %s \n" "$(echo "$disk" | jq '.index')" "$(echo "$disk" | jq '.item' | tr -d "\"")";
done
printf "%4s) Exit\n" "q"
readp "Enter a option: " disk
if [ $disk = "q" ];then
exit 1
else
i="$disk"
fi
if jq -e --argjson i "$i" 'nth($i)' "$available_disks" > /dev/null 2>&1; then
disk="$(jq -e --argjson i "$i" 'nth($i) | .item' "$available_disks" | tr -d "\"")";
else
warning "No disk selected. Select a disk to continue.\n"
fi
done
case "$disk" in
"nvme"*)
export DISK_EFI="/dev/${disk}"p1
export DISK_ROOT="/dev/${disk}"p2
;;
"sd"* |"vd"*)
export DISK_EFI="/dev/${disk}"1
export DISK_ROOT="/dev/${disk}"2
;;
*)
die "The disk type: ${disk} is not yet supported!"
;;
esac
msg "Mounting..."
# TODO umount -R /mnt
mount -t tmpfs none /mnt
mount --mkdir "$DISK_EFI" /mnt/boot
mne nix-store /mnt/nix
mne persistent-storage /mnt/srv
mount --mkdir --options bind /mnt/srv/nixos-config /mnt/etc/nixos
msg "Finished mounting"
readp "Do you want to continue with nixos-install? [N/y]: " result
case $result in
[Yy])
msg "Great, select a host-config:"
hosts=$(mktmp);
host="";
awk -F "." '/nixosConfiguration/{print $2}' "$(tmp 'curl https://git.sils.li/ene/nixos-config/raw/branch/prime/flake.nix 2> /dev/null')" | awk '{print $1}' > $hosts;
while ! grep "$host" "$hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do
i=1;
while read -r ho ; do
printf "%4s) %s \n" "$i" "$ho";
i=$((i+1));
done < "$hosts"
printf "%4s) Exit\n" "q"
readp "Enter a option: " host
[ "$host" = "q" ] && exit 1
host=$(awk -v i="$host" '{if (NR==i) {print $0}}' "$hosts");
if ! grep "$host" "$hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; then
warning "No host selected. Select a host to continue.\n"
fi
done
nixos-install --flake git+https://git.sils.li/ene/nixos-config#${host} --no-root-passwd
;;
*)
msg "Sure, do it yourself"
exit 1
;;
esac
if [ -d "$LIB_TEMP_DIR_FOR_SCRIPT" ];then rm -r "$LIB_TEMP_DIR_FOR_SCRIPT"; fi
|