This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathdisko.sh
70 lines (64 loc) · 2.37 KB
/
disko.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
set -e
common_dir="$FLAKE_ROOT/hosts/laptop/disko_layout"
function ask {
while true; do
echo -n "Would you like to edit this layout? (y/n): "
read choice
if [ "$choice" = "y" ]; then
nvim $partition_layout
break
elif [ "$choice" = "n" ]; then
break
else
echo "Invalid input, please try again."
fi
done
}
# Select the disk partition layout and edit it
while true; do
echo "Please select a disk partition layout:"
echo "1. single-device"
echo "2. single-device-luks"
echo "3. multi-device"
echo "4. multi-device-luks"
read -p $'\e[1;32mEnter your choice(number): \e[0m' choice
case $choice in
1)
partition_layout="$common_dir/single-device.nix";
ask;
break ;;
2)
partition_layout="$common_dir/single-device-luks.nix";
ask;
#to set luks password
read -p $'\e[1;31mEnter LUKS password (important!): \e[0m' -r luks_pass
echo -n "$luks_pass" > /tmp/secret.key
break ;;
3)
partition_layout="$common_dir/multi-device.nix";
ask;
break ;;
4)
partition_layout="$common_dir/multi-device-luks.nix";
ask;
#to set luks password
read -p $'\e[1;31mEnter LUKS password (important!): \e[0m' -r luks_pass
echo -n "$luks_pass" > /tmp/secret.key
break ;;
*)
echo "Invalid choice, please try again."
;;
esac
done
nix --extra-experimental-features nix-command --extra-experimental-features flakes run github:nix-community/disko -- --mode zap_create_mount "$partition_layout"
mkdir -p /mnt/etc/nixos
mkdir -p /mnt/nix/persist/etc/nixos
mount -o bind /mnt/nix/persist/etc/nixos /mnt/etc/nixos
nixos-generate-config --no-filesystems --root /mnt
cd /mnt/etc/nixos
cp hardware-configuration.nix "$FLAKE_ROOT"/hosts/laptop/hardware-configuration.nix && cp hardware-configuration.nix "$FLAKE_ROOT"/hosts/laptop_minimal/hardware-configuration.nix
# To truncate characters, simplify the following sed command
layout=.${partition_layout#$FLAKE_ROOT/hosts/laptop}
sed -i "/imports\ =/cimports\ = [(import\ $layout\ {})]++" "$FLAKE_ROOT"/hosts/{laptop,laptop_minimal}/hardware-configuration.nix
cp -r "$FLAKE_ROOT" /mnt/etc/nixos
lsblk