dotfiles

My PC Dotfiles & Website
commit 332ff28a4b9fc9295cbda30efe08dc2989bcccbb
parent 7a5338b4224a09e6caa58e47a118299f1a4883af
Author: maydayv7 <maydayv7@gmail.com>
Date:   Wed, 13 Dec 2023 22:42:12 +0530

feat: Separate `install` Script

Diffstat:

MREADME.md | 10++++++----
Mdevices/flake.nix | 66++++++++++++++++++++++++++----------------------------------------
Mfiles/flake.nix | 8++++----
Mlib/pack.nix | 6+++---
Mmodules/base/console.nix | 20--------------------
Mmodules/base/default.nix | 21++++++++++++++++++++-
Mmodules/configuration.nix | 21++++++++++++++++++---
Mmodules/hardware/filesystem.nix | 6+++---
Mscripts/README.md | 6++++--
Ascripts/install.nix | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/nixos.nix | 160+++++++++++++++++++++++++------------------------------------------------------
Dscripts/partitions.sh | 67-------------------------------------------------------------------
12 files changed, 294 insertions(+), 257 deletions(-)

diff --git a/README.md b/README.md @@ -146,6 +146,7 @@ github:maydayv7/dotfiles │ ├── map.nix │ └── pack.nix ├── scripts +│ ├── install.nix │ └── nixos.nix ├── packages │ └── overlays @@ -242,8 +243,8 @@ _Replace_ **_VARIANT_** _with the name of Install Media to create_ You can also download the NixOS `.iso` from [here](https://nixos.org/download.html) and run the `install` script using the following command: ``` -nix build github:maydayv7/dotfiles#nixos -sudo ./result/bin/nixos install +nix build github:maydayv7/dotfiles#install +sudo ./result/bin/os-install ``` If you want to create an `.iso` image of the entire system, run the following command: @@ -269,9 +270,9 @@ _Note that the `install` script automatically creates and labels all the require #### Procedure -To install the OS, just boot the Live USB and run `sudo nixos install` +To install the OS, just boot the Live USB and run `sudo os-install` _If the image doesn't boot, try disabling the `secure boot` and `RAID` options from `BIOS`_ -After the reboot, run `nixos install --first-boot` to finish the install +After the reboot, run `nixos setup` to finish the install _In case you are using the `advanced` filesystem scheme, you may need to set the boot flag `zfs_force=1` on first boot_ </details> @@ -408,6 +409,7 @@ You can navigate to the `README`s present in the various directories to know mor - Support Secure Boot using [`lanzaboote`](https://github.com/nix-community/lanzaboote) - Allow patching Default Package Channel - Separate `games` and `laptop` module +- Separate `install` Script - Show package delta using [`nvd`](https://gitlab.com/khumba/nvd) - Upgrade to GNOME 45 - Update Extensions diff --git a/devices/flake.nix b/devices/flake.nix @@ -7,60 +7,46 @@ inherit (inputs) self; inherit (util) map pack; inherit (builtins) head readFile; + inherit (lib) listToAttrs nameValuePair; inherit (import ../modules/configuration.nix {inherit lib inputs;}) build; in { flake = { ## Device Configuration ## nixosConfigurations = map.modules ./. (name: build (import name)); - ## Virtual Machines ## - vmConfigurations = with self; - map.modules ./vm - (name: import name inputs.wfvm.lib legacyPackages."${head systems}"); - ## Install Media Configuration ## - installMedia = let - iso = config: - build (config - // { - format = "iso"; - description = "Install Media"; + installMedia = + listToAttrs (builtins.map (name: + nameValuePair name (build { + format = "iso"; + description = "Install Media"; - kernelModules = ["nvme"]; - kernel = "zfs"; - gui.desktop = config.gui.desktop + "-minimal"; + # Region + timezone = "Asia/Kolkata"; + locale = "IN"; - # Default User - user = { - name = "nixos"; - description = "Default User"; - minimal = true; - shells = null; - password = readFile ../modules/user/passwords/default; - }; + kernelModules = ["nvme"]; + kernel = "zfs"; + gui.desktop = name + "-minimal"; - # Disabled Modules - imports = [ - { - user.home = lib.mkForce {}; - sops.secrets = lib.mkForce {}; - } - ]; - }); + user = { + name = "nixos"; + description = "Default User"; + minimal = true; + shells = null; + password = readFile ../modules/user/passwords/default; + }; + })) (map.modules.name ../modules/gui/desktop)) + // {default = self.installMedia.xfce;}; - region = { - timezone = "Asia/Kolkata"; - locale = "IN"; - }; - in rec { - default = xfce; - gnome = iso (region // {gui.desktop = "gnome";}); - xfce = iso (region // {gui.desktop = "xfce";}); - }; + ## Virtual Machines ## + vmConfigurations = with self; + map.modules ./vm + (name: import name inputs.wfvm.lib legacyPackages."${head systems}"); }; # Install Media Checks perSystem = _: { - checks = pack.device self.installMedia "nixos-rebuild"; + checks = pack.device self.installMedia; }; } diff --git a/files/flake.nix b/files/flake.nix @@ -11,7 +11,10 @@ # File Paths path = { toplevel = ./.; - system = "/etc/nixos"; + + system = "/etc/nixos"; # Configuration Directory + persist = "/nix/state"; # Persisted Files + cache = "maydayv7-dotfiles"; flake = "github:maydayv7/dotfiles"; repo = "https://github.com/maydayv7/dotfiles"; @@ -60,9 +63,6 @@ # Pictures images.profile = ./images/Profile.png; - # Persisted Files - persist = "/nix/state"; - # Plank Dock plank = { autostart = readFile ./plank/dock.desktop; diff --git a/lib/pack.nix b/lib/pack.nix @@ -1,13 +1,13 @@ lib: let inherit (builtins) attrNames; inherit (lib) genAttrs id mapAttrs'; -in rec { +in { ## Packager Functions ## # Device Configurations - device = attrs: check: + device = attrs: mapAttrs' (_: name: { name = "Device-${name}"; - value = attrs."${name}".config.system.build."${check}"; + value = attrs."${name}".config.system.build."nixos-rebuild"; }) (genAttrs (attrNames attrs) id); # User Home Configurations diff --git a/modules/base/console.nix b/modules/base/console.nix @@ -24,25 +24,5 @@ in { font-size=14 ''; }; - - # Essential Utilities - environment.systemPackages = with pkgs; [ - cryptsetup - gparted - inxi - killall - mkpasswd - custom.nixos - ntfsprogs - parted - pciutils - rsync - sdparm - smartmontools - unrar - unzip - usbutils - wget - ]; }; } diff --git a/modules/base/default.nix b/modules/base/default.nix @@ -8,10 +8,29 @@ ## Base Configuration ## config = { # Documentation - environment.systemPackages = [pkgs.man-pages]; documentation = { dev.enable = true; man.enable = true; }; + + # Essential Utilities + environment.systemPackages = with pkgs; [ + cryptsetup + gparted + inxi + killall + man-pages + mkpasswd + ntfsprogs + parted + pciutils + rsync + sdparm + smartmontools + unrar + unzip + usbutils + wget + ]; }; } diff --git a/modules/configuration.nix b/modules/configuration.nix @@ -13,7 +13,6 @@ getAttr hashString map - removeAttrs replaceStrings substring ; @@ -83,7 +82,7 @@ in { # Modulated Configuration Imports imports = imports - ++ (attrValues (removeAttrs self.nixosModules ["default"])) + ++ (attrValues self.nixosModules) ++ map user' ( if (user != null) then [user] @@ -94,7 +93,23 @@ in { then [(getAttr format inputs.generators.nixosModules)] else [] ) - ++ util.map.array (hardware.modules or []) inputs.hardware.nixosModules; + ++ util.map.array (hardware.modules or []) inputs.hardware.nixosModules + ++ ( + if (format == "iso") + then [ + { + environment.systemPackages = [pkgs.custom.install]; + + # Disabled Modules + user.home = lib.mkForce {}; + sops.secrets = lib.mkForce {}; + } + ] + else if (format != "iso") + then [{environment.systemPackages = [pkgs.custom.nixos];}] + else [] + ); + inherit apps gui hardware shell; # Device Name diff --git a/modules/hardware/filesystem.nix b/modules/hardware/filesystem.nix @@ -28,7 +28,7 @@ in { imports = [inputs.impermanence.nixosModule] ++ [ - (mkAliasOptionModule ["environment" "persist"] ["environment" "persistence" files.persist]) + (mkAliasOptionModule ["environment" "persist"] ["environment" "persistence" files.path.persist]) ]; options = with types; { @@ -159,14 +159,14 @@ in { # Persisted Files system.activationScripts.dotfiles = let - dir = with files; "${persist}/${path.system}"; + dir = with files.path; "${persist}/${system}"; in '' chown root:keys ${dir} chmod 774 -R ${dir} ''; environment.persistence = { - "${files.persist}" = { + "${files.path.persist}" = { files = ["/etc/machine-id"]; directories = [ files.path.system diff --git a/scripts/README.md b/scripts/README.md @@ -1,7 +1,7 @@ ### Scripts The `scripts` directory contains a combination of custom Bash Scripts (with `nix` shebangs, and can be run using <code><i>./path/to/script</i></code>) as well as ones written in conjunction with the Nix Syntax (which can be accessed by `github:maydayv7/dotfiles#apps.${system}`) -A system management script, invoked with the command [`nixos`](./nixos.nix), has been included, which can be used to apply user and device configuration changes, painlessly install the OS and setup the device using a single command, and perform various other useful functions (If you have a working NixOS install, you can check it out using `nix run github:maydayv7/dotfiles`) +A system management script is present, invoked with the command [`nixos`](./nixos.nix), which can be used to apply user and device configuration changes, setup the device on first boot, and perform various other useful functions (If you have a working NixOS install, you can check it out using `nix run github:maydayv7/dotfiles`) ```shellsession $ nixos -h @@ -17,7 +17,6 @@ $ nixos -h check [ --trace ] - Checks System Configuration [ Displays Error to Trace ] clean [ --all ] - Garbage Collects and Optimises Nix Store explore - Opens Interactive Shell to explore Syntax and Configuration - install - Installs NixOS onto System iso 'variant' [ --burn ] - Builds Image for Specified Install Media or Device [ Burns '.iso' to USB ] list [ 'pattern' ] - Lists all Installed Packages [ Returns Matches ] locate 'package' - Locates Installed Package @@ -25,6 +24,9 @@ $ nixos -h save - Saves Configuration State to Repository search 'term' [ 'source' ] - Searches for Packages [ Providing 'term' ] or Configuration Options secret 'choice' [ 'path' ] - Manages 'sops' Encrypted Secrets + setup - Sets up NixOS System (on First Boot) shell [ 'name' ] - Opens desired Nix Developer Shell update [ 'repo' / --'option' ] - Manages System Package Updates ``` + +There is also a system install script, invoked with the command [`os-install`](./install.nix), that painlessly installs the OS diff --git a/scripts/install.nix b/scripts/install.nix @@ -0,0 +1,160 @@ +{ + lib, + pkgs, + files, + ... +}: +with files.path; let + inherit (lib) licenses recursiveUpdate; + + # File System Operations + partitions = '' + partition_disk() { + read -rp "Enter Path to Disk: /dev/" DISK + if [ -z "$DISK" ] + then + error "Path to Disk cannot be empty. If unsure, use the command 'fdisk -l'" + fi + echo "Creating Partitions..." + parted /dev/"$DISK" -- mkpart ESP fat32 1MiB 1024MiB + parted /dev/"$DISK" -- set 1 esp on + parted /dev/"$DISK" -- name 1 ESP + mkfs.fat -F 32 /dev/disk/by-partlabel/ESP + + parted /dev/"$DISK" -- mkpart primary 1025MiB -8GiB + parted /dev/"$DISK" -- name 2 System + + parted /dev/"$DISK" -- mkpart primary linux-swap -8GiB 100% + parted /dev/"$DISK" -- name 3 swap + mkswap /dev/disk/by-partlabel/swap + + mkdir -p /mnt + } + + create_ext4() { + echo "Creating 'EXT4' Partition..." + mkfs.ext4 /dev/disk/by-partlabel/System + } + + mount_ext4() { + echo "Mounting 'EXT4' Partition..." + mount /dev/disk/by-partlabel/System /mnt + } + + create_zfs() { + echo "Creating 'ZFS' Volumes..." + read -rp "Enter Password for Pool Encryption: " PASS + echo "$PASS" | zpool create -f fspool -O compression=zstd -O encryption=on -O keyformat=passphrase /dev/disk/by-partlabel/System + + zfs create -p -o mountpoint=legacy -o xattr=sa -o acltype=posixacl fspool/system/root + zfs snapshot fspool/system/root@blank + zfs create -o mountpoint=legacy -o atime=off fspool/system/nix + + zfs create -p -o mountpoint=legacy -o xattr=sa -o acltype=posixacl -o com.sun:auto-snapshot=true fspool/data + + # Use 'zfs set refreservation=none fspool/reserve' to free space + zfs create -o canmount=off -o refreservation=1G fspool/reserve + } + + mount_zfs() { + echo "Mounting 'ZFS' Volumes..." + zpool import -f fspool + mount -t zfs fspool/system/root /mnt + mkdir -p /mnt/{nix,data} + mount -t zfs fspool/system/nix /mnt/nix + mount -t zfs fspool/data /mnt/data + } + + mount_other() { + echo "Mounting Other Partitions..." + mkdir -p /mnt/boot + mount -t vfat /dev/disk/by-partlabel/ESP /mnt/boot + swapoff --all + swapon /dev/disk/by-partlabel/swap + } + + unmount_all () { + echo "Unmounting All Partitions..." + umount -l /mnt + zpool export fspool + } + ''; +in + recursiveUpdate { + meta = { + description = "System Install Script"; + homepage = repo; + license = licenses.mit; + maintainers = ["maydayv7"]; + }; + } (pkgs.writeShellApplication { + name = "os-install"; + runtimeInputs = with pkgs; [ + coreutils + dosfstools + git + gparted + nixFlakes + ntfs3g + parted + util-linux + zfs + ]; + + text = '' + set +eu + ${files.scripts.commands} + ${partitions} + + internet + if [ "$EUID" -ne 0 ] + then + error "This Command must be Executed as 'root'" + fi + + read -rp "Enter Name of Device to Install: " HOST + read -rp "Do you want to Automatically Create the Partitions? (Y/N): " choice + case $choice in + [Yy]*) warn "Assuming Disk is Completely Empty"; partition_disk;; + *) warn "You must Create, Format and Label the Partitions on your own"; gparted &> /dev/null;; + esac + newline + read -rp "Select Filesystem to use for Disk (simple/advanced): " choice + case $choice in + 1|[Ss]*) + read -rp "Do you want to Create and Format the EXT4 Partitions? (Y/N): " choice + case $choice in + [Yy]*) create_ext4; mount_ext4;; + *) warn "Assuming that Required EXT4 Partition has already been Created"; mount_ext4;; + esac + ;; + 2|[Aa]*) + read -rp "Do you want to Create the ZFS Pool and Datasets? (Y/N): " choice + case $choice in + [Yy]*) create_zfs; mount_zfs;; + *) warn "Assuming that Required ZFS Pool and Datasets have already been Created"; mount_zfs;; + esac + ;; + *) error "Choose (1)simple or (2)advanced";; + esac + newline + + mount_other + newline + + read -rp "Enter Path to Repository (path/URL): " URL + if [ -z "$URL" ] + then + URL=${flake} + fi + echo "Installing System from '$URL'..." + nixos-install --no-root-passwd --root /mnt --flake "$URL"#"$HOST" + newline + + unmount_all + newline + + info "Run 'nixos setup' after rebooting to finish the install" + restart + ''; + }) diff --git a/scripts/nixos.nix b/scripts/nixos.nix @@ -30,7 +30,6 @@ with files; let check [ --trace ] - Checks System Configuration [ Displays Error to Trace ] clean [ --all ] - Garbage Collects and Optimises Nix Store explore - Opens Interactive Shell to explore Syntax and Configuration - install - Installs NixOS onto System iso 'variant' [ --burn ] - Builds Image for Specified Install Media or Device [ Burns '.iso' to USB ] list [ 'pattern' ] - Lists all Installed Packages [ Returns Matches ] locate 'package' - Locates Installed Package @@ -38,6 +37,7 @@ with files; let save - Saves Configuration State to Repository search 'term' [ 'source' ] - Searches for Packages [ Providing 'term' ] or Configuration Options secret 'choice' [ 'path' ] - Manages 'sops' Encrypted Secrets + setup - Sets up NixOS System (on First Boot) shell [ 'name' ] - Opens desired Nix Developer Shell update [ 'repo' / --'option' ] - Manages System Package Updates ''; @@ -92,22 +92,18 @@ in git gnupg gnused - gparted jq manix nixFlakes nvd - parted sops tree wine.mkwindowsapp-tools - zfs ]; text = '' set +eu ${scripts.commands} - ${scripts.partitions} if [[ -n $IN_NIX_SHELL ]] then @@ -117,7 +113,7 @@ in case $1 in "") error "Expected an Option" "${usage.script}";; help|--help|-h) echo -e "## Tool for NixOS System Management ##\n${usage.script}";; - apply) + "apply") case $2 in help|--help|-h) echo "${usage.apply}";; "") @@ -162,7 +158,7 @@ in echo "Applying Rollback..." sudo nixos-rebuild switch --rollback ;; - list) + "list") echo "# System Generations #" nixos-rebuild list-generations ;; @@ -175,7 +171,7 @@ in *) error "Unknown Option '$2'" "${usage.apply}";; esac ;; - cache) + "cache") if [ -z "$2" ] then error "Expected a Build Command" @@ -185,7 +181,7 @@ in cachix watch-exec ${path.cache} "''${@:2}" fi ;; - check) + "check") echo "Formatting Code..." pushd ${path.system} &> /dev/null; nix fmt; popd &> /dev/null case $2 in @@ -194,7 +190,7 @@ in *) nix flake check "$2" --keep-going;; esac ;; - clean) + "clean") echo "Running Garbage Collection..." mkwindows-tools-gc nix-collect-garbage -d @@ -212,100 +208,13 @@ in echo "Running De-Duplication..." nix store optimise ;; - explore) + "explore") case $2 in "") nix repl --arg host true --arg path ${path.system} --file ${repl};; *) nix repl --arg path "$(readlink -f "$2" | sed 's|/flake.nix||')" --file ${repl};; esac ;; - install) - case $2 in - "--first-boot") - if [ -d ${persist} ]; then - DIR=${persist}${path.system} - else - DIR=${path.system} - fi - - echo "Cloning Repository..." - git clone --recurse-submodules ${path.repo} "$DIR" - pushd "$DIR" &> /dev/null; git config core.fileMode false; popd &> /dev/null - newline - - read -rp "Enter Path to GPG Keys (path/.git): " KEY - LINK='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' - if [ -z "$KEY" ] - then - error "Path to GPG Keys cannot be empty" - elif [[ $KEY =~ $LINK ]] - then - echo "Cloning Keys..." - git clone "$KEY" keys --progress - else - cp -r "$KEY"/. ./keys - fi - echo "Importing Keys..." - find ./keys -name '*.gpg' -exec gpg --homedir ${files.gpg} --import {} \+ - rm -rf ./keys - newline - - nixos apply --activate - ;; - "") - internet - if [ "$EUID" -ne 0 ] - then - error "This Command must be Executed as 'root'" - fi - - read -rp "Enter Name of Device to Install: " HOST - read -rp "Do you want to Automatically Create the Partitions? (Y/N): " choice - case $choice in - [Yy]*) warn "Assuming Disk is Completely Empty"; partition_disk;; - *) warn "You must Create, Format and Label the Partitions on your own"; gparted &> /dev/null;; - esac - newline - read -rp "Select Filesystem to use for Disk (simple/advanced): " choice - case $choice in - 1|[Ss]*) - read -rp "Do you want to Create and Format the EXT4 Partitions? (Y/N): " choice - case $choice in - [Yy]*) DIR=${path.system}; create_ext4; mount_ext4;; - *) warn "Assuming that Required EXT4 Partition has already been Created"; mount_ext4;; - esac - ;; - 2|[Aa]*) - read -rp "Do you want to Create the ZFS Pool and Datasets? (Y/N): " choice - case $choice in - [Yy]*) DIR=${persist}${path.system}; create_zfs; mount_zfs;; - *) warn "Assuming that Required ZFS Pool and Datasets have already been Created"; mount_zfs;; - esac - ;; - *) error "Choose (1)simple or (2)advanced";; - esac - newline - - mount_other - newline - - read -rp "Enter Path to Repository (path/URL): " URL - if [ -z "$URL" ] - then - URL=${path.flake} - fi - echo "Installing System from '$URL'..." - nixos-install --no-root-passwd --root /mnt --flake "$URL"#"$HOST" - newline - - unmount_all - newline - - info "Run 'nixos install --first-boot' after rebooting to finish the install" - restart - ;; - esac - ;; - iso) + "iso") case $2 in "") error "Expected a Variant of Install Media or Device";; *) @@ -389,7 +298,7 @@ in ;; esac ;; - run) + "run") if [[ "$2" == *[:/]* ]] || grep -wq "$2" <<<"${list inputs + "nixpkgs"}" then nix run "$2"#"$3" -- "''${@:4}" @@ -397,7 +306,7 @@ in nix run ${path.system}#"$2" -- "''${@:3}" fi ;; - save) + "save") echo "Saving Changes..." pushd ${path.system} &> /dev/null git stash @@ -410,7 +319,7 @@ in git push --set-upstream origin save --force popd &> /dev/null ;; - search) + "search") case $2 in "") error "Expected an Option" "${usage.search}";; help|--help|-h) echo "${usage.search}";; @@ -441,11 +350,11 @@ in ;; esac ;; - secret) + "secret") case $2 in "") error "Expected an Option" "${usage.secret}";; help|--help|-h) echo "${usage.secret}";; - create) + "create") case $3 in "") error "Expected 'name' of Secret";; *) @@ -454,7 +363,7 @@ in ;; esac ;; - edit) + "edit") case $3 in "") error "Expected 'name' of Secret";; *) @@ -468,11 +377,11 @@ in ;; esac ;; - list) + "list") echo "## Secrets in ${path.system} ##" grep / ${sops} | sed -e 's|- path_regex:||' -e 's/\/\.\*\$//' -e 's| |${path.system}/|' | xargs tree -C --noreport -P '*.secret' -I '_*' | sed 's/\.secret//' ;; - show) + "show") if find ${path.system} -name "$3".secret | grep "secret" &> /dev/null then echo "Showing Secret '$3'..." @@ -481,14 +390,45 @@ in error "Unknown Secret '$3'" fi ;; - update) + "update") echo "Updating Secrets..." find ${path.system} -name '*.secret' ! -name '_*' -exec sops --config ${sops} updatekeys {} \; ;; *) error "Unknown Option '$2'" "${usage.secret}";; esac ;; - shell) + "setup") + if [ -d ${path.persist} ]; then + DIR=${path.persist}${path.system} + else + DIR=${path.system} + fi + + echo "Cloning Repository..." + git clone --recurse-submodules ${path.repo} "$DIR" + pushd "$DIR" &> /dev/null; git config core.fileMode false; popd &> /dev/null + newline + + read -rp "Enter Path to GPG Keys (path/.git): " KEY + LINK='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' + if [ -z "$KEY" ] + then + error "Path to GPG Keys cannot be empty" + elif [[ $KEY =~ $LINK ]] + then + echo "Cloning Keys..." + git clone "$KEY" keys --progress + else + cp -r "$KEY"/. ./keys + fi + echo "Importing Keys..." + find ./keys -name '*.gpg' -exec gpg --homedir ${files.gpg} --import {} \+ + rm -rf ./keys + newline + + nixos apply --activate + ;; + "shell") case $2 in "") nix develop ${path.system} --command "$SHELL";; *) @@ -501,7 +441,7 @@ in ;; esac ;; - update) + "update") case $2 in help|--help|-h) echo "${usage.update}";; "--pkgs") diff --git a/scripts/partitions.sh b/scripts/partitions.sh @@ -1,67 +0,0 @@ -#! /usr/bin/env nix -#! nix shell nixpkgs#bash nixpkgs#dosfstools nixpkgs#ntfs3g nixpkgs#parted nixpkgs#util-linux nixpkgs#zfs -c bash - -# Script to automatically Create, Label, Format and Mount Partitions # - -partition_disk() { - read -rp "Enter Path to Disk: /dev/" DISK - if [ -z "$DISK" ] - then - error "Path to Disk cannot be empty. If unsure, use the command 'fdisk -l'" - fi - echo "Creating Partitions..." - parted /dev/"$DISK" -- mkpart ESP fat32 1MiB 1024MiB - parted /dev/"$DISK" -- set 1 esp on - parted /dev/"$DISK" -- name 1 ESP - mkfs.fat -F 32 /dev/disk/by-partlabel/ESP - parted /dev/"$DISK" -- mkpart primary 1025MiB -8GiB - parted /dev/"$DISK" -- name 2 System - parted /dev/"$DISK" -- mkpart primary linux-swap -8GiB 100% - parted /dev/"$DISK" -- name 3 swap - mkswap /dev/disk/by-partlabel/swap - mkdir -p /mnt -} - -create_ext4() { - echo "Creating 'EXT4' Partition..." - mkfs.ext4 /dev/disk/by-partlabel/System -} - -mount_ext4() { - echo "Mounting 'EXT4' Partition..." - mount /dev/disk/by-partlabel/System /mnt -} - -create_zfs() { - echo "Creating 'ZFS' Volumes..." - read -rp "Enter Password for Pool Encryption: " PASS - echo "$PASS" | zpool create -f fspool -O compression=zstd -O encryption=on -O keyformat=passphrase /dev/disk/by-partlabel/System - zfs create -p -o mountpoint=legacy -o xattr=sa -o acltype=posixacl fspool/system/root - zfs snapshot fspool/system/root@blank - zfs create -o mountpoint=legacy -o atime=off fspool/system/nix - zfs create -p -o mountpoint=legacy -o xattr=sa -o acltype=posixacl -o com.sun:auto-snapshot=true fspool/data - zfs create -o canmount=off -o refreservation=1G fspool/reserve # Use 'zfs set refreservation=none fspool/reserve' to free space -} - -mount_zfs() { - echo "Mounting 'ZFS' Volumes..." - zpool import -f fspool - mount -t zfs fspool/system/root /mnt - mkdir -p /mnt/{nix,data} - mount -t zfs fspool/system/nix /mnt/nix - mount -t zfs fspool/data /mnt/data -} - -mount_other() { - echo "Mounting Other Partitions..." - mkdir -p /mnt/boot - mount -t vfat /dev/disk/by-partlabel/ESP /mnt/boot - swapoff --all - swapon /dev/disk/by-partlabel/swap -} - -unmount_all () { - echo "Unmounting All Partitions..." - umount -l /mnt - zpool export fspool -}