diff options
-rwxr-xr-x | bootstrap/01_activate | 20 | ||||
-rwxr-xr-x | bootstrap/01_install | 72 | ||||
-rwxr-xr-x | bootstrap/02_setup (renamed from bootstrap/setup/setup.sh) | 0 | ||||
-rwxr-xr-x | bootstrap/03_config_setup (renamed from bootstrap/config_setup/config_setup.sh) | 0 | ||||
-rwxr-xr-x | bootstrap/99_ensure_config_variables | 86 | ||||
-rwxr-xr-x | bootstrap/activate/activate.sh | 75 | ||||
-rw-r--r-- | bootstrap/activate/default.nix | 11 | ||||
-rw-r--r-- | bootstrap/config_setup/default.nix | 11 | ||||
-rw-r--r-- | bootstrap/default.nix | 39 | ||||
-rw-r--r-- | bootstrap/install/default.nix | 11 | ||||
-rwxr-xr-x | bootstrap/install/install.sh | 158 | ||||
-rw-r--r-- | bootstrap/setup/default.nix | 11 | ||||
-rw-r--r-- | flake/default.nix | 1 | ||||
-rw-r--r-- | flake/packages/default.nix | 49 |
14 files changed, 232 insertions, 312 deletions
diff --git a/bootstrap/01_activate b/bootstrap/01_activate new file mode 100755 index 00000000..b5195d3c --- /dev/null +++ b/bootstrap/01_activate @@ -0,0 +1,20 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +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 + +msg "Finished mounting" + +case "$ACTIVATE_TO_SETUP" in + "yes") + nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes'; + ;; + *) + ;; +esac + +# vim: ft=sh diff --git a/bootstrap/01_install b/bootstrap/01_install new file mode 100755 index 00000000..5a3acc2d --- /dev/null +++ b/bootstrap/01_install @@ -0,0 +1,72 @@ +#! /usr/bin/env dash + +# shellcheck source=/dev/null +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 "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)"; +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; +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/$disk/queue/rotational); +case "$ssd_or_hdd" in + 0) + msg2 "You seem to use a ssd." + trim_support=$(lsblk --bytes --json --discard | jq --arg name "$disk" '.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, go on"; + ;; + *) + 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 + + +readp "Do you want to continue with nixos-install? [N/y]: " result +case $result in + [Yy]) + 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/setup/setup.sh b/bootstrap/02_setup index a9e534ab..a9e534ab 100755 --- a/bootstrap/setup/setup.sh +++ b/bootstrap/02_setup diff --git a/bootstrap/config_setup/config_setup.sh b/bootstrap/03_config_setup index 577cb8eb..577cb8eb 100755 --- a/bootstrap/config_setup/config_setup.sh +++ b/bootstrap/03_config_setup diff --git a/bootstrap/99_ensure_config_variables b/bootstrap/99_ensure_config_variables new file mode 100755 index 00000000..6758b221 --- /dev/null +++ b/bootstrap/99_ensure_config_variables @@ -0,0 +1,86 @@ +#! /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 + +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" + + while ! grep "$host" "$_hosts" > /dev/null || [ "$(printf "%s" "$host" | wc -c)" -eq 0 ]; do + i=1 + while read -r host_read; do + printf "%4s) %s \n" "$i" "$host_read" + 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 + + export NIX_HOST="$host" +fi +if ! [ "$NIX_DISK" ] && [ "$NIX_INSTALL" ]; then + 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 a disk to format:" + + 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=$(mktmp) + jq -e --argjson i "$i" 'nth($i)' "$available_disks" > "$_disk" + else + warning "No disk selected. Select a disk to continue.\n" + fi + done + + warn "All data on disk $(jq '.item' "$_disk") will be deleted." + readp "Continue with this disk? [N/y]: " result + case "$result" in + [Yy]) + msg "Great, continuing..." + _disk="$(jq '.item' "$_disk" | tr -d "\"")" + export NIX_DISK="$_disk" + ;; + *) + msg "Sure, keep your data" + exit 1 + ;; + esac +fi + +if ! [ "$ACTIVATE_TO_SETUP" ] && ! [ "$INSTALL" ]; then + readp "Do you want to continue with nixos-install after activation? [N/y]: " result + case $result in + [Yy]) + export ACTIVATE_TO_SETUP=yes; + ;; + *) + export ACTIVATE_TO_SETUP=no; + ;; + esac +fi + +# vim: ft=sh diff --git a/bootstrap/activate/activate.sh b/bootstrap/activate/activate.sh deleted file mode 100755 index 0c3589c5..00000000 --- a/bootstrap/activate/activate.sh +++ /dev/null @@ -1,75 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH - -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]) - nix run "git+https://codeberg.org/soispha/nixos-config#setup" --experimental-features 'nix-command flakes'; - ;; - *) - msg "Sure, do it yourself" - exit 1 - ;; -esac - -# vim: ft=sh diff --git a/bootstrap/activate/default.nix b/bootstrap/activate/default.nix deleted file mode 100644 index abada12c..00000000 --- a/bootstrap/activate/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -# vim: ts=2 -{ - pkgs, - sysLib, - ... -}: let - dependencies = builtins.attrValues {inherit (pkgs) jq gawk curl coreutils libuuid nix git;}; - name = "activate"; - src = ./activate.sh; -in - sysLib.writeShellScriptWithLibrary {inherit dependencies name src;} diff --git a/bootstrap/config_setup/default.nix b/bootstrap/config_setup/default.nix deleted file mode 100644 index 4cae8424..00000000 --- a/bootstrap/config_setup/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -# vim: ts=2 -{ - pkgs, - sysLib, - ... -}: let - dependencies = builtins.attrValues {inherit (pkgs) git neovim;}; - name = "config_setup"; - src = ./config_setup.sh; -in - sysLib.writeShellScriptWithLibrary {inherit dependencies name src;} diff --git a/bootstrap/default.nix b/bootstrap/default.nix new file mode 100644 index 00000000..60c72e6a --- /dev/null +++ b/bootstrap/default.nix @@ -0,0 +1,39 @@ +{ + pkgs, + sysLib, + ... +}: let + 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}";}; + }; + 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}";}; + }; + 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}";}; + }; + 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}";}; + }; + ensure_config_variables = sysLib.writeShellScriptWithLibrary { + dependencies = builtins.attrValues {inherit (pkgs) jq dash;}; + name = "ensure_config_variables"; + src = ./99_ensure_config_variables.sh; + }; + output = {inherit activate install setup config_setup ensure_config_variables;}; +in + output +# vim: ts=2 + diff --git a/bootstrap/install/default.nix b/bootstrap/install/default.nix deleted file mode 100644 index 4f520c92..00000000 --- a/bootstrap/install/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -# vim: ts=2 -{ - pkgs, - sysLib, - ... -}: let - dependencies = builtins.attrValues {inherit (pkgs) jq dash curl gawk btrfs-progs coreutils libuuid gptfdisk dosfstools toybox nix git;}; - name = "install"; - src = ./install.sh; -in - sysLib.writeShellScriptWithLibrary {inherit dependencies name src;} diff --git a/bootstrap/install/install.sh b/bootstrap/install/install.sh deleted file mode 100755 index 74642d08..00000000 --- a/bootstrap/install/install.sh +++ /dev/null @@ -1,158 +0,0 @@ -#! /usr/bin/env dash - -# shellcheck source=/dev/null -SHELL_LIBRARY_VERSION="1.1.4" . %SHELL_LIBRARY_PATH -bsc() { - msg2 "$(btrfs subvolume create "$1" || die "Creating of subvol $1 failed")"; -} - -mne() { - mount --mkdir --options compress-force=zstd:15,subvol="$1" $DISK_ROOT "$2" || die "Mounting of $1 failed"; -} - - -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 a disk to format:\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=$(mktmp); - jq -e --argjson i "$i" 'nth($i)' "$available_disks" > "$disk"; - else - warning "No disk selected. Select a disk to continue.\n" - fi -done - -readp "Do you really want to delete all data on disk $(jq '.item' "$disk")? [N/y]: " result -case $result in - [Yy]) - msg "Great, deleting everything..." - disk="$(jq '.item' "$disk" | tr -d "\"")" - ;; - *) - msg "Sure, keep your data" - exit 1 - ;; -esac - -sgdisk -Z "/dev/${disk}" > /dev/null|| die "Zapping failed" - -sgdisk -n 1:0:+550M -n 2:0:"$ENDSECTOR" -t 1:ef00 -t 2:8300 "/dev/${disk}" > /dev/null|| die "Partitioning failed" - -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 "Started Formatting..." -mkfs.fat -F32 "$DISK_EFI" > /dev/null || die "Formatting(fat32) failed" -mkfs.btrfs -f "$DISK_ROOT" > /dev/null || die "Formatting(btrfs) failed" - - -msg "Mounting..." -mount -t btrfs $DISK_ROOT /mnt -cd /mnt || die "(Bug): no /mnt" -bsc nix-store -bsc persistent-storage -bsc persistent-storage/nixos-config -bsc persistent-storage/.snapshots -bsc swap -cd / -umount -R /mnt -mount -t tmpfs none /mnt -mount --mkdir "$DISK_EFI" /mnt/boot - -mne nix-store /mnt/nix -mne persistent-storage /mnt/srv -mne swap /mnt/swap - -mount --mkdir --options bind /mnt/srv/nixos-config /mnt/etc/nixos - -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)"; -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; -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/$disk/queue/rotational); -case "$ssd_or_hdd" in - 0) - msg2 "You seem to use a ssd." - trim_support=$(lsblk --bytes --json --discard | jq --arg name "$disk" '.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, go on"; - ;; - *) - 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 - - -readp "Do you want to continue with nixos-install? [N/y]: " result -case $result in - [Yy]) - 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/setup/default.nix b/bootstrap/setup/default.nix deleted file mode 100644 index 905ddd1b..00000000 --- a/bootstrap/setup/default.nix +++ /dev/null @@ -1,11 +0,0 @@ -# vim: ts=2 -{ - pkgs, - sysLib, - ... -}: let - dependencies = builtins.attrValues {inherit (pkgs) dash gawk curl git nix gnugrep nixos-install-tools coreutils libuuid;}; - name = "setup"; - src = ./setup.sh; -in - sysLib.writeShellScriptWithLibrary {inherit dependencies name src;} diff --git a/flake/default.nix b/flake/default.nix index 6e70428b..02d6e5b4 100644 --- a/flake/default.nix +++ b/flake/default.nix @@ -138,6 +138,7 @@ in { nil ragenix.packages."${system}".default shellcheck + shfmt statix yamllint ]; diff --git a/flake/packages/default.nix b/flake/packages/default.nix index 8ca00e98..0c3d6c1b 100644 --- a/flake/packages/default.nix +++ b/flake/packages/default.nix @@ -4,39 +4,18 @@ defaultSpecialArgs, pkgs, sysLib, - lib, ... -}: { - iso = nixos-generators.nixosGenerate { - system = "x86_64-linux"; - specialArgs = defaultSpecialArgs; - modules = [ - ../../hosts/marduk - ]; - format = "install-iso"; - }; - install = import ../../bootstrap/install { - inherit - pkgs - sysLib - ; - }; - activate = import ../../bootstrap/activate { - inherit - pkgs - sysLib - ; - }; - setup = import ../../bootstrap/setup { - inherit - pkgs - sysLib - ; - }; - config_setup = import ../../bootstrap/config_setup { - inherit - pkgs - sysLib - ; - }; -} +}: let + output = import ../../bootstrap {inherit pkgs sysLib;}; +in + { + iso = nixos-generators.nixosGenerate { + system = "x86_64-linux"; + specialArgs = defaultSpecialArgs; + modules = [ + ../../hosts/marduk + ]; + format = "install-iso"; + }; + } + // output |