-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild-iso-image.sh
executable file
·53 lines (43 loc) · 1.08 KB
/
build-iso-image.sh
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
#!/usr/bin/env bash
# see also: https://nixos.mayflower.consulting/blog/2018/09/11/custom-images/
set -exuo pipefail
writeScripts() {
local outDir="$1"
local outFile="$2"
cat <<EOF | tee "$outDir/dd.sh"
#!/usr/bin/env bash
set -ex
sdX="\$1"
sudo dd if="$outFile" of="\$sdX" bs=4M conv=sync
EOF
chmod +x "$outDir/dd.sh"
cat <<EOF | tee "$outDir/run-qemu.sh"
#!/usr/bin/env bash
set -ex
qemu-kvm -boot d -cdrom "$outFile" -m 32000 -cpu host -smp 6
EOF
chmod +x "$outDir/run-qemu.sh"
}
getIsoFromOutLink() {
local iso="$1"
local outLink="$2"
local outArr
outArr=("$outLink/$iso/"*".iso")
echo "$(readlink -f "${outArr[-1]}")"
}
build() {
local iso="$1"
local outDir="../$iso"
local outLink="$outDir/result"
time nix build --out-link "$outLink" --show-trace .#myconfig-"$iso"
local out
out="$(getIsoFromOutLink "$iso" "$outLink")"
du -h "$out"
writeScripts "$outDir" "$out"
}
iso="${1:-iso}"
cd "$(dirname "${BASH_SOURCE[0]}")"
[[ -d "$HOME/myconfig/priv" ]] && cd "$HOME/myconfig/priv"
nix flake update
build "$iso"
times