diff options
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap/01_activate | 2 | ||||
-rwxr-xr-x | bootstrap/01_install | 33 | ||||
-rwxr-xr-x | bootstrap/02_setup | 29 | ||||
-rwxr-xr-x | bootstrap/03_config_setup | 3 | ||||
-rwxr-xr-x | bootstrap/99_ensure_config_variables | 41 | ||||
-rw-r--r-- | bootstrap/default.nix | 21 |
6 files changed, 77 insertions, 52 deletions
diff --git a/bootstrap/01_activate b/bootstrap/01_activate index b5195d3c..b46e9145 100755 --- a/bootstrap/01_activate +++ b/bootstrap/01_activate @@ -5,7 +5,7 @@ SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH . %SCRIPT_ENSURE_CONFIG_VARIABLES -nix run github:nix-community/disko -- --flake "git+https://codeberg.org/soispha/nixos-config#$NIX_HOST" --mode mount +nix run github:nix-community/disko -- --flake "git+https://codeberg.org/soispha/nixos-config#$NIX_HOST" --mode mount --experimental-features 'nix-command flakes'; msg "Finished mounting" diff --git a/bootstrap/01_install b/bootstrap/01_install index 5a3acc2d..2c8fa108 100755 --- a/bootstrap/01_install +++ b/bootstrap/01_install @@ -5,8 +5,24 @@ SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH INSTALL=y . %SCRIPT_ENSURE_CONFIG_VARIABLES -msg "started creating filesystem..." -nix run github:nix-community/disko -- --flake "git+https://codeberg.org/soispha/nixos-config#$NIX_HOST" --mode disko +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 -- --flake "git+https://codeberg.org/soispha/nixos-config#$NIX_HOST" --mode disko --experimental-features 'nix-command flakes'; msg "Finished mounting and generating btrfs subvolumes" msg "Creating swapfile..." @@ -16,8 +32,6 @@ 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)"; -msg2 "Root-disk UUID is: $(lsblk -no UUID -T $DISK_ROOT)"; -msg2 "EFI-disk UUID is: $(lsblk -no UUID -T $DISK_EFI)"; warning "This information needs to be entered in the host configuration BEFORE rebuilding it. Otherwise the system won't boot!" info_applied=false; @@ -34,7 +48,7 @@ while [ "$info_applied" = false ];do done msg "Checking for incompatibilities..." -ssd_or_hdd=$(cat /sys/block/$disk/queue/rotational); +ssd_or_hdd="$(cat /sys/block/"$(basename "$(readlink -f "$NIX_DISK")" | tr -d '\n')"/queue/rotational)"; case "$ssd_or_hdd" in 0) msg2 "You seem to use a ssd." @@ -44,7 +58,7 @@ case "$ssd_or_hdd" in msg2 "Yay, your ssd supports trim, go on and activate it"; ;; "false") - msg2 "Nay, your ssd doesn't support trim, go on"; + msg2 "Nay, your ssd doesn't support trim"; ;; *) warning "Your ssd doesn't seem to exists, if this bothers you please open an issue.'"; @@ -60,13 +74,10 @@ case "$ssd_or_hdd" in esac -readp "Do you want to continue with nixos-install? [N/y]: " result -case $result in - [Yy]) +case "$INSTALL_TO_SETUP" in + "yes") nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes'; ;; *) - msg "Sure, do it yourself" - exit 1 ;; esac diff --git a/bootstrap/02_setup b/bootstrap/02_setup index a9e534ab..68affe85 100755 --- a/bootstrap/02_setup +++ b/bootstrap/02_setup @@ -2,28 +2,10 @@ # shellcheck source=/dev/null SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH -msg "Select a host-config:" -hosts=$(mktmp); -host=""; -curl https://codeberg.org/soispha/nixos-config/raw/branch/prime/flake/nixosConfigurations/default.nix 2> /dev/null | awk -F '"' '/hosts = /{for (i=2;i<NF;i+=2) {print $i}}' > "$hosts"; +. %SCRIPT_ENSURE_CONFIG_VARIABLES -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://codeberg.org/soispha/nixos-config#${host} --no-root-passwd +nixos-install --flake git+https://codeberg.org/soispha/nixos-config#"$NIX_HOST" --no-root-passwd # clone the git config git clone https://codeberg.org/soispha/nixos-config.git /mnt/srv/etc/nixos @@ -33,13 +15,10 @@ mkdir --parents /mnt/srv/home chown 1000:100 --recursive /mnt/srv/home chmod 700 /mnt/srv/home -readp "Do you want to continue with the user configuration setup?[N/y]: " result; -case "$result" in - [yY]) +case "$SETUP_TO_CONFIG_SETUP" in + "yes") nix run "git+https://codeberg.org/soispha/nixos-config#config_setup" --experimental-features 'nix-command flakes'; ;; *) - msg "Well, if you want to do everything yourself..." - exit 1 ;; esac diff --git a/bootstrap/03_config_setup b/bootstrap/03_config_setup index 577cb8eb..c3e7e07e 100755 --- a/bootstrap/03_config_setup +++ b/bootstrap/03_config_setup @@ -7,6 +7,7 @@ SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH # clone packer.nvim to the needed dir, for the nvim install to work git clone --depth 1 https://github.com/wbthomason/packer.nvim /mnt/srv/home/soispha/.local/share/nvim/site/pack/packer/start/packer.nvim -nvim -c 'PackerSync' -c 'qall' -u '/mnt/srv/home/soispha/.config/nvim/init.lua' --headless +nixos-enter --command 'nvim -c "PackerSync" -c "qall" -u "/mnt/srv/home/soispha/.config/nvim/init.lua" --headless' + # vim: ft=sh diff --git a/bootstrap/99_ensure_config_variables b/bootstrap/99_ensure_config_variables index 6758b221..89961150 100755 --- a/bootstrap/99_ensure_config_variables +++ b/bootstrap/99_ensure_config_variables @@ -1,13 +1,12 @@ #! /usr/bin/env dash # shellcheck source=/dev/null -#SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH -SHELL_LIBRARY_VERSION="1.1.4" . /nix/store/m5vww39n11768whvhww00zrgkd3ry0q9-shell_library-v1.1.4/include/lib.sh +SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH if ! [ "$NIX_HOST" ]; then msg "Select a host:" _hosts=$(mktmp) - curl https://codeberg.org/soispha/nixos-config/raw/branch/prime/flake/nixosConfigurations/default.nix 2> /dev/null | awk -F '"' '/hosts = /{for (i=2;i<NF;i+=2) {print $i}}' > "$_hosts" + curl https://codeberg.org/soispha/nixos-config/raw/branch/prime/flake/nixosConfigurations/default.nix 2>/dev/null | awk -F '"' '/hosts = /{for (i=2;i<NF;i+=2) {print $i}}' > "$_hosts" while ! grep "$host" "$_hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do i=1 @@ -62,7 +61,19 @@ if ! [ "$NIX_DISK" ] && [ "$NIX_INSTALL" ]; then [Yy]) msg "Great, continuing..." _disk="$(jq '.item' "$_disk" | tr -d "\"")" - export NIX_DISK="$_disk" + _disk_serial="$(udevadm info --query=all --name="$_disk" | grep ID_SERIAL= | awk 'BEGIN{FS="="}{print $2}')"; + case "$_disk" in + "nvme*") + _nix_disk="nvme-$_disk_serial"; + ;; + "sd*") + _nix_disk="ata-$_disk_serial"; + ;; + *) + die "Disk with name '$_disk' and serial '$_disk_serial' not yet supported!" + ;; + esac + export NIX_DISK="$_nix_disk" ;; *) msg "Sure, keep your data" @@ -82,5 +93,27 @@ if ! [ "$ACTIVATE_TO_SETUP" ] && ! [ "$INSTALL" ]; then ;; esac fi +if ! [ "$INSTALL_TO_SETUP" ] && [ "$INSTALL" ]; then + readp "Do you want to continue with nixos-install after disk formatting? [N/y]: " result + case $result in + [Yy]) + export INSTALL_TO_SETUP=yes; + ;; + *) + export INSTALL_TO_SETUP=no; + ;; + esac +fi +if ! [ "$SETUP_TO_CONFIG_SETUP" ]; then + readp "Do you want to continue with the user configuration setup after setup? [N/y]: " result; + case $result in + [Yy]) + export SETUP_TO_CONFIG_SETUP=yes; + ;; + *) + export SETUP_TO_CONFIG_SETUP=no; + ;; + esac +fi # vim: ft=sh diff --git a/bootstrap/default.nix b/bootstrap/default.nix index 60c72e6a..f21fabe3 100644 --- a/bootstrap/default.nix +++ b/bootstrap/default.nix @@ -3,34 +3,35 @@ sysLib, ... }: let + replacementStrings = {SCRIPT_ENSURE_CONFIG_VARIABLES = "${ensure_config_variables}/bin/ensure_config_variables";}; activate = sysLib.writeShellScriptWithLibrary { dependencies = builtins.attrValues {inherit (pkgs) jq gawk curl coreutils libuuid nix git;}; name = "activate"; - src = ./01_activate.sh; - replacementStrings = {SCRIPT_ENSURE_CONFIG_VARIABLES = "${ensure_config_variables}";}; + src = ./01_activate; + inherit replacementStrings; }; install = sysLib.writeShellScriptWithLibrary { dependencies = builtins.attrValues {inherit (pkgs) jq dash curl gawk btrfs-progs coreutils libuuid gptfdisk dosfstools toybox nix git;}; name = "install"; - src = ./01_install.sh; - replacementStrings = {SCRIPT_ENSURE_CONFIG_VARIABLES = "${ensure_config_variables}";}; + src = ./01_install; + inherit replacementStrings; }; setup = sysLib.writeShellScriptWithLibrary { dependencies = builtins.attrValues {inherit (pkgs) dash gawk curl git nix gnugrep nixos-install-tools coreutils libuuid;}; name = "setup"; - src = ./02_setup.sh; - replacementStrings = {SCRIPT_ENSURE_CONFIG_VARIABLES = "${ensure_config_variables}";}; + src = ./02_setup; + inherit replacementStrings; }; config_setup = sysLib.writeShellScriptWithLibrary { dependencies = builtins.attrValues {inherit (pkgs) git neovim;}; name = "config_setup"; - src = ./03_config_setup.sh; - replacementStrings = {SCRIPT_ENSURE_CONFIG_VARIABLES = "${ensure_config_variables}";}; + src = ./03_config_setup; + inherit replacementStrings; }; ensure_config_variables = sysLib.writeShellScriptWithLibrary { - dependencies = builtins.attrValues {inherit (pkgs) jq dash;}; + dependencies = builtins.attrValues {inherit (pkgs) jq dash gnugrep curl;}; name = "ensure_config_variables"; - src = ./99_ensure_config_variables.sh; + src = ./99_ensure_config_variables; }; output = {inherit activate install setup config_setup ensure_config_variables;}; in |