forked from arianvp/nixos-vultr-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·47 lines (35 loc) · 1.22 KB
/
bootstrap.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
#! /bin/sh
# Create partition table
parted /dev/vda --script -- mklabel msdos
# Create 1G boot partition
parted /dev/vda --script -- mkpart primary ext4 2048s 1G
# Make rest of it one partition
parted /dev/vda --script -- mkpart primary btrfs 1G 100%
# Encrypt it with given passphrase
echo -n verysecure | cryptsetup luksFormat /dev/vda2 -
# Open the encrypted disk
echo -n verysecure | cryptsetup luksOpen /dev/vda2 rootPartition -
# Create VG out of encrypted partition
vgcreate nixvg /dev/mapper/rootPartition
# Define 1G swap partition
lvcreate -L 1G -n swap nixvg
# Make rest of the disk single partition
lvcreate -l '100%FREE' -n root nixvg
# Format and enable the swap
mkswap /dev/nixvg/swap
swapon /dev/nixvg/swap
# Format the root disk as btrfs and mount it
mkfs.btrfs -L nixos /dev/nixvg/root
mount /dev/nixvg/root /mnt
# Format the boot partition as ext4
mkfs.ext4 /dev/vda1
# Create boot directory and mount boot partition
mkdir /mnt/boot
mount /dev/vda1 /mnt/boot
# Generate the configuration. We'll use the hardware config.
nixos-generate-config --root /mnt
# Put our configs :)
cp ./configuration.nix /mnt/etc/nixos/configuration.nix
cp ./luks-configuration.nix /mnt/etc/nixos/luks-configuration.nix
# And ...
nixos-install