aboutsummaryrefslogtreecommitdiffstats
path: root/bootstrap/99_ensure_config_variables
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-07-02 13:01:36 +0200
committerSoispha <soispha@vhack.eu>2023-07-10 16:44:20 +0200
commiteb6a837828134ef034a6ee9b0feec197c52f8bc7 (patch)
treeed4dc09af0182e058534866935974bfba3f6f5f4 /bootstrap/99_ensure_config_variables
parentFix(system/disks): Add remainder about bootable option (diff)
downloadnixos-config-eb6a837828134ef034a6ee9b0feec197c52f8bc7.zip
Fix(bootstrap): Only set environment variables once
Diffstat (limited to '')
-rwxr-xr-xbootstrap/99_ensure_config_variables207
1 files changed, 105 insertions, 102 deletions
diff --git a/bootstrap/99_ensure_config_variables b/bootstrap/99_ensure_config_variables
index 89961150..b2ca9792 100755
--- a/bootstrap/99_ensure_config_variables
+++ b/bootstrap/99_ensure_config_variables
@@ -3,117 +3,120 @@
# shellcheck source=/dev/null
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"
+if ! [ "$NIX_ENVIRONMENT_VARIABLES_SET" ]; then
+ 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
+ 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
+ [ "$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"
+ 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:"
+ [ "$(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
+ 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 "\"")"
+ 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
- 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 "\"")"
+ _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"
+ exit 1
+ ;;
+ esac
+ fi
- 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 "\"")"
- _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"
- 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
-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
+ 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
+ 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
+ export NIX_ENVIRONMENT_VARIABLES_SET="set";
fi
# vim: ft=sh