main
 1#! /usr/bin/env nix-shell
 2#! nix-shell -i bash -p git
 3# This scripts tries to automate the NixOS installation
 4# as much as possible.
 5# curl https://gitlab.com/vdemeester/home/-/raw/master/install.sh | sh
 6
 7set -eo pipefail
 8
 9read -p "Hostname: " name
10read -p "Disk:" disk
11read -p "Swap size (8GiB)": swap
12swap=${swap:-8GiB}
13
14echo "Partiton disk"
15set -x
16
17parted ${disk} -- mklabel gpt
18parted ${disk} -- mkpart primary 512MiB -${swap}
19parted ${disk} -- mkpart primary linux-swap -${swap} 100%
20parted ${disk} -- mkpart ESP fat32 1MiB 512MiB
21parted ${disk} -- set 3 boot on
22
23set +x
24echo "Format partiion"
25set -x
26
27mkfs.ext4 -L nixos ${disk}1
28mkswap -L swap ${disk}2
29mkfs.fat -F 32 -n boot ${disk}3
30sleep 20
31
32set +x
33echo "Mount filesystems"
34set -x
35
36mount /dev/disk/by-label/nixos /mnt
37mkdir -p /mnt/boot
38mount /dev/disk/by-label/boot /mnt/boot
39swapon ${disk}2
40
41set +x
42echo "Setup configuration"
43set -x
44
45mkdir -p /mnt/etc
46git clone --recurse-submodules https://gitlab.com/vdemeester/home.git /mnt/etc/nixos
47echo -n ${name} > /mnt/etc/nixos/hostname
48nixos-generate-config --root /mnt
49
50set +x
51echo "Run the following:"
52echo "- populate assets/ folder"
53echo "- do last minutes changes"
54echo "Once you are done, just exit the shell (C-D or exit)"
55bash || true
56
57echo "Run nixos-install"
58set -x
59nixos-install --channel $(nix eval --raw '(import /mnt/etc/nixos/nix/sources.nix).nixos.outPath') --no-channel-copy