From 88977eff6b4bb7d346370f19c3e3a597c12fe5d7 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Mon, 31 Jan 2022 02:40:06 -0500 Subject: [PATCH] feat(Infini-DESKTOP): migrate to opt-in state --- hosts/Infini-DESKTOP/bare_install.bash | 7 + hosts/Infini-DESKTOP/default.nix | 28 ++- .../Infini-DESKTOP/hardware-configuration.nix | 58 ++++-- hosts/Infini-DESKTOP/install.bash | 57 ++++++ hosts/Infini-DESKTOP/mount.bash | 35 ++++ hosts/Infini-DESKTOP/prep.bash | 43 +++++ hosts/Infini-DESKTOP/readme.org | 167 ++++++++++++++++++ 7 files changed, 376 insertions(+), 19 deletions(-) create mode 100755 hosts/Infini-DESKTOP/bare_install.bash create mode 100755 hosts/Infini-DESKTOP/install.bash create mode 100755 hosts/Infini-DESKTOP/mount.bash create mode 100755 hosts/Infini-DESKTOP/prep.bash create mode 100644 hosts/Infini-DESKTOP/readme.org diff --git a/hosts/Infini-DESKTOP/bare_install.bash b/hosts/Infini-DESKTOP/bare_install.bash new file mode 100755 index 0000000..0428be2 --- /dev/null +++ b/hosts/Infini-DESKTOP/bare_install.bash @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# [[file:readme.org::bare_install][bare_install]] +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::installing][installing]]][installing]] +echo "LOG: Installing NixOS" +sudo nixos-install --flake /etc/nixos#Infini-DESKTOP --no-root-password +# installing ends here +# bare_install ends here diff --git a/hosts/Infini-DESKTOP/default.nix b/hosts/Infini-DESKTOP/default.nix index 597c896..3087dc7 100644 --- a/hosts/Infini-DESKTOP/default.nix +++ b/hosts/Infini-DESKTOP/default.nix @@ -12,7 +12,31 @@ ./hardware-configuration.nix ]; - system.stateVersion = "21.05"; + system.stateVersion = "21.11"; + + environment.persistence."/persist" = { + directories = [ + "/home" + "/etc/nixos" + + # /var directories + "/var/log" + "/var/lib/bluetooth" + "/var/lib/systemd/coredump" + ]; + + files = [ + "/etc/machine-id" + + "/etc/ssh/ssh_host_rsa_key" + "/etc/ssh/ssh_host_rsa_key.pub" + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_ed25519_key.pub" + + "/root/.local/share/nix/trusted-settings.json" + "/root/.ssh/known_hosts" + ]; + }; modules = { boot.grub.enable = true; @@ -25,7 +49,7 @@ }; services = { foldingathome = { - enable = true; + enable = false; user = "Infinidoge"; extra = { control = true; diff --git a/hosts/Infini-DESKTOP/hardware-configuration.nix b/hosts/Infini-DESKTOP/hardware-configuration.nix index 6c688de..12c00fd 100644 --- a/hosts/Infini-DESKTOP/hardware-configuration.nix +++ b/hosts/Infini-DESKTOP/hardware-configuration.nix @@ -3,6 +3,9 @@ # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: +let + uuid = uuid: "/dev/disk/by-uuid/${uuid}"; +in { imports = [ ]; @@ -10,31 +13,52 @@ boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-amd" ]; boot.extraModulePackages = [ ]; + boot.kernelParams = [ "boot.shell_on_fail" ]; + boot.supportedFilesystems = [ "btrfs" ]; hardware.enableRedistributableFirmware = lib.mkDefault true; - fileSystems."/" = + fileSystems = + let + main = uuid "13f97ece-823e-4785-b06e-6c284105d379"; + esp = uuid "1DB7-2844"; + in { - device = "/dev/disk/by-uuid/c40e2655-8f7e-4dd3-95ab-f2d48639cc59"; - fsType = "ext4"; - }; + "/" = { + device = "none"; + fsType = "tmpfs"; + options = [ "defaults" "size=4G" "mode=755" ]; + }; - fileSystems."/boot/efi" = - { - device = "/dev/disk/by-uuid/21E6-6801"; - fsType = "vfat"; - }; + "/persist" = { + device = main; + fsType = "btrfs"; + options = [ "subvol=root" "autodefrag" "noatime" "ssd" ]; + neededForBoot = true; + }; - fileSystems."/home" = - { - device = "/dev/disk/by-uuid/26438642-0683-4ce3-af6b-b555cb8e388d"; - fsType = "ext4"; + "/nix" = { + device = main; + fsType = "btrfs"; + options = [ "subvol=nix" "autodefrag" "noatime" "ssd" ]; + neededForBoot = true; + }; + + "/boot" = { + device = main; + fsType = "btrfs"; + options = [ "subvol=boot" "autodefrag" "noatime" "ssd" ]; + neededForBoot = true; + }; + + "/boot/efi" = { + device = esp; + fsType = "vfat"; + neededForBoot = true; + }; }; swapDevices = [ - { - device = "/dev/disk/by-uuid/dfbe858e-5732-48d7-8777-37ed19138d7e"; - } + { device = uuid "37916097-dbb9-4a74-b761-17043629642a"; } ]; - } diff --git a/hosts/Infini-DESKTOP/install.bash b/hosts/Infini-DESKTOP/install.bash new file mode 100755 index 0000000..cba1289 --- /dev/null +++ b/hosts/Infini-DESKTOP/install.bash @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# [[file:readme.org::install][install]] +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::mount][mount]]][mount]] +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::boilerplate][boilerplate]]][boilerplate]] +DISK=$1 +PARTITION_PREFIX="p" + +sudo mkdir -p /mnt +# boilerplate ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::mount_check][mount_check]]][mount_check]] +if mountpoint -q -- "/mnt"; then + echo "ERROR: /mnt is a mounted filesystem, aborting" + exit 1 +fi +# mount_check ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::mounting][mounting]]][mounting]] +echo "LOG: Mounting tmpfs" +sudo mount -t tmpfs root /mnt + +echo "LOG: - Mounting persistent directories" +sudo mkdir -p /mnt/persist /mnt/nix /mnt/boot +sudo mount -o subvol=root,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/persist +sudo mount -o subvol=nix,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/nix +sudo mount -o subvol=boot,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/boot + +echo "LOG: - - Mounting persistent subdirectories" +sudo mkdir -p /mnt/home +sudo mount --bind /mnt/persist/home /mnt/home + +echo "LOG: - Mounting EFI System Partition" +sudo mkdir -p /mnt/boot/efi +sudo mount "${DISK}${PARTITION_PREFIX}1" /mnt/boot/efi +# mounting ends here +# mount ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::installing][installing]]][installing]] +echo "LOG: Installing NixOS" +sudo nixos-install --flake /etc/nixos#Infini-DESKTOP --no-root-password +# installing ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::install_extra][install_extra]]][install_extra]] +echo "LOG: Cloning configuration" +sudo chown -R infinidoge /mnt/persist/etc/nixos +git clone --no-hardlinks --progress https://gitlab.com/infinidoge/devos.git /mnt/persist/etc/nixos + +echo "LOG: Installing Doom Emacs" +git clone --no-hardlinks --progress --depth 1 https://github.com/hlissner/doom-emacs /mnt/persist/home/infinidoge/.config/emacs +HOME=/mnt/persist/home/infinidoge /mnt/persist/home/infinidoge/.config/emacs/bin/doom -y install --no-config +# install_extra ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::cleanup][cleanup]]][cleanup]] +echo "LOG: Unmounting all" +sudo umount -R /mnt +# cleanup ends here +# install ends here diff --git a/hosts/Infini-DESKTOP/mount.bash b/hosts/Infini-DESKTOP/mount.bash new file mode 100755 index 0000000..5328d94 --- /dev/null +++ b/hosts/Infini-DESKTOP/mount.bash @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# [[file:readme.org::mount][mount]] +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::boilerplate][boilerplate]]][boilerplate]] +DISK=$1 +PARTITION_PREFIX="p" + +sudo mkdir -p /mnt +# boilerplate ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::mount_check][mount_check]]][mount_check]] +if mountpoint -q -- "/mnt"; then + echo "ERROR: /mnt is a mounted filesystem, aborting" + exit 1 +fi +# mount_check ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::mounting][mounting]]][mounting]] +echo "LOG: Mounting tmpfs" +sudo mount -t tmpfs root /mnt + +echo "LOG: - Mounting persistent directories" +sudo mkdir -p /mnt/persist /mnt/nix /mnt/boot +sudo mount -o subvol=root,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/persist +sudo mount -o subvol=nix,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/nix +sudo mount -o subvol=boot,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/boot + +echo "LOG: - - Mounting persistent subdirectories" +sudo mkdir -p /mnt/home +sudo mount --bind /mnt/persist/home /mnt/home + +echo "LOG: - Mounting EFI System Partition" +sudo mkdir -p /mnt/boot/efi +sudo mount "${DISK}${PARTITION_PREFIX}1" /mnt/boot/efi +# mounting ends here +# mount ends here diff --git a/hosts/Infini-DESKTOP/prep.bash b/hosts/Infini-DESKTOP/prep.bash new file mode 100755 index 0000000..151f4dd --- /dev/null +++ b/hosts/Infini-DESKTOP/prep.bash @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# [[file:readme.org::preparation][preparation]] +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::boilerplate][boilerplate]]][boilerplate]] +DISK=$1 +PARTITION_PREFIX="p" + +sudo mkdir -p /mnt +# boilerplate ends here + + + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::partitioning][partitioning]]][partitioning]] +echo "LOG: Partitioning $DISK" +sudo parted $DISK -- mktable gpt +sudo parted $DISK -s -- mkpart ESP fat32 1MiB 512MiB +sudo parted $DISK -s -- mkpart primary btrfs 512MiB -48GiB +sudo parted $DISK -s -- mkpart primary linux-swap -48GiB 100% +sudo parted $DISK -s -- set 1 esp on +# partitioning ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::filesystems][filesystems]]][filesystems]] +echo "LOG: Making filesystems" +echo "- Making fat32 filesystem on ${DISK}${PARTITION_PREFIX}1" +sudo mkfs.fat -F 32 -n boot "${DISK}${PARTITION_PREFIX}1" +echo "- Making btrfs filesystem on ${DISK}${PARTITION_PREFIX}2" +sudo mkfs.btrfs "${DISK}${PARTITION_PREFIX}2" -L "Infini-DESKTOP" -f +echo "- Making swap space on ${DISK}${PARTITION_PREFIX}3" +sudo mkswap -L swap "${DISK}${PARTITION_PREFIX}3" +# filesystems ends here + +# [[[[file:/etc/nixos/hosts/Infini-DESKTOP/readme.org::subvolumes][subvolumes]]][subvolumes]] +echo "LOG: Making subvolumes on ${DISK}${PARTITION_PREFIX}2" +sudo mount "${DISK}${PARTITION_PREFIX}2" /mnt +sudo btrfs subvolume create /mnt/root +sudo btrfs subvolume create /mnt/root/home +sudo mkdir -p /mnt/root/etc +sudo btrfs subvolume create /mnt/root/etc/nixos +sudo btrfs subvolume create /mnt/boot +sudo btrfs subvolume create /mnt/nix +sudo btrfs subvolume create /mnt/nix/store +sudo umount /mnt +# subvolumes ends here +# preparation ends here diff --git a/hosts/Infini-DESKTOP/readme.org b/hosts/Infini-DESKTOP/readme.org new file mode 100644 index 0000000..c47588a --- /dev/null +++ b/hosts/Infini-DESKTOP/readme.org @@ -0,0 +1,167 @@ +#+TITLE: Infini-DESKTOP Specification +#+AUTHOR: Infinidoge +#+OPTIONS: toc:nil +#+LaTeX_CLASS_OPTIONS: [12pt] +#+LATEX_HEADER: \usepackage[margin=1in]{geometry} + +* Partition Scheme + +| Position | Label | FS Type | Size | Type | +|----------+------------------+------------------+------+----------------------| +| 1 | =boot= | =vfat= / =fat32= | 511M | EFI System Partition | +| 2 | =Infini-DESKTOP= | =btrfs= | Rest | Root Partition | +| 3 | =swap= | =swap= | 48G | Swap Space | + +* Configuration + +Setup for my main desktop computer, using an Nvidia GPU and the =desktop= form factor from =hardware/form=. + +* Setup Scripts + +#+NAME: preparation +#+BEGIN_SRC bash :tangle prep.bash :shebang "#!/usr/bin/env bash" :noweb yes :comments noweb +<> + +<> + +<> + +<> + +<> +#+END_SRC + +#+NAME: install +#+BEGIN_SRC bash :tangle install.bash :shebang "#!/usr/bin/env bash" :noweb yes :comments noweb +<> + +<> + +<> + +<> +#+END_SRC + +#+NAME: mount +#+BEGIN_SRC bash :tangle mount.bash :shebang "#!/usr/bin/env bash" :noweb yes :comments noweb +<> + +<> + +<> +#+END_SRC + +#+NAME: bare_install +#+BEGIN_SRC bash :tangle bare_install.bash :shebang "#!/usr/bin/env bash" :noweb yes :comments noweb +<> +#+END_SRC + +** Script Boilerplate + +#+NAME: boilerplate +#+BEGIN_SRC bash +DISK=$1 +PARTITION_PREFIX="p" + +sudo mkdir -p /mnt +#+END_SRC + +#+NAME: mount_check +#+BEGIN_SRC bash +if mountpoint -q -- "/mnt"; then + echo "ERROR: /mnt is a mounted filesystem, aborting" + exit 1 +fi +#+END_SRC + +** Partitioning + +#+NAME: partitioning +#+BEGIN_SRC bash +echo "LOG: Partitioning $DISK" +sudo parted $DISK -- mktable gpt +sudo parted $DISK -s -- mkpart ESP fat32 1MiB 512MiB +sudo parted $DISK -s -- mkpart primary btrfs 512MiB -48GiB +sudo parted $DISK -s -- mkpart primary linux-swap -48GiB 100% +sudo parted $DISK -s -- set 1 esp on +#+END_SRC + +** Making Filesystems + +#+NAME: filesystems +#+BEGIN_SRC bash +echo "LOG: Making filesystems" +echo "- Making fat32 filesystem on ${DISK}${PARTITION_PREFIX}1" +sudo mkfs.fat -F 32 -n boot "${DISK}${PARTITION_PREFIX}1" +echo "- Making btrfs filesystem on ${DISK}${PARTITION_PREFIX}2" +sudo mkfs.btrfs "${DISK}${PARTITION_PREFIX}2" -L "Infini-DESKTOP" -f +echo "- Making swap space on ${DISK}${PARTITION_PREFIX}3" +sudo mkswap -L swap "${DISK}${PARTITION_PREFIX}3" +#+END_SRC + +** Making Subvolumes + +#+NAME: subvolumes +#+BEGIN_SRC bash +echo "LOG: Making subvolumes on ${DISK}${PARTITION_PREFIX}2" +sudo mount "${DISK}${PARTITION_PREFIX}2" /mnt +sudo btrfs subvolume create /mnt/root +sudo btrfs subvolume create /mnt/root/home +sudo mkdir -p /mnt/root/etc +sudo btrfs subvolume create /mnt/root/etc/nixos +sudo btrfs subvolume create /mnt/boot +sudo btrfs subvolume create /mnt/nix +sudo btrfs subvolume create /mnt/nix/store +sudo umount /mnt +#+END_SRC + +** Mounting Volumes + +#+NAME: mounting +#+BEGIN_SRC bash +echo "LOG: Mounting tmpfs" +sudo mount -t tmpfs root /mnt + +echo "LOG: - Mounting persistent directories" +sudo mkdir -p /mnt/persist /mnt/nix /mnt/boot +sudo mount -o subvol=root,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/persist +sudo mount -o subvol=nix,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/nix +sudo mount -o subvol=boot,autodefrag,noatime "${DISK}${PARTITION_PREFIX}2" /mnt/boot + +echo "LOG: - - Mounting persistent subdirectories" +sudo mkdir -p /mnt/home +sudo mount --bind /mnt/persist/home /mnt/home + +echo "LOG: - Mounting EFI System Partition" +sudo mkdir -p /mnt/boot/efi +sudo mount "${DISK}${PARTITION_PREFIX}1" /mnt/boot/efi +#+END_SRC + +** Installing + +#+NAME: installing +#+BEGIN_SRC bash +echo "LOG: Installing NixOS" +sudo nixos-install --flake /etc/nixos#Infini-DESKTOP --no-root-password +#+END_SRC + +** Extra (Install) + +#+NAME: install_extra +#+BEGIN_SRC bash +echo "LOG: Cloning configuration" +sudo chown -R infinidoge /mnt/persist/etc/nixos +git clone --no-hardlinks --progress https://gitlab.com/infinidoge/devos.git /mnt/persist/etc/nixos + +echo "LOG: Installing Doom Emacs" +git clone --no-hardlinks --progress --depth 1 https://github.com/hlissner/doom-emacs /mnt/persist/home/infinidoge/.config/emacs +HOME=/mnt/persist/home/infinidoge /mnt/persist/home/infinidoge/.config/emacs/bin/doom -y install --no-config +#+END_SRC + +** Cleanup + +#+NAME: cleanup +#+BEGIN_SRC bash +echo "LOG: Unmounting all" +sudo umount -R /mnt +#+END_SRC