blob: 6126631490cd8754f9c14290b2c1017b5b0171f7 (
plain)
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
|
# Install NixOS on OCI
# The hostname of the to-be-installed machine.
# It's used to select the configuration.
name=example
# The IP address or domain name of the to-be-installed machine.
target=INSERT_YOUR_PUBLIC_IP_HERE
# The machine hardware name of the target machine.
# Supported values: aarch64, x86_64
machine=aarch64
kexec_tarball=$(nix-build --no-out-link '<nixpkgs/nixos>' -A config.system.build.kexec_tarball -I nixos-config=./kexec.nix)
scp $kexec_tarball/tarball/nixos-system-$machine-linux.tar.xz ubuntu@$target:/tmp/
ssh ubuntu@$target sudo tar -C / -xf /tmp/nixos-system-$machine-linux.tar.xz
ssh ubuntu@$target sudo /kexec_nixos
sed -i "/^$target /d" ~/.ssh/known_hosts
ssh root@$target
# If the VM doesn't have enough memory, add a swap device and
# increase the size of the kexec's Nix store.
if test "$(free -m | awk '/^Mem:/{print$2}')" -lt 1024; then
printf '%s\n' label:gpt ,512M,U ,4G,S ,,L | sfdisk /dev/sda
mkfs.fat -F 32 -n boot /dev/sda1
mkswap -L swap /dev/sda2
mkfs.ext4 -L root /dev/sda3
swapon /dev/disk/by-label/swap
mount -o remount,size=800M /nix/.rw-store/
else
printf '%s\n' label:gpt ,512M,U ,,L | sfdisk /dev/sda
mkfs.fat -F 32 -n boot /dev/sda1
mkfs.ext4 -L root /dev/sda2
fi
mkdir -m 0000 -p /mnt && mount /dev/disk/by-label/root /mnt
mkdir -m 0000 -p /mnt/boot && mount /dev/disk/by-label/boot /mnt/boot
nix-channel --add https://nixos.org/channels/nixos-23.05 nixpkgs
nix-channel --update
ssh root@$target mkdir -p /mnt/etc/nixos
scp "$name"/config.nix root@$target:/mnt/etc/nixos/configuration.nix
nixos-install --no-root-passwd
shutdown -r now
sed -i "/^$target /d" ~/.ssh/known_hosts
ssh root@$target
|