2006-11-24 00:22:43 +01:00
|
|
|
#! @bash@/bin/sh -e
|
|
|
|
|
2007-12-25 17:07:55 +01:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2006-12-10 23:29:44 +01:00
|
|
|
export PATH=/empty
|
|
|
|
for i in @path@; do PATH=$PATH:$i/bin; done
|
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
default=$1
|
|
|
|
if test -z "$1"; then
|
|
|
|
echo "Syntax: grub-menu-builder.sh <DEFAULT-CONFIG>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2008-01-09 06:36:40 +01:00
|
|
|
bootMount="@bootMount@"
|
2008-01-04 16:02:31 +01:00
|
|
|
if test -z "$bootMount"; then bootMount=/boot; fi
|
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
|
|
|
|
target=/boot/grub/menu.lst
|
|
|
|
tmp=$target.tmp
|
|
|
|
|
|
|
|
cat > $tmp << GRUBEND
|
|
|
|
# Automatically generated. DO NOT EDIT THIS FILE!
|
2008-01-04 16:02:31 +01:00
|
|
|
default 0
|
|
|
|
timeout 5
|
2006-11-24 00:22:43 +01:00
|
|
|
GRUBEND
|
|
|
|
|
2007-02-09 17:19:29 +01:00
|
|
|
|
2008-01-04 16:02:31 +01:00
|
|
|
if test -n "@grubSplashImage@"; then
|
|
|
|
splashLocation=@grubSplashImage@
|
|
|
|
# !!! image in /nix/store doesn't seem to work
|
|
|
|
#if test -n "@copyKernels@"; then
|
|
|
|
cp -f $splashLocation /boot/background.xpm.gz
|
2008-01-09 06:36:40 +01:00
|
|
|
splashLocation="$bootMount/background.xpm.gz"
|
2008-01-04 16:02:31 +01:00
|
|
|
#fi
|
|
|
|
echo "splashimage $splashLocation" >> $tmp
|
|
|
|
fi
|
|
|
|
|
2008-01-10 13:28:01 +01:00
|
|
|
configurationCounter=0
|
|
|
|
configurationLimit="@configurationLimit@"
|
|
|
|
numAlienEntries=$(cat <<EOF | egrep '^[[:space:]]*title' | wc -l
|
|
|
|
@extraGrubEntries@
|
|
|
|
EOF)
|
|
|
|
|
|
|
|
if test $((configurationLimit+numAlienEntries)) -gt 190; then
|
|
|
|
configurationLimit=$((190-numAlienEntries));
|
|
|
|
fi
|
2007-02-09 17:19:29 +01:00
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
addEntry() {
|
2007-02-09 17:19:29 +01:00
|
|
|
local name="$1"
|
|
|
|
local path="$2"
|
2007-06-23 18:09:05 +02:00
|
|
|
local shortSuffix="$3"
|
2006-11-24 00:22:43 +01:00
|
|
|
|
2008-01-10 05:43:19 +01:00
|
|
|
configurationCounter=$((configurationCounter + 1))
|
|
|
|
if test $configurationCounter -gt @configurationLimit@ ; then
|
|
|
|
return
|
|
|
|
fi;
|
|
|
|
|
2007-02-09 17:19:29 +01:00
|
|
|
if ! test -e $path/kernel -a -e $path/initrd; then
|
2006-12-11 18:36:57 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2007-02-09 17:19:29 +01:00
|
|
|
local kernel=$(readlink -f $path/kernel)
|
|
|
|
local initrd=$(readlink -f $path/initrd)
|
|
|
|
|
2008-01-10 05:43:19 +01:00
|
|
|
if test "$path" = "$default"; then
|
|
|
|
cp "$kernel" /boot/nixos-kernel
|
|
|
|
cp "$initrd" /boot/nixos-initrd
|
|
|
|
cp "$(readlink -f "$path/init")" /boot/nixos-init
|
|
|
|
cat > /boot/nixos-grub-config <<EOF
|
2008-01-10 06:50:58 +01:00
|
|
|
title Emergency boot
|
|
|
|
kernel ${bootMount:-/boot}/nixos-kernel systemConfig=$(readlink -f "$path") init=/boot/nixos-init $(cat "$path/kernel-params")
|
2008-01-10 05:43:19 +01:00
|
|
|
initrd ${bootMount:-/boot}/nixos-initrd
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2007-02-09 17:19:29 +01:00
|
|
|
if test -n "@copyKernels@"; then
|
|
|
|
local kernel2=/boot/kernels/$(echo $kernel | sed 's^/^-^g')
|
|
|
|
if ! test -e $kernel2; then
|
|
|
|
cp $kernel $kernel2
|
|
|
|
fi
|
|
|
|
kernel=$kernel2
|
|
|
|
|
|
|
|
local initrd2=/boot/kernels/$(echo $initrd | sed 's^/^-^g')
|
|
|
|
if ! test -e $initrd2; then
|
|
|
|
cp $initrd $initrd2
|
|
|
|
fi
|
|
|
|
initrd=$initrd2
|
2007-12-16 19:56:36 +01:00
|
|
|
|
2008-01-04 16:02:31 +01:00
|
|
|
if test -n "$bootMount"; then
|
|
|
|
kernel=$(echo $kernel2 | sed -e "s^/boot^$bootMount^")
|
|
|
|
initrd=$(echo $initrd2 | sed -e "s^/boot^$bootMount^")
|
2007-12-16 19:56:36 +01:00
|
|
|
fi
|
2007-02-09 17:19:29 +01:00
|
|
|
fi
|
|
|
|
|
2007-06-23 18:09:05 +02:00
|
|
|
local confName=$(if test -e $path/configuration-name; then
|
|
|
|
cat $path/configuration-name;
|
|
|
|
fi);
|
|
|
|
if test -n "$confName" ; then
|
|
|
|
name="$confName $3";
|
|
|
|
fi;
|
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
cat >> $tmp << GRUBEND
|
2008-01-04 16:02:31 +01:00
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
title $name
|
2007-03-20 14:01:53 +01:00
|
|
|
kernel $kernel systemConfig=$(readlink -f $path) init=$(readlink -f $path/init) $(cat $path/kernel-params)
|
2007-02-09 17:19:29 +01:00
|
|
|
initrd $initrd
|
2006-11-24 00:22:43 +01:00
|
|
|
GRUBEND
|
2007-02-09 17:19:29 +01:00
|
|
|
}
|
2006-11-24 00:22:43 +01:00
|
|
|
|
|
|
|
|
2007-02-09 17:19:29 +01:00
|
|
|
rm -rf /boot/kernels
|
|
|
|
if test -n "@copyKernels@"; then
|
|
|
|
mkdir -p /boot/kernels
|
|
|
|
fi
|
2006-11-24 00:22:43 +01:00
|
|
|
|
2007-06-15 13:40:57 +02:00
|
|
|
# Additional entries specified verbatim by the configuration.
|
2008-07-23 11:10:19 +02:00
|
|
|
extraGrubEntries=$(cat <<EOF
|
2007-06-15 13:40:57 +02:00
|
|
|
@extraGrubEntries@
|
2008-07-23 11:10:19 +02:00
|
|
|
EOF
|
|
|
|
)
|
2007-06-15 13:40:57 +02:00
|
|
|
|
2008-07-05 02:16:39 +02:00
|
|
|
if test -n "@extraGrubEntriesBeforeNixos@"; then
|
2008-07-23 11:10:19 +02:00
|
|
|
echo "$extraGrubEntries" >> $tmp
|
2008-07-05 02:16:39 +02:00
|
|
|
fi
|
|
|
|
|
2008-07-23 11:10:19 +02:00
|
|
|
addEntry "NixOS - Default" $default ""
|
2007-06-15 13:40:57 +02:00
|
|
|
|
2008-07-23 11:10:19 +02:00
|
|
|
if test -z "@extraGrubEntriesBeforeNixos@"; then
|
|
|
|
echo "$extraGrubEntries" >> $tmp
|
2008-07-05 02:16:39 +02:00
|
|
|
fi
|
2007-06-15 13:40:57 +02:00
|
|
|
|
2006-11-24 00:22:43 +01:00
|
|
|
# Add all generations of the system profile to the menu, in reverse
|
|
|
|
# (most recent to least recent) order.
|
2007-12-25 17:07:55 +01:00
|
|
|
for link in $((ls -d $default/fine-tune/* ) | sort -n); do
|
2007-12-20 12:36:30 +01:00
|
|
|
date=$(stat --printf="%y\n" $link | sed 's/\..*//')
|
|
|
|
addEntry "NixOS - variation" $link ""
|
|
|
|
done
|
2006-11-24 00:22:43 +01:00
|
|
|
for generation in $(
|
|
|
|
(cd /nix/var/nix/profiles && ls -d system-*-link) \
|
|
|
|
| sed 's/system-\([0-9]\+\)-link/\1/' \
|
|
|
|
| sort -n -r); do
|
|
|
|
echo $generation
|
2006-11-24 01:00:32 +01:00
|
|
|
link=/nix/var/nix/profiles/system-$generation-link
|
|
|
|
date=$(stat --printf="%y\n" $link | sed 's/\..*//')
|
2007-06-23 18:09:05 +02:00
|
|
|
addEntry "NixOS - Configuration $generation ($date)" $link "$generation ($date)"
|
2006-11-24 00:22:43 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
cp $tmp $target
|