-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·85 lines (61 loc) · 1.91 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·85 lines (61 loc) · 1.91 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
NIXOS_CONFIGURATION_URL=https://raw.githubusercontent.com/maxdeviant/dotfiles/master/nixos/configuration.nix
SWAP_SIZE_IN_GB=8
if [ "$EUID" -ne 0 ]; then
echo "Please run as root."
exit 1
fi
if [ -b "$1" ]; then
BLOCK_DEV=$1
if [[ $* == *--dry-run* ]]; then
RUN=echo
echo "Performing a dry run!"
else
RUN=''
fi
if [[ "$BLOCK_DEV" == *"nvme"* ]]; then
IS_NVME=1
else
IS_NVME=0
fi
echo "Preparing to install NixOS on $BLOCK_DEV..."
#
# 2.2.1. UEFI (GPT)
#
echo "Partitioning drive..."
if [ $IS_NVME -eq 1 ]; then
PARTITION_PREFIX=p
else
PARTITION_PREFIX=''
fi
$RUN parted "$BLOCK_DEV" -- mklabel gpt
$RUN parted "$BLOCK_DEV" -- mkpart primary 512MiB -${SWAP_SIZE_IN_GB}GiB
NIXOS_PARTITION="${BLOCK_DEV}${PARTITION_PREFIX}1"
$RUN parted "$BLOCK_DEV" -- mkpart primary linux-swap -${SWAP_SIZE_IN_GB}GiB 100%
SWAP_PARTITION="${BLOCK_DEV}${PARTITION_PREFIX}2"
$RUN parted "$BLOCK_DEV" -- mkpart ESP fat32 1MiB 512MiB
$RUN parted "$BLOCK_DEV" -- set 3 boot on
BOOT_PARTITION="${BLOCK_DEV}${PARTITION_PREFIX}3"
#
# 2.2.3. Formatting
#
echo "Formatting partitions..."
$RUN mkfs.ext4 -L nixos "$NIXOS_PARTITION"
$RUN mkswap -L swap "$SWAP_PARTITION"
$RUN mkfs.fat -F 32 -n boot "$BOOT_PARTITION"
#
# 2.3. Installing
#
echo "Mounting filesystems..."
$RUN mount "$NIXOS_PARTITION" /mnt
$RUN mkdir -p /mnt/boot
$RUN mount "$BOOT_PARTITION" /mnt/boot
echo "Generating default NixOS configuration..."
$RUN nixos-generate-config --root /mnt
echo "Applying NixOS configuration from $NIXOS_CONFIGURATION_URL..."
$RUN curl -o /mnt/etc/nixos/configuration.nix $NIXOS_CONFIGURATION_URL
echo "Starting the NixOS install..."
$RUN nixos-install
else
echo "Usage: $0 /dev/<BLOCK_DEV> [--dry-run]"
fi