3 # This can end up being called disregarding the shebang.
9 for i
in @path@
; do PATH
=$PATH:$i/bin
; done
12 echo "usage: $0 -c <path-to-default-configuration> [-d <boot-dir>]" >&2
16 default
= # Default configuration
17 target
=/boot
# Target directory
19 while getopts "c:d:" opt
; do
21 c
) default
="$OPTARG" ;;
22 d
) target
="$OPTARG" ;;
27 echo "updating the boot generations directory..."
31 # Convert a path to a file in the Nix store such as
32 # /nix/store/<hash>-<name>/file to <hash>-<name>-<file>.
35 echo "$path" |
sed 's|^/nix/store/||' |
sed 's|/|-|g'
38 # Copy a file from the Nix store to $target/kernels.
39 declare -A filesCopied
43 local dst
="$target/old/$(cleanName $src)"
44 # Don't copy the file if $dst already exists. This means that we
45 # have to create $dst atomically to prevent partially copied
46 # kernels or initrd if this script is ever interrupted.
47 if ! test -e $dst; then
48 local dstTmp
=$dst.tmp.$$
64 mkdir
-p $outdir || true
66 # Copy its kernel and initrd to $target/old.
71 if ! test -e $path/kernel
-a -e $path/initrd
; then
75 local kernel
=$
(readlink
-f $path/kernel
)
76 local initrd
=$
(readlink
-f $path/initrd
)
77 local dtb_path
=$
(readlink
-f $path/dtbs
)
79 if test -n "@copyKernels@"; then
80 copyToKernelsDir
$kernel; kernel
=$result
81 copyToKernelsDir
$initrd; initrd
=$result
84 echo $
(readlink
-f $path) > $outdir/$generation-system
85 echo $
(readlink
-f $path/init
) > $outdir/$generation-init
86 cp $path/kernel-params
$outdir/$generation-cmdline.txt
87 echo $initrd > $outdir/$generation-initrd
88 echo $kernel > $outdir/$generation-kernel
90 if test "$generation" = "default"; then
91 copyForced
$kernel $target/kernel.img
92 copyForced
$initrd $target/initrd
93 for dtb
in $dtb_path/{broadcom
,}/bcm
*.dtb
; do
94 dst
="$target/$(basename $dtb)"
95 copyForced
$dtb "$dst"
98 cp "$(readlink -f "$path/init
")" $target/nixos-init
99 echo "`cat $path/kernel-params` init=$path/init" >$target/cmdline.txt
103 addEntry
$default default
105 # Add all generations of the system profile to the menu, in reverse
106 # (most recent to least recent) order.
108 (cd /nix
/var
/nix
/profiles
&& ls -d system-
*-link) \
109 |
sed 's/system-\([0-9]\+\)-link/\1/' \
111 link
=/nix
/var
/nix
/profiles
/system-
$generation-link
112 addEntry
$link $generation
115 # Add the firmware files
116 fwdir
=@firmware@
/share
/raspberrypi
/boot
/
117 copyForced
$fwdir/bootcode.bin
$target/bootcode.bin
118 copyForced
$fwdir/fixup.dat
$target/fixup.dat
119 copyForced
$fwdir/fixup4.dat
$target/fixup4.dat
120 copyForced
$fwdir/fixup4cd.dat
$target/fixup4cd.dat
121 copyForced
$fwdir/fixup4db.dat
$target/fixup4db.dat
122 copyForced
$fwdir/fixup4x.dat
$target/fixup4x.dat
123 copyForced
$fwdir/fixup_cd.dat
$target/fixup_cd.dat
124 copyForced
$fwdir/fixup_db.dat
$target/fixup_db.dat
125 copyForced
$fwdir/fixup_x.dat
$target/fixup_x.dat
126 copyForced
$fwdir/start.elf
$target/start.elf
127 copyForced
$fwdir/start4.elf
$target/start4.elf
128 copyForced
$fwdir/start4cd.elf
$target/start4cd.elf
129 copyForced
$fwdir/start4db.elf
$target/start4db.elf
130 copyForced
$fwdir/start4x.elf
$target/start4x.elf
131 copyForced
$fwdir/start_cd.elf
$target/start_cd.elf
132 copyForced
$fwdir/start_db.elf
$target/start_db.elf
133 copyForced
$fwdir/start_x.elf
$target/start_x.elf
136 copyForced @configTxt@
$target/config.txt
138 # Remove obsolete files from $target and $target/old.
139 for fn
in $target/old
/*linux
* $target/old
/*initrd-initrd
* $target/bcm
*.dtb
; do
140 if ! test "${filesCopied[$fn]}" = 1; then