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