added steps to the installation script so if it is interrupted, you dont have to restart

This commit is contained in:
pagedmov
2024-10-18 07:00:42 -04:00
parent ca3c8a9b2e
commit d7db940262
4 changed files with 165 additions and 123 deletions

View File

@@ -14,12 +14,12 @@
boot.extraModulePackages = [ ]; boot.extraModulePackages = [ ];
fileSystems."/" = fileSystems."/" =
{ device = "/dev/disk/by-uuid/91413e4e-538c-4266-8a4d-bf60ec83e7b9"; { device = "/dev/disk/by-partlabel/disk-main-root";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/nix" = fileSystems."/nix" =
{ device = "/dev/disk/by-uuid/aad759e2-6c39-4350-89b9-07f2bc6eb3cc"; { device = "/dev/disk/by-partlabel/disk-main-ESP";
fsType = "ext4"; fsType = "ext4";
}; };

View File

@@ -35,7 +35,7 @@
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";
mountpoint = "/home"; mountpoint = "/nix";
}; };
}; };
root = { root = {

View File

@@ -1,141 +1,167 @@
#!/run/current-system/sw/bin/bash #!/run/current-system/sw/bin/bash
echo "Welcome. This script will install pagedMov's NixOS configuration flake onto your machine."
echo "If this script stops at any point, it will resume from the most recent major step when you call it again."
echo "Call the script with --reset to restart the installation process"
set -e set -e
trap 'echo "Aborting installation."; exit 1' INT trap 'echo "Aborting installation."; exit 1' INT
# set up working directory if [ "$1" = "--reset" ]; then
mkdir -p /tmp/install_pwd && cd /tmp/install_pwd rm -rf /tmp/reset
rm -rf ./* fi
# download disko.nix file for defining partitions if [ ! -f /tmp/install_steps ]; then
echo -n "Downloading partition plan..." echo "0" > /tmp/install_steps
curl -s https://raw.githubusercontent.com/pagedMov/pagedmov-nix-cfg/refs/heads/master/hosts/installer/disko-ext4-singledisk.nix > disko.nix fi
echo "Done!"
echo install_step=$(cat /tmp/install_steps)
echo "This script is about to format and partition a hard drive."
sleep 2.5
echo -e "\033[4;31mThis process is irreversible and will destroy all data on the drive.\033[0m"
sleep 2.5
echo "Make absolutely sure that you know which drive you are choosing."
sleep 2.5
echo
lsblk -d -o NAME,SIZE
echo
echo -n "Which drive do you wish to sacrifice? "
read -r drive
size=$(lsblk -b -d -o NAME,SIZE | grep "$drive" | awk '{ printf "%.0f\n", $2 / 1024 / 1024 / 1024 }') step_1() {
size=$((size-1)) # set up working directory
root_size_default=$(echo "scale=0;$size * 0.10 / 1" | bc) mkdir -p /tmp/install_pwd && cd /tmp/install_pwd
nix_size_default=$(echo "scale=0;$size * 0.35 / 1" | bc) rm -rf ./*
for part in "root" "nix"; do # download disko.nix file for defining partitions
echo "You have $size GB remaining to work with on this drive. How big do you want your $part partition?" echo -n "Downloading partition plan..."
curl -s https://raw.githubusercontent.com/pagedMov/pagedmov-nix-cfg/refs/heads/master/hosts/installer/disko-ext4-singledisk.nix > disko.nix
echo "Done!"
if [ "$part" = "root" ]; then echo
echo "Default value is 10% of hard drive space ($root_size_default GB)" echo "This script is about to format and partition a hard drive."
else sleep 2.5
echo "Default value is 35% of hard drive space ($nix_size_default GB)" echo -e "\033[4;31mThis process is irreversible and will destroy all data on the drive.\033[0m"
fi sleep 2.5
echo "Give a positive integer or leave blank to use default value" echo "Make absolutely sure that you know which drive you are choosing."
deciding=true sleep 2.5
echo
lsblk -d -o NAME,SIZE
echo
echo -n "Which drive do you wish to sacrifice? "
read -r drive
while $deciding; do size=$(lsblk -b -d -o NAME,SIZE | grep "$drive" | awk '{ printf "%.0f\n", $2 / 1024 / 1024 / 1024 }')
echo -n "> " size=$((size-1))
read -r size_choice root_size_default=$(echo "scale=0;$size * 0.10 / 1" | bc)
nix_size_default=$(echo "scale=0;$size * 0.35 / 1" | bc)
case "$size_choice" in echo
'') for part in "root" "nix"; do
deciding=false echo "You have $size GB remaining to work with on this drive. How big do you want your $part partition?"
;;
*[!0-9]*) # Matches non-numeric input if [ "$part" = "root" ]; then
echo "Invalid input. Please enter a valid positive number." echo "Default value is 10% of hard drive space ($root_size_default GB)"
else
echo "Default value is 35% of hard drive space ($nix_size_default GB)"
fi
echo "Give a positive integer or leave blank to use default value"
echo
deciding=true
while $deciding; do
echo -n "> "
read -r size_choice
case "$size_choice" in
'')
deciding=false
;; ;;
0) # Matches zero *[!0-9]*) # Matches non-numeric input
echo "Please enter a positive number greater than zero." echo "Invalid input. Please enter a valid positive number."
;; ;;
*) # Matches positive numbers 0) # Matches zero
if (( size_choice > size - 50 )); then echo "Please enter a positive number greater than zero."
echo "You need to leave more room for the other partitions." ;;
elif (( size_choice < 5 )); then *) # Matches positive numbers
echo "Partition size is too small." if (( size_choice > size - 50 )); then
else echo "You need to leave more room for the other partitions."
echo "Valid input: $size_choice" elif (( size_choice < 5 )); then
deciding=false # Exit the loop on valid input echo "Partition size is too small."
fi else
;; echo "Valid input: $size_choice"
esac deciding=false # Exit the loop on valid input
fi
;;
esac
done
case "$part" in
"root" )
if [ -z "$size_choice" ]; then root_size=$root_size_default; else root_size=$size_choice; fi
size=$((size - root_size))
;;
"nix" )
if [ -z "$size_choice" ]; then nix_size=$nix_size_default; else nix_size=$size_choice; fi
size=$((size - nix_size))
;;
esac
done done
case "$part" in echo
"root" ) echo "Final partition sizes:"
if [ -z "$size_choice" ]; then root_size=$root_size_default; else root_size=$size_choice; fi echo "root: $root_size GB"
size=$((size - root_size)) echo "nix: $nix_size GB"
;; echo "home: $size GB"
"nix" ) echo
if [ -z "$size_choice" ]; then nix_size=$nix_size_default; else nix_size=$size_choice; fi
size=$((size - nix_size))
;;
esac
done
echo "Final partition sizes:" sleep 1
echo "root: $root_size GB"
echo "nix: $nix_size GB"
echo "home: $size GB"
sleep 1 # commence formatting
echo "Commencing formatting/partitioning..." && sleep 0.5
nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/install_pwd/disko.nix --arg device "\"/dev/$drive\"" --arg root_size "\"$root_size\G\"" --arg nix_size "\"$nix_size\G\""
# commence formatting mount /dev/disk/by-partlabel/disk-main-root /mnt
echo "Commencing formatting/partitioning..." && sleep 0.5 mkdir -p /mnt/nix && mount /dev/disk/by-partlabel/disk-main-nix /mnt/nix
nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/install_pwd/disko.nix --arg device "\"/dev/$drive\"" --arg root_size "\"$root_size\G\"" --arg nix_size "\"$nix_size\G\"" mkdir -p /mnt/boot && mount /dev/disk/by-partlabel/disk-main-ESP /mnt/boot
mkdir -p /mnt/home && mount /dev/disk/by-partlabel/disk-main-home /mnt/home
}
mount /dev/disk/by-partlabel/disk-main-root /mnt step_2() {
mkdir -p /mnt/nix && mount /dev/disk/by-partlabel/disk-main-nix /mnt/nix mkdir -p /mnt/etc
mkdir -p /mnt/boot && mount /dev/disk/by-partlabel/disk-main-ESP /mnt/boot cd /mnt/etc/
mkdir -p /mnt/home && mount /dev/disk/by-partlabel/disk-main-home /mnt/home if [ ! -d ./nixos ]; then
git clone https://github.com/pagedMov/pagedmov-nix-cfg.git ./nixos
mkdir -p /mnt/etc echo
cd /mnt/etc/ echo "Do you want to install the light or heavy configuration?"
[ -d /mnt/etc/nixos ] && rm -rf /mnt/etc/nixos echo "Light configuration does not include gaming or virtualization features; intended for laptops, etc."
git clone https://github.com/pagedMov/pagedmov-nix-cfg.git ./nixos echo "Heavy config includes gaming and virtualization features; intended for performant desktop environments."
echo
select config in "Heavy" "Light" "Quit"; do
case $config in
"Heavy")
echo "Installing heavy configuration \`Oganesson\`"
config="oganesson"
sleep 0.5
break
;;
"Light")
echo "Installing light configuration \`Mercury\`"
config="mercury"
sleep 0.5
break
;;
"Quit")
echo "Exiting installation..."
sleep 0.5
exit 0
;;
*)
echo "Invalid option."
sleep 0.5
;;
esac
done
fi
echo "Do you want to install the light or heavy configuration?" nixos-install --root /mnt --flake /mnt/etc/nixos#"$config" --no-root-password
echo "Light configuration does not include gaming or virtualization features; intended for laptops, etc."
echo "Heavy config includes gaming and virtualization features; intended for performant desktop environments."
select config in "Heavy" "Light" "Quit"; do
case $config in
"Desktop")
echo "Installing heavy configuration \`Oganesson\`"
config="oganesson"
sleep 0.5
break
;;
"Laptop")
echo "Installing light configuration \`Mercury\`"
config="mercury"
sleep 0.5
break
;;
"Quit")
echo "Exiting installation..."
sleep 0.5
exit 0
;;
*)
echo "Invalid option."
sleep 0.5
;;
esac
done
nixos-install --root /mnt --flake /mnt/etc/nixos#"$config" --no-root-password echo
echo "Preliminary installation successful!"
echo echo "Beginning secondary installation phase..."
echo "Preliminary installation successful!" echo
echo "Adapting config to your setup..." }
echo
step_3() {
cp -r /mnt/etc/nixos /mnt/home/pagedmov/.sysflake cp -r /mnt/etc/nixos /mnt/home/pagedmov/.sysflake
rm -rf /mnt/etc/nixos rm -rf /mnt/etc/nixos
ln -s /mnt/home/pagedmov/.sysflake /etc/nixos ln -s /mnt/home/pagedmov/.sysflake /etc/nixos
@@ -150,3 +176,19 @@ echo "INSTALLATION COMPLETE ! !" | toilet -f 3d -w 120 | lolcat -a -s 180
echo "You can now reboot into your new system." echo "You can now reboot into your new system."
echo "The system configuration flake will be found in your home folder under .sysflake" echo "The system configuration flake will be found in your home folder under .sysflake"
echo "/etc/nixos is a symlink leading to the .sysflake folder" echo "/etc/nixos is a symlink leading to the .sysflake folder"
}
next_step() {
((install_step += 1))
echo $install_step > /tmp/install_steps
}
running=true
while $running; do
case $install_step in
0) step_1;next_step;;
1) step_2;next_step;;
2) step_3;next_step;;
3) step_4;next_step;;
esac
done

View File

@@ -14,23 +14,23 @@
boot.extraModulePackages = [ ]; boot.extraModulePackages = [ ];
fileSystems."/" = fileSystems."/" =
{ device = "/dev/disk/by-uuid/91413e4e-538c-4266-8a4d-bf60ec83e7b9"; { device = "/dev/disk/by-uuid/a843b14e-5e50-408d-9c23-c691c0efe46c";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/nix" = fileSystems."/nix" =
{ device = "/dev/disk/by-uuid/aad759e2-6c39-4350-89b9-07f2bc6eb3cc"; { device = "/dev/disk/by-uuid/fbf1f87a-5ed4-42bd-943d-67fae6e6537c";
fsType = "ext4"; fsType = "ext4";
}; };
fileSystems."/boot" = fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/F529-2C16"; { device = "/dev/disk/by-uuid/8BFD-57A2";
fsType = "vfat"; fsType = "vfat";
options = [ "fmask=0077" "dmask=0077" ]; options = [ "fmask=0077" "dmask=0077" ];
}; };
fileSystems."/home" = fileSystems."/home" =
{ device = "/dev/disk/by-uuid/7edc690b-7e30-49d7-afbe-78354d0f7497"; { device = "/dev/disk/by-uuid/1a3c99c8-5c61-4253-8812-16c5985489f0";
fsType = "ext4"; fsType = "ext4";
}; };