feat(install): add disko direct-url workflow
This commit is contained in:
parent
7a42926fba
commit
973bac7ed0
8 changed files with 154 additions and 92 deletions
|
|
@ -1,17 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Non-interactive Btrfs installer using the flake in this repo.
|
||||
# Non-interactive Btrfs installer using disko-install.
|
||||
# Defaults: DISK=/dev/vda TARGET_HOST=nanuqsaurus
|
||||
# If FLAKE is unset and /etc/nixos/flake.nix exists, it uses /etc/nixos.
|
||||
# Otherwise, set FLAKE to a flake URI like:
|
||||
# - git+https://codeberg.org/<owner>/<repo>.git
|
||||
# - github:<owner>/<repo>
|
||||
|
||||
DISK="${DISK:-/dev/vda}"
|
||||
TARGET_HOST="${TARGET_HOST:-nanuqsaurus}"
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
|
||||
FLAKE="${FLAKE:-}"
|
||||
|
||||
MNT=/mnt
|
||||
EFI_SIZE=550M
|
||||
|
||||
have() { command -v "$1" >/dev/null 2>&1; }
|
||||
|
||||
|
|
@ -27,85 +28,34 @@ confirm_disk() {
|
|||
sleep 5
|
||||
}
|
||||
|
||||
resolve_flake() {
|
||||
if [[ -n "$FLAKE" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -e /etc/nixos/flake.nix ]]; then
|
||||
FLAKE=/etc/nixos
|
||||
return 0
|
||||
fi
|
||||
|
||||
die "FLAKE is unset. Set FLAKE to a flake URI (or run from an ISO that provides /etc/nixos)."
|
||||
}
|
||||
|
||||
clear
|
||||
confirm_disk
|
||||
resolve_flake
|
||||
|
||||
echo "[1/7] Partitioning ${DISK}"
|
||||
sfdisk "$DISK" <<EOF
|
||||
label: gpt
|
||||
,${EFI_SIZE},U
|
||||
,,L
|
||||
EOF
|
||||
|
||||
echo "[2/7] Formatting filesystems"
|
||||
mkfs.fat -F32 "${DISK}1"
|
||||
mkfs.btrfs -f "${DISK}2"
|
||||
|
||||
echo "[3/7] Creating Btrfs subvolumes"
|
||||
mkdir -p "$MNT"
|
||||
mount "${DISK}2" "$MNT"
|
||||
|
||||
for subvol in root home nix; do
|
||||
btrfs subvolume create "$MNT/$subvol"
|
||||
done
|
||||
|
||||
umount "$MNT"
|
||||
|
||||
echo "[4/7] Mounting subvolumes"
|
||||
mount -o compress=zstd,subvol=root "${DISK}2" "$MNT"
|
||||
mkdir -p "$MNT"/{home,nix,boot}
|
||||
|
||||
mount -o compress=zstd,subvol=home "${DISK}2" "$MNT/home"
|
||||
mount -o compress=zstd,subvol=nix "${DISK}2" "$MNT/nix"
|
||||
mount "${DISK}1" "$MNT/boot"
|
||||
|
||||
echo "[5/7] Copying flake to /etc/nixos"
|
||||
mkdir -p "$MNT/etc/nixos"
|
||||
|
||||
EXCLUDES=(--exclude=.git --exclude=result --exclude=node_modules)
|
||||
|
||||
if have rsync; then
|
||||
rsync -a "${EXCLUDES[@]}" "$REPO_ROOT/" "$MNT/etc/nixos/"
|
||||
else
|
||||
(cd "$REPO_ROOT" && tar -cf - "${EXCLUDES[@]/#/--exclude=}" .) \
|
||||
| (cd "$MNT/etc/nixos" && tar -xf -)
|
||||
fi
|
||||
|
||||
echo "[6/7] Generating hardware config"
|
||||
HOSTS_DIR="$MNT/etc/nixos/hosts"
|
||||
mkdir -p "$HOSTS_DIR"
|
||||
|
||||
HW_FILE="$HOSTS_DIR/local-${TARGET_HOST}-hardware.nix"
|
||||
HOST_FILE="$HOSTS_DIR/local-${TARGET_HOST}.nix"
|
||||
|
||||
nixos-generate-config --root "$MNT" --show-hardware-config > "$HW_FILE"
|
||||
|
||||
if [[ ! -e "$HOST_FILE" ]]; then
|
||||
cat > "$HOST_FILE" <<EOF
|
||||
{ inputs, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
inputs.lix-module.nixosModules.lixFromNixpkgs
|
||||
../modules/system/base.nix
|
||||
../modules/system/packages.nix
|
||||
../modules/system/home-manager-skel.nix
|
||||
../modules/desktop/gnome-minimal.nix
|
||||
../modules/users/admin.nix
|
||||
./local-${TARGET_HOST}-hardware.nix
|
||||
];
|
||||
|
||||
networking.hostName = "${TARGET_HOST}";
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "[7/7] Installing ${TARGET_HOST} via flake"
|
||||
echo "[1/1] Installing ${TARGET_HOST} via disko-install"
|
||||
LOG=/tmp/nixos-install.log
|
||||
nixos-install \
|
||||
--root "$MNT" \
|
||||
--flake "$MNT/etc/nixos#local-${TARGET_HOST}" \
|
||||
--no-root-passwd |& tee "$LOG"
|
||||
|
||||
nix \
|
||||
--experimental-features "nix-command flakes" \
|
||||
run "github:nix-community/disko/latest#disko-install" -- \
|
||||
--mode format \
|
||||
--flake "${FLAKE}#${TARGET_HOST}" \
|
||||
--disk main "${DISK}" \
|
||||
--mount-point "$MNT" \
|
||||
--system-config '{"users":{"users":{"root":{"hashedPassword":"!"}}}}' |& tee "$LOG"
|
||||
|
||||
echo "Install log saved to $LOG"
|
||||
echo "Install complete. You can reboot now."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue