about summary refs log tree commit diff
path: root/run
blob: 9d890c4848c355106b6ffa4cf4d27d786c8f6480 (plain) (blame)
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
#!/run/current-system/sw/bin/bash
# SPDX-FileCopyrightText: 2022-2023 Alyssa Ross <hi@alyssa.is>
# SPDX-License-Identifier: EUPL-1.2+
#
# Swap setup adapted from swap-to-disk.nix, from commit
# 8796bc3006917c14b6c5e383d6ae706d08a5e48e of
# <https://github.com/DeterminateSystems/nix-netboot-serve>:
# SPDX-FileCopyrightText: Determinate Systems
# SPDX-License-Identifier: MIT

set -uexo pipefail
export PATH=/run/wrappers/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin

cryptsetup open -d /dev/random --type plain /dev/vda swap
mkswap /dev/mapper/swap
swapon /dev/mapper/swap

size=$(lsblk --noheadings --bytes --output SIZE /dev/mapper/swap)
pagesize=$(getconf PAGESIZE)
inodes=$((size / pagesize))
mount -o remount,size="$size",nr_inodes="$inodes" /

for o in $(</proc/cmdline); do
	case $o in
		configuration=*)
			configuration="${o#configuration=}"
			;;
		userdata=*)
			userdata="${o#userdata=}"
			;;
	esac
done

systemctl start network-online.target

# --ignore-garbage because provider might e.g. insert carriage returns.
curl -fLsS --retry-all-errors --retry 5 "$userdata" | base64 -d --ignore-garbage > user-data.tar.zst
tar -Pxvf user-data.tar.zst
rm user-data.tar.zst
curl -fLsSo /tmp/spectrum-main.tar.gz https://spectrum-os.org/git/spectrum/snapshot/spectrum-main.tar.gz
tar -C /tmp -xf /tmp/spectrum-main.tar.gz

curl -fLsSo /etc/nixos/configuration.nix "$configuration"
systemctl start dbus.socket
nixos-rebuild switch -I nixos-config=/etc/nixos/configuration.nix \
	--show-trace \
	-I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos
systemctl start --no-block multi-user.target systemd-journal-gatewayd.socket

exec systemd-run --wait -u nix-build \
	-p Restart=on-failure \
	-p StartLimitBurst=5 \
	-p StartLimitIntervalSec=1d \
	nix-build --keep-going /tmp/spectrum-main/release.nix