-
Notifications
You must be signed in to change notification settings - Fork 0
/
installnix.sh
68 lines (53 loc) · 1.87 KB
/
installnix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# Set the device name of the disk to install on
DISK=/dev/nvme0n1
BOOTPART=${DISK}p1
DATAPART=${DISK}p2
# Set the passphrase for the encryption
PASSPHRASE="secret"
# Set ZFS pool and datasets
ZFS_POOL="nixos_pool"
ZFS_HOME_DATASET="$ZFS_POOL/home"
ZFS_NIX_DATASET="$ZFS_POOL/nix"
ZFS_PERSIST_DATASET="$ZFS_POOL/persist"
# Wipe anything that was left behind
echo "WARNING: wiping ${DISK}"
wipefs --all --force ${DISK}*
# Create the EFI partition
echo "Creating EFI partition..."
parted -s $DISK mklabel gpt
parted -s $DISK mkpart primary fat32 1MiB 1024MiB
parted -s $DISK set 1 esp on
# Create the boot partition
echo "Formatting boot partition..."
mkfs.fat -F 32 -n boot $BOOTPART
# Create the ZFS pool
echo "Creating ZFS pool with native encryption..."
echo $PASSPHRASE | zpool create -O mountpoint=none -O encryption=aes-256-gcm -O keyformat=passphrase -O keylocation=prompt $ZFS_POOL $DATAPART
# Create ZFS datasets
echo "Creating ZFS datasets..."
# Stores persistent data
zfs create $ZFS_PERSIST_DATASET -o atime=off -o compression=zstd
# Stores required packages etc
zfs create $ZFS_NIX_DATASET-o atime=off -o compression=zstd
# Home directory for system
zfs create $ZFS_HOME_DATASET -o atime=off -o compression=zstd
mkdir -p /mnt
# Mount datasets
mkdir /mnt/home
mount -t zfs $ZFS_HOME_DATASET /mnt/home
mkdir /mnt/nix
mount -t zfs $ZFS_NIX_DATASET /mnt/nix
mkdir /mnt/persist
mount -t zfs $ZFS_PERSIST_DATASET /mnt/persist
# Mount the EFI partition
echo "Mounting /boot..."
mkdir -p /mnt/boot/efi
mount $BOOTPART /mnt/boot/efi
# Generate a basic NixOS configuration
echo "Generating config..."
nixos-generate-config --root /mnt
# Create the necessary subdirs in /persist
echo "Creating /persist subdirectories..."
mkdir -p /mnt/persist/communication /mnt/persist/gaming /mnt/persist/sensitive /mnt/persist/system /mnt/persist/dotfiles
echo "Done, paste in configuration"