Last active
October 27, 2025 18:20
-
-
Save con-f-use/82cc8d926615e778abad44cc99a1e04a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| prt:all() { | |
| prt:part "$@" | |
| prt:lvm | |
| prt:fs | |
| prt:mnt | |
| } | |
| prt:part() { | |
| local disc | |
| disc=${1:?Error: need disk device as first arg} | |
| # Note: partition 1 bios_grub is a hack so we can be compatible | |
| # ...with legacy bios AND use GPT partition tables. | |
| parted --align optimal --fix --script "$disc" \ | |
| mklabel gpt \ | |
| mkpart primary 1MB 3MB \ | |
| set 1 bios_grub on \ | |
| mkpart eps fat32 3MB 2GB \ | |
| name 2 boot \ | |
| set 2 boot on \ | |
| mkpart primary 2GB 100% \ | |
| name 3 system \ | |
| set 3 lvm on | |
| } | |
| prt:lvm() { | |
| pvcreate /dev/disk/by-partlabel/system | |
| vgcreate storage /dev/disk/by-partlabel/system | |
| lvcreate -l 100%FREE -n root storage /dev/disk/by-partlabel/system | |
| } | |
| prt:fs() { | |
| mkfs.fat -F 32 /dev/disk/by-partlabel/boot -n BOOT | |
| mkfs.btrfs /dev/storage/root -L system -f | |
| sleep 3; sync || true | |
| mount -t btrfs /dev/disk/by-label/system /mnt/ -o "$btrfsopts" | |
| btrfs subvolume create /mnt/nix | |
| btrfs subvolume create /mnt/nixos | |
| btrfs subvolume create /mnt/home | |
| btrfs subvolume create /mnt/log | |
| btrfs subvolume set-default /mnt/nixos | |
| umount /mnt/ | |
| } | |
| prt:mnt() { | |
| mount -t btrfs /dev/disk/by-label/system /mnt/ -o "$btrfsopts" | |
| mkdir -p /mnt/{var/log,nix,home,boot} | |
| chattr +i /mnt/{var/log,nix,home} | |
| mount -t btrfs /dev/disk/by-label/system /mnt/var/log -o "subvol=/log" | |
| mount -t btrfs /dev/disk/by-label/system /mnt/nix -o "subvol=/nix" | |
| mount -t btrfs /dev/disk/by-label/system /mnt/home -o "subvol=/home" | |
| mount /dev/disk/by-label/BOOT /mnt/boot | |
| } | |
| btrfsopts='autodefrag,space_cache=v2,clear_cache,compress=zstd' | |
| if [ "$0" = "${BASH_SOURCE[0]}" ]; then | |
| set -o errexit -o errtrace -o pipefail -o nounset -o xtrace | |
| cmd=${1:?Need cmd}; shift | |
| prt:"$cmd" "$@" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Corresponding
fileSystemsNixOS config: