From 99605585e1673e0aa0ff12f5f775705a21196b6b Mon Sep 17 00:00:00 2001 From: caem Date: Tue, 14 Jan 2025 00:16:41 +0100 Subject: [PATCH] moar progress --- hosts/puter/default.nix | 2 +- hosts/puter/disko.nix | 4 ++-- hosts/vm/default.nix | 4 ++-- hosts/vm/disko.nix | 4 ++-- install.sh | 46 ++++++++++++++++++++++++++++++++++++++--- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/hosts/puter/default.nix b/hosts/puter/default.nix index 692d94b..dfa035f 100644 --- a/hosts/puter/default.nix +++ b/hosts/puter/default.nix @@ -20,7 +20,7 @@ efi.canTouchEfiVariables = true; grub = { enable = true; - device = "/dev/nvme0"; # [managed by install.sh] { grub device } + device = "/dev/nvme0n1"; # [managed by install.sh] efiSupport = true; gfxmodeEfi = "1920x1080"; }; diff --git a/hosts/puter/disko.nix b/hosts/puter/disko.nix index 2b42347..963773e 100644 --- a/hosts/puter/disko.nix +++ b/hosts/puter/disko.nix @@ -5,7 +5,7 @@ disk = { master = { type = "disk"; - device = ""; # [managed by install.sh] { device } + device = "/dev/nvme0n1"; # [managed by install.sh] content = { type = "gpt"; partitions = { @@ -32,7 +32,7 @@ extraArgs = [ "-f" "-L nixos" ]; postCreateHook = '' TMP_MNT=$(mktemp -d) - MNT_PART="" # [managed by install.sh] { root partition } + MNT_PART="/dev/nvme0n1" # [managed by install.sh] mount "$MNT_PART" "$TMP_MNT" -o subvol=/ trap 'umount "$TMP_MNT"; rm -rf "$TMP_MNT"' EXIT btrfs subvolume snapshot "$TMP_MNT/root" "$TMP_MNT/blank" diff --git a/hosts/vm/default.nix b/hosts/vm/default.nix index f10bcc1..18f41d7 100644 --- a/hosts/vm/default.nix +++ b/hosts/vm/default.nix @@ -19,7 +19,7 @@ loader = { grub = { enable = true; - device = "/dev/nvme0n1"; # [managed by install.sh] { grub device } + device = "/dev/sda"; # [managed by install.sh] gfxmodeEfi = "1920x1080"; }; }; @@ -45,6 +45,6 @@ # these specific partitions. }; - system.stateVersion = "24.11"; # [managed by install.sh] { state version } + system.stateVersion = "24.11"; # [managed by install.sh] } diff --git a/hosts/vm/disko.nix b/hosts/vm/disko.nix index 2b42347..cf79e16 100644 --- a/hosts/vm/disko.nix +++ b/hosts/vm/disko.nix @@ -5,7 +5,7 @@ disk = { master = { type = "disk"; - device = ""; # [managed by install.sh] { device } + device = "/dev/sda"; # [managed by install.sh] content = { type = "gpt"; partitions = { @@ -32,7 +32,7 @@ extraArgs = [ "-f" "-L nixos" ]; postCreateHook = '' TMP_MNT=$(mktemp -d) - MNT_PART="" # [managed by install.sh] { root partition } + MNT_PART="/dev/sda2" # [managed by install.sh] mount "$MNT_PART" "$TMP_MNT" -o subvol=/ trap 'umount "$TMP_MNT"; rm -rf "$TMP_MNT"' EXIT btrfs subvolume snapshot "$TMP_MNT/root" "$TMP_MNT/blank" diff --git a/install.sh b/install.sh index 85ce6bd..7c48e55 100755 --- a/install.sh +++ b/install.sh @@ -72,19 +72,59 @@ args() { args_ensure_is_set "--host" "$DOTNIX_HOSTNAME" } +sed_safe () { + # I got this off of some random StackOverflow answer. Don't put too much trust in this. + printf "%s" "$1" | sed -r 's/([\$\.\*\/\[\\^])/\\\1/g' | sed 's/[]]/\[]]/g' +} + +partition_num_for_device() { + parent_dir="$(basename "$(dirname "$1")")" + if [ "$parent_dir" = "disk" ]; then + >&2 echo "Don't use persistent device names. They will automatically be set later on." + exit 1 + elif [ "$parent_dir" = "mapper" ]; then + >&2 echo "lvm volumes are not supported." + exit 1 + elif [ "$parent_dir" != "dev" ]; then + >&2 echo "Block device directory not recognized: $parent_dir" + exit 1 + fi + + case "$(basename "$1")" in + "nvme"* | "mmcblk"*) + printf "%s" "${1}p${2}" + ;; + "sda"* | "vda"* | "hda"*) + printf "%s" "${1}${2}" + ;; + *) + >&2 echo "Invalid block device type '$(basename "$1")'" + exit 1 + ;; + esac +} + update_managed_values() { - echo "piss" + sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$DOTNIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/default.nix" + sed -i 's/\( *device = \)".*"\(; #.*\)/\1"'"$(sed_safe "$DOTNIX_INSTALL_DEVICE")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/disko.nix" + sed -i 's/\( *MNT_PART=\)".*"\( #.*\)/\1"'"$(sed_safe \ + "$(partition_num_for_device "$DOTNIX_INSTALL_DEVICE" "2")")"'"\2/' "./hosts/$DOTNIX_HOSTNAME/disko.nix" } main () { args "$@" - update_managed_values - if [ "$(id -u)" != "0" ]; then >&2 echo "The installation script must be run as root to work." exit 1 fi + + if [ ! -d /sys/firmware/efi ]; then + >&2 echo "Legacy BIOS is unsupported" + exit 1 + fi + + update_managed_values } set -e