diff --git a/pkgs/min-copy-closure/liminix-rebuild.sh b/pkgs/min-copy-closure/liminix-rebuild.sh index 5dda92c..16ec7f1 100755 --- a/pkgs/min-copy-closure/liminix-rebuild.sh +++ b/pkgs/min-copy-closure/liminix-rebuild.sh @@ -2,12 +2,18 @@ ssh_command=${SSH_COMMAND-ssh} -if [ "$1" = "--no-reboot" ] ; then - reboot="true" - shift -else - reboot="reboot" -fi +reboot="reboot" + +case "$1" in + "--no-reboot") + unset reboot + shift + ;; + "--fast") + reboot="soft" + shift + ;; +esac target_host=$1 shift @@ -21,7 +27,16 @@ if toplevel=$(nix-build "$@" -A outputs.systemConfiguration --no-out-link); then echo systemConfiguration $toplevel min-copy-closure $target_host $toplevel $ssh_command $target_host $toplevel/bin/install - $ssh_command $target_host "sync; source /etc/profile; reboot" + case "$reboot" in + reboot) + $ssh_command $target_host "sync; source /etc/profile; reboot" + ;; + soft) + $ssh_command $target_host $toplevel/bin/restart-services + ;; + *) + ;; + esac else echo Rebuild failed fi diff --git a/pkgs/s6-rc-database/default.nix b/pkgs/s6-rc-database/default.nix index 9983bbf..1fabe41 100644 --- a/pkgs/s6-rc-database/default.nix +++ b/pkgs/s6-rc-database/default.nix @@ -21,11 +21,22 @@ in stdenvNoCC.mkDerivation { if test -d $i; then for j in $i/* ; do if test -f $j/type ; then + case $(cat $j/type) in + longrun|oneshot) + # s6-rc-update only wants oneshots in its + # restarts file + echo $(basename $j) " " $i >> $out/hashes + ;; + *) + ;; + esac srcs="$srcs $i" fi done fi done s6-rc-compile $out/compiled $srcs - ''; - } + s6-rc-db -c $out/compiled contents default + mv $out/hashes $out/compiled + ''; +} diff --git a/pkgs/systemconfig/default.nix b/pkgs/systemconfig/default.nix index f6f38b1..f6a6f9d 100644 --- a/pkgs/systemconfig/default.nix +++ b/pkgs/systemconfig/default.nix @@ -6,6 +6,7 @@ { writeText +, writeFennelScript , lib , s6-init-bin , closureInfo @@ -52,7 +53,7 @@ let chown = if uid>0 || gid>0 then "\nCHOWN(${qpathname},${toString uid},${toString gid});\n" else ""; - in "${cmd} ${chown}"; + in "unlink(${qpathname}); ${cmd} ${chown}"; in mapAttrsToList (makeFile prefix) attrset; activateScript = attrset: writeText "makedevs.c" '' #include "defs.h" @@ -80,6 +81,7 @@ in attrset: cp $closure/store-paths $out/etc/nix-store-paths $STRIP --remove-section=.note --remove-section=.comment --strip-all makedevs -o $out/bin/activate ln -s ${s6-init-bin}/bin/init $out/bin/init + cp -p ${writeFennelScript "restart-services" [] ./restart-services.fnl} $out/bin/restart-services cat > $out/bin/install < rootfs -truncate -s 24M rootfs +truncate -s 32M rootfs resize2fs rootfs dd if=rootfs of=disk-image bs=512 seek=4 conv=sync @@ -51,9 +62,12 @@ echo "READY" touch known_hosts export SSH_COMMAND="ssh -o UserKnownHostsFile=${work}/known_hosts -o StrictHostKeyChecking=no -p 2022 -i ${here}/id" -(cd ${top} && liminix-rebuild root@localhost -I liminix-config=${here}/with-figlet.nix --arg device "import ./devices/qemu-armv7l") +if test -n "$FAST"; then + (cd ${top} && liminix-rebuild --fast root@localhost -I liminix-config=${here}/with-figlet.nix --argstr deviceName qemu-armv7l) + cd ${work} && expect $here/wait-for-soft-restart.expect +else + (cd ${top} && liminix-rebuild root@localhost -I liminix-config=${here}/with-figlet.nix --arg device "import ./devices/qemu-armv7l") + cd ${work} && expect $here/wait-for-reboot.expect +fi -ls -l vm - -cd ${work} && expect $here/wait-for-reboot.expect cd / ; rm -rf $work diff --git a/tests/min-copy-closure/wait-for-soft-restart.expect b/tests/min-copy-closure/wait-for-soft-restart.expect new file mode 100644 index 0000000..381f7a2 --- /dev/null +++ b/tests/min-copy-closure/wait-for-soft-restart.expect @@ -0,0 +1,13 @@ +proc chat {instr outstr} { + expect { + $instr { send $outstr } + timeout { exit 1 } + } +} +spawn socat unix-connect:vm/console - + +send "exit\r" +chat "BusyBox" "\r" +chat "#" "stty -echo; type -p figlet\r" +chat "figlet-armv7l-unknown-linux" "s6-rc -a list |grep w\\inkle\r" +chat "winkle" "poweroff\r" diff --git a/tests/min-copy-closure/with-figlet.nix b/tests/min-copy-closure/with-figlet.nix index 5614d92..09ec47c 100644 --- a/tests/min-copy-closure/with-figlet.nix +++ b/tests/min-copy-closure/with-figlet.nix @@ -4,4 +4,11 @@ defaultProfile.packages = with pkgs; [ figlet ]; + services.ripvanwinkle = pkgs.liminix.services.longrun { + name = "winkle"; + run = '' + echo SLEEPING > /dev/console + sleep 3600 + ''; + }; }