about summary refs log tree commit diff stats
path: root/bootstrap/01_install.sh
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-02-20 16:35:15 +0100
committerSoispha <soispha@vhack.eu>2024-02-20 16:35:15 +0100
commitcc09b607330385d6d81b9c47cf64a2442432e93f (patch)
treedc7e4503a3341b8936576c6339a70df4adaa2512 /bootstrap/01_install.sh
parentrefactor(hm/conf/zsh/config): Rework old config scripts (diff)
downloadnixos-config-cc09b607330385d6d81b9c47cf64a2442432e93f.tar.gz
nixos-config-cc09b607330385d6d81b9c47cf64a2442432e93f.zip
refactor(treewide): Add a `.sh` extension to shell scripts
Diffstat (limited to 'bootstrap/01_install.sh')
-rwxr-xr-xbootstrap/01_install.sh81
1 files changed, 81 insertions, 0 deletions
diff --git a/bootstrap/01_install.sh b/bootstrap/01_install.sh
new file mode 100755
index 00000000..e4581b6d
--- /dev/null
+++ b/bootstrap/01_install.sh
@@ -0,0 +1,81 @@
+#! /usr/bin/env dash
+
+# shellcheck source=/dev/null
+SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH
+
+INSTALL=y . %SCRIPT_ENSURE_CONFIG_VARIABLES
+
+msg "Important information:"
+msg2 "Choose disk id is: $NIX_DISK"
+warning "This information needs to be entered in the host configuration BEFORE rebuilding it. Otherwise you'll have to wait for a 1 h cooldown!"
+info_applied=false
+while [ "$info_applied" = false ]; do
+    readp "Have you updated your chosen host with the choose disk id? [N/y]: " result
+    case $result in
+        [Yy])
+            info_applied=true
+            ;;
+        *)
+            warning "You won't be able to boot, if you don't update it!"
+            ;;
+    esac
+done
+
+msg "Started creating filesystem..."
+nix run github:nix-community/disko --experimental-features 'nix-command flakes' -- --flake "git+https://codeberg.org/soispha/nixos-config#$NIX_HOST" --mode disko
+msg "Finished mounting and generating btrfs subvolumes"
+
+msg "Creating swapfile..."
+msg2 "$(btrfs filesystem mkswapfile --size "$(free -m | awk '{if (NR==2) {printf "%sm\n", $2 + 500}}')" /mnt/swap/swapfile)"
+msg "Finished creating swapfile!"
+
+msg "Important information:"
+msg2 "Swapfile UUID is: $(findmnt -no UUID -T /mnt/swap/swapfile)"
+msg2 "Swapfile resume offset is: $(btrfs inspect-internal map-swapfile -r /mnt/swap/swapfile)"
+warning "This information needs to be entered in the host configuration BEFORE rebuilding it. Otherwise the system won't boot!"
+
+info_applied=false
+while [ "$info_applied" = false ]; do
+    readp "Have you updated your chosen host with this information? [N/y]: " result
+    case $result in
+        [Yy])
+            info_applied=true
+            ;;
+        *)
+            warning "You won't be able to boot, if you don't update it!"
+            ;;
+    esac
+done
+
+msg "Checking for incompatibilities..."
+ssd_or_hdd="$(cat /sys/block/"$(basename "$(readlink -f "/dev/disk/by-id/$NIX_DISK")" | tr -d '\n')"/queue/rotational)"
+case "$ssd_or_hdd" in
+    0)
+        msg2 "You seem to use a ssd."
+        trim_support=$(lsblk --bytes --json --discard | jq --arg name "$(basename "$(readlink -f "/dev/disk/by-id/$NIX_DISK")" | tr -d '\n')" '.blockdevices | .[] | select(.name == $name) | (.["disc-gran"] + .["disc-max"]) != 0')
+        case $trim_support in
+            "true")
+                msg2 "Yay, your ssd supports trim, go on and activate it"
+                ;;
+            "false")
+                msg2 "Nay, your ssd doesn't support trim"
+                ;;
+            *)
+                warning "Your ssd doesn't seem to exists, if this bothers you please open an issue."
+                ;;
+        esac
+        ;;
+    1)
+        msg2 "You seem to use a hdd there is nothing you have to do"
+        ;;
+    *)
+        warning "There is no indicator, which shows, which drive your are using.\n This means, that you have to check yourself, which optimizations you should activate."
+        ;;
+esac
+
+case "$INSTALL_TO_SETUP" in
+    "yes")
+        nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes'
+        ;;
+    *) ;;
+esac