~sircmpwn/builds.sr.ht

builds.sr.ht/images/nixos/functions -rw-r--r-- 1.2 KiB
48fa5794Dhruvin Gandhi alpine: run setup-timezone conditionally 7 days ago
                                                                                
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
#!/bin/sh
poweroff_cmd="sudo poweroff"
default_arch=x86_64

boot() {
	if [ "$arch" != "x86_64" ]
	then
		echo "Unsupported architecture $arch" >&2
		exit 1
	fi
	_boot $(cpu_opts x86_64)
}

install() {
	port=$1
	shift 1
	guest_ssh -p $port build@127.0.0.1 nix-channel --update
	guest_ssh -p $port build@127.0.0.1 nix-env -iA "$@"
}

add_repository() {
	port=$1
	name=$2
	src=$3
	shift 1
	guest_ssh -p $port build@127.0.0.1 nix-channel --add "${src}" "${name}"
	# Only update the selected channel, so we don't perform n^2 updates:
	guest_ssh -p $port build@127.0.0.1 nix-channel --update "${name}"
}

sanity_check() {
	echo "Booting..."
	cmd_boot x86_64 8022 qemu &
	trap 'cmd_cleanup 8022' EXIT
	_wait_boot 8022
	echo "Testing sudo..."
	guest_ssh -p 8022 build@127.0.0.1 sudo ls -a
	echo "Testing networking..."
	guest_ssh -p 8022 build@127.0.0.1 curl https://example.org
	echo "Testing nix..."
	add_repository 8022 nixpkgs https://nixos.org/channels/nixpkgs-unstable
	guest_ssh -p 8022 build@127.0.0.1 nix-shell -p hello --run "hello"
	echo "Testing git..."
	guest_ssh -p 8022 build@127.0.0.1 git --version
	echo "Testing mercurial..."
	guest_ssh -p 8022 build@127.0.0.1 hg --version
	echo "Everything works!"
	guest_ssh -p 8022 build@127.0.0.1 sudo poweroff || true
}