diff --git a/boot/init.sh b/boot/boot.sh similarity index 65% rename from boot/init.sh rename to boot/boot.sh index e34a516c6de..3f17ea32ac0 100644 --- a/boot/init.sh +++ b/boot/boot.sh @@ -16,15 +16,4 @@ mount -n -o remount,rw /dev/root / echo "mounting /mnt/host..." mount -n -t hostfs none /mnt/host -echo "starting root shell..." - -@bash@/bin/sh - -echo "remounting / read-only..." -mount -n -o remount,rw /dev/root / || echo "(failed)" # ignore errors - -echo "syncing..." -sync || echo "(failed)" # ignore errors - -echo "shutting down..." -halt -d -f +echo "boot done." diff --git a/boot/builder.sh b/boot/builder.sh index a12da5342b1..902940dc907 100755 --- a/boot/builder.sh +++ b/boot/builder.sh @@ -5,14 +5,16 @@ mkdir $out mkdir $out/bin -sed \ - -e "s^@bash\@^$bash^g" \ - -e "s^@coreutils\@^$coreutils^g" \ - -e "s^@findutils\@^$findutils^g" \ - -e "s^@utillinux\@^$utillinux^g" \ - -e "s^@sysvinit\@^$sysvinit^g" \ - -e "s^@e2fsprogs\@^$e2fsprogs^g" \ - -e "s^@nix\@^$nix^g" \ - < $src > $out/bin/init - -chmod +x $out/bin/init +for i in $boot $halt $login; do + dst=$out/bin/$(basename $i | cut -c34-) + sed \ + -e "s^@bash\@^$bash^g" \ + -e "s^@coreutils\@^$coreutils^g" \ + -e "s^@findutils\@^$findutils^g" \ + -e "s^@utillinux\@^$utillinux^g" \ + -e "s^@sysvinit\@^$sysvinit^g" \ + -e "s^@e2fsprogs\@^$e2fsprogs^g" \ + -e "s^@nix\@^$nix^g" \ + < $i > $dst + chmod +x $dst +done \ No newline at end of file diff --git a/boot/default.nix b/boot/default.nix index c49891d593f..8f6820c5e4a 100644 --- a/boot/default.nix +++ b/boot/default.nix @@ -1,9 +1,11 @@ {stdenv, bash, coreutils, findutils, utillinux, sysvinit, e2fsprogs, nix}: derivation { - name = "init"; + name = "boot"; system = stdenv.system; builder = ./builder.sh; - src = ./init.sh; + boot = ./boot.sh; + halt = ./halt.sh; + login = ./login.sh; inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; } diff --git a/boot/halt.sh b/boot/halt.sh new file mode 100644 index 00000000000..19e89045854 --- /dev/null +++ b/boot/halt.sh @@ -0,0 +1,12 @@ +#! @bash@/bin/sh -e + +export PATH=@nix@/bin:@bash@/bin:@coreutils@/bin:@findutils@/bin:@utillinux@/bin:@utillinux@/sbin:@sysvinit@/bin:@sysvinit@/sbin:@e2fsprogs@/bin:@e2fsprogs@/sbin + +echo "remounting / read-only..." +mount -n -o remount,rw /dev/root / || echo "(failed)" # ignore errors + +echo "syncing..." +sync || echo "(failed)" # ignore errors + +echo "shutting down..." +halt -d -f diff --git a/boot/login.sh b/boot/login.sh new file mode 100644 index 00000000000..74e14b64de6 --- /dev/null +++ b/boot/login.sh @@ -0,0 +1,15 @@ +#! @bash@/bin/sh -e + +tty=$1 + +exec < $tty > $tty 2>&1 + +export PATH=@nix@/bin:@bash@/bin:@coreutils@/bin:@findutils@/bin:@utillinux@/bin:@utillinux@/sbin:@sysvinit@/bin:@sysvinit@/sbin:@e2fsprogs@/bin:@e2fsprogs@/sbin + +echo +echo "=== Welcome to Nix! ===" + +export HOME=/home/root +cd $HOME + +exec @bash@/bin/sh diff --git a/fill-disk.sh b/fill-disk.sh index 8c9e3b6c8fd..b50088e16e0 100755 --- a/fill-disk.sh +++ b/fill-disk.sh @@ -1,7 +1,7 @@ #! /bin/sh -e sysvinitPath=$1 -initPath=$2 +bootPath=$2 make_dir() { mode=$1 @@ -66,7 +66,10 @@ ln -s $sysvinitPath/sbin/init $root/init echo setting up inittab... rm -f $root/etc/inittab echo "id:2:initdefault:" >> $root/etc/inittab -echo "si::bootwait:$initPath/bin/init" >> $root/etc/inittab +echo "si::bootwait:$bootPath/bin/boot.sh" >> $root/etc/inittab +echo "ht:06:wait:$bootPath/bin/halt.sh" >> $root/etc/inittab +echo "1:2345:respawn:$bootPath/bin/login.sh /dev/ttys/0" >> $root/etc/inittab +echo "2:2345:respawn:$bootPath/bin/login.sh /dev/ttys/1" >> $root/etc/inittab echo unmounting... umount $root diff --git a/make-disk.sh b/make-disk.sh index 498753d6fbb..00e3cb28de1 100755 --- a/make-disk.sh +++ b/make-disk.sh @@ -30,10 +30,10 @@ done) < $storePaths > $successors # Location of sysvinit? sysvinitPath=$(nix-store -qn $(echo '(import ./pkgs.nix).sysvinit' | nix-instantiate -)) -# Location of Nix init? -initPath=$(nix-store -qn $(echo '(import ./pkgs.nix).init' | nix-instantiate -)) +# Location of Nix boot scripts? +bootPath=$(nix-store -qn $(echo '(import ./pkgs.nix).boot' | nix-instantiate -)) # Fill the disk with the minimal Nix store. if ! test -d /tmp/mnt; then mkdir /tmp/mnt; fi linux ubd0=$image root=/dev/root rootflags=/ rootfstype=hostfs \ - init="$(pwd)/fill-disk.sh $sysvinitPath $initPath" + init="$(pwd)/fill-disk.sh $sysvinitPath $bootPath" diff --git a/pkgs.nix b/pkgs.nix index d0314a6b300..d0df974d902 100644 --- a/pkgs.nix +++ b/pkgs.nix @@ -2,8 +2,8 @@ rec { inherit (import pkgs/system/i686-linux.nix) stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix; - init = (import ./init) + boot = (import ./boot) {inherit stdenv bash coreutils findutils utillinux sysvinit e2fsprogs nix;}; - everything = [init sysvinit]; + everything = [boot sysvinit]; }