-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelusive-generate-base
executable file
·59 lines (49 loc) · 1.33 KB
/
elusive-generate-base
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
55
56
57
58
#!/usr/bin/env nix-shell
#!nix-shell -p zsh qemu -i zsh
# vim: ft=zsh
set -euo pipefail
. util
# note that these are symlinks to *directories*
# the actual images are called base.qcow2 in there
current="$gcroots/elusive"
new="$gcroots/elusive-new"
# idea:
# 1. generate the image and symlink to $new
# 2. rebase from $(readlink $current) to $(readlink $new)
# 3. move $new to $current
state="$state_local/elusive"
# step 1
begin building image
hint "might take some time, but it's worth it"
hint compression makes the final base image small and cute
nix-build \
--option allowed-uris https://static.rust-lang.org/dist/ \
--out-link "$new" \
"$config/nixos/elusive" \
$@
# step 2
# need to do so only iff all off these apply:
#
# - there is an old image
# - there's any overlays
#
# otherwise there's nothing qemu could rebase
if [[ -h $current && -d $state && -n "$(ls $state)" ]]; then
begin rebasing images
for project in $state/*; do
part $project
qemu-img rebase \
-p \
-b "$(readlink $new)/base.qcow2" -F qcow2 \
"$project/overlay.qcow2"
done
elif [[ ! -d $state || -z "$(ls $state)" ]]; then
cancel "rebasing skipped: no overlays to rebase"
else
cancel "rebasing skipped: no old image to rebase from"
fi
# step 3
begin replacing current image
rm $current
mv $new $current
complete generation finished