paste in ai generated bootstrap script
This commit is contained in:
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env bash
|
||||
# this will one day be an interactive install bootstrap script for my nix config!
|
||||
# right now this shall be treated as psudocode but also just a list of steps for installing
|
||||
# without further adoo:
|
||||
#
|
||||
# 1. boot target device into nixos installer iso
|
||||
# 2. `sudo -i``
|
||||
# 3. `git clone https://git.blakedheld.xyz/blake/nix.git bootstrap_nix`
|
||||
# 4. if new host use `ls -l /dev/disk/by-id/` to get the id of the target disk and update the related line in the disko config for that host (or partition the target disk manually however you wish)
|
||||
# 5. run the disko install command `nix run github:nix-community/disko -- --mode destroy,format,mount --flake bootstrap_nix#hostname` to just format the disk(s)
|
||||
# 6. generate hardware config `nixos-generate-config --root /mnt`
|
||||
# 7. create directories for keys `mkdir -p /mnt/etc/sops` `mkdir -p /mnt/home/blake/.config/sops/age`
|
||||
# 8. move nix config to home dir `mv /bootstrap_nix /mnt/home/blake/.nix`
|
||||
# 9. copy age keys.txt to previously made dirs `echo "<key>" | tee /mnt/etc/sops/keys.txt /mnt/home/blake/.config/sops/age/keys.txt > dev/null`
|
||||
# 10. install the os (let it fail, fix it, repeat, etc) `nixos-install --flake /mnt/home/blake/.nix#hostname`
|
||||
# 11. set the root password
|
||||
# 12. reboot and dont forget to `sudo chown -R blake:blake /home/blake`
|
||||
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "nixos bootstrap installer =="
|
||||
|
||||
# --- input ---
|
||||
read -rp "hostname: " HOSTNAME
|
||||
read -rsp "age key (will not be echoed): " AGE_KEY
|
||||
echo
|
||||
|
||||
echo
|
||||
echo "install mode:"
|
||||
echo " 1) disko (auto partition/format/mount)"
|
||||
echo " 2) manual (you already mounted disks)"
|
||||
read -rp "choice [1/2]: " MODE
|
||||
echo
|
||||
if [[ -d /bootstrap_nix ]]; then
|
||||
echo "repo already exists, skipping clone"
|
||||
else
|
||||
echo "cloning nix config..."
|
||||
git clone https://git.blakedheld.xyz/blake/nix.git /bootstrap_nix
|
||||
fi
|
||||
|
||||
cd /bootstrap_nix
|
||||
|
||||
# --- disk setup ---
|
||||
if [[ "$MODE" == "1" ]]; then
|
||||
echo
|
||||
echo "running disko (THIS WILL DESTROY DISKS)..."
|
||||
echo "make sure /dev/disk/by-id is correct in your host config!"
|
||||
|
||||
nix run github:nix-community/disko -- \
|
||||
--mode destroy,format,mount \
|
||||
--flake .#"${HOSTNAME}"
|
||||
|
||||
elif [[ "$MODE" == "2" ]]; then
|
||||
echo
|
||||
echo "MANUAL MODE SELECTED"
|
||||
echo "WARNING: you must have already partitioned + mounted disks to /mnt"
|
||||
read -rp "press ENTER to continue once disks are mounted..."
|
||||
|
||||
else
|
||||
echo "invalid selection"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- generate hardware config ---
|
||||
echo
|
||||
echo "generating hardware config..."
|
||||
nixos-generate-config --root /mnt
|
||||
|
||||
# --- setup directories ---
|
||||
echo "creating sops/age directories..."
|
||||
mkdir -p /mnt/etc/sops
|
||||
mkdir -p /mnt/home/blake/.config/sops/age
|
||||
|
||||
# --- move config ---
|
||||
echo "moving nix config into /mnt/home/blake/.nix ..."
|
||||
mv /bootstrap_nix /mnt/home/blake/.nix
|
||||
|
||||
# --- write age key ---
|
||||
echo "writing age key..."
|
||||
echo "$AGE_KEY" | tee \
|
||||
/mnt/etc/sops/keys.txt \
|
||||
/mnt/home/blake/.config/sops/age/keys.txt \
|
||||
> /dev/null
|
||||
|
||||
# --- install ---
|
||||
echo
|
||||
echo "running nixos-install..."
|
||||
set +e
|
||||
nixos-install --flake /mnt/home/blake/.nix#"${HOSTNAME}"
|
||||
INSTALL_EXIT=$?
|
||||
set -e
|
||||
|
||||
if [[ $INSTALL_EXIT -ne 0 ]]; then
|
||||
echo
|
||||
echo "install failed. fix issues and re-run nixos-install manually if needed."
|
||||
exit $INSTALL_EXIT
|
||||
fi
|
||||
|
||||
# --- post install ---
|
||||
echo
|
||||
echo "installation complete!"
|
||||
echo "set root password if needed, then reboot."
|
||||
echo "after reboot: sudo chown -R blake:blake /home/blake"
|
||||
|
||||
echo "fin."
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# this will one day be an interactive install bootstrap script for my nix config!
|
||||
# right now this shall be treated as psudocode but also just a list of steps for installing
|
||||
# without further adoo:
|
||||
#
|
||||
# 1. boot target device into nixos installer iso
|
||||
# 2. `sudo -i``
|
||||
# 3. `git clone https://git.blakedheld.xyz/blake/nix.git bootstrap_nix`
|
||||
# 4. if new host use `ls -l /dev/disk/by-id/` to get the id of the target disk and update the related line in the disko config for that host (or partition the target disk manually however you wish)
|
||||
# 5. run the disko install command `nix run github:nix-community/disko -- --mode destroy,format,mount --flake bootstrap_nix#hostname` to just format the disk(s)
|
||||
# 6. generate hardware config `nixos-generate-config --root /mnt`
|
||||
# 7. create directories for keys `mkdir -p /mnt/etc/sops` `mkdir -p /mnt/home/blake/.config/sops/age`
|
||||
# 8. move nix config to home dir `mv /bootstrap_nix /mnt/home/blake/.nix`
|
||||
# 9. copy age keys.txt to previously made dirs `echo "<key>" | tee /mnt/etc/sops/keys.txt /mnt/home/blake/.config/sops/age/keys.txt > dev/null`
|
||||
# 10. install the os (let it fail, fix it, repeat, etc) `nixos-install --flake /mnt/home/blake/.nix`
|
||||
# 11. set the root password
|
||||
# 12. reboot and dont forget to `sudo chown -R blake:blake /home/blake`
|
||||
|
||||
Reference in New Issue
Block a user