This repository was archived by the owner on Oct 4, 2025. It is now read-only.
forked from matthewbauer/nixiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpixiecore.sh
More file actions
executable file
·77 lines (65 loc) · 2.53 KB
/
pixiecore.sh
File metadata and controls
executable file
·77 lines (65 loc) · 2.53 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix pixiecore jq
set -eu -o pipefail
NIXIOSK="$PWD"
if [ "$#" -gt 0 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ] ; }; then
echo Usage: "$0" nixiosk.json.sample
exit 1
fi
flake=
if [ "$#" -gt 0 ] && [ "$1" = --flake ]; then
shift
flake="${1-.#nixosConfiguration}"
if [ "$#" -gt 0 ]; then
shift
fi
fi
if [ -n "$flake" ]; then
hardware="$(nix eval --raw "$flake.config.nixiosk.hardware")"
else
custom=./nixiosk.json
if [ "$#" -gt 0 ]; then
if [ "${1:0:1}" != "-" ]; then
custom="$1"
shift
fi
fi
if ! [ -f "$custom" ]; then
echo "No custom file provided, $custom does not exist."
echo "Consult README.org for a template to use."
exit 1
fi
hardware="$(jq -r .hardware $custom)"
fi
if [ "$hardware" != "pxe" ]; then
echo "Config must set hardware to pxe"
exit 1
fi
sudo -v
pxe_ramdisk=
pxe_kernel=
system=
if [ -n "$flake" ]; then
tmpdir="$(mktemp -d)"
cleanup() {
rm -rf "$tmpdir"
}
trap cleanup EXIT
nix --experimental-features 'nix-command flakes' build "$flake.config.system.build.netbootRamdisk" --out-link $tmpdir/netboot "$@" ${NIX_OPTIONS:-}
pxe_ramdisk=$(readlink -f $tmpdir/netboot)
nix --experimental-features 'nix-command flakes' build "$flake.config.system.build.kernel" --out-link $tmpdir/kernel "$@" ${NIX_OPTIONS:-}
pxe_kernel=$(readlink -f $tmpdir/kernel)
nix --experimental-features 'nix-command flakes' build "$flake.config.system.build.toplevel" --out-link $tmpdir/system "$@" ${NIX_OPTIONS:-}
system=$(readlink -f $tmpdir/system)
else
pxe_ramdisk=$(nix-build --no-gc-warning --no-out-link \
--arg custom "builtins.fromJSON (builtins.readFile $(realpath "$custom"))" \
"$NIXIOSK/boot" -A config.system.build.netbootRamdisk "$@" ${NIX_OPTIONS:-})
pxe_kernel=$(nix-build --no-gc-warning --no-out-link \
--arg custom "builtins.fromJSON (builtins.readFile $(realpath "$custom"))" \
"$NIXIOSK/boot" -A config.system.build.kernel "$@" ${NIX_OPTIONS:-})
system=$(nix-build --no-gc-warning --no-out-link \
--arg custom "builtins.fromJSON (builtins.readFile $(realpath "$custom"))" \
"$NIXIOSK/boot" -A config.system.build.toplevel "$@" ${NIX_OPTIONS:-})
fi
sudo pixiecore boot $pxe_kernel/bzImage $pxe_ramdisk/initrd --cmdline "init=$system/init $(cat $system/kernel-params)"