From 4ff6821a03680ad92db08701555be3a6f5c735e3 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Thu, 17 Dec 2009 06:04:36 +0000 Subject: [PATCH] module creating /sbin/init svn path=/nixos/trunk/; revision=19009 --- .../init-script/init-script-builder.sh | 89 +++++++++++++++++++ modules/installer/init-script/init-script.nix | 51 +++++++++++ modules/module-list.nix | 1 + .../activation/switch-to-configuration.sh | 2 + modules/system/activation/top-level.nix | 1 + 5 files changed, 144 insertions(+) create mode 100644 modules/installer/init-script/init-script-builder.sh create mode 100644 modules/installer/init-script/init-script.nix diff --git a/modules/installer/init-script/init-script-builder.sh b/modules/installer/init-script/init-script-builder.sh new file mode 100644 index 000000000000..24128ae9abc9 --- /dev/null +++ b/modules/installer/init-script/init-script-builder.sh @@ -0,0 +1,89 @@ + +#! @bash@/bin/sh -e + +shopt -s nullglob + +export PATH=/empty +for i in @path@; do PATH=$PATH:$i/bin; done + +if test $# -ne 1; then + echo "Usage: grub-menu-builder.sh DEFAULT-CONFIG" + exit 1 +fi + +defaultConfig="$1" + + +[ "$(stat -f -c '%i' /)" = "$(stat -f -c '%i' /boot)" ] || { + # see grub-menu-builder.sh + echo "WARNING: /boot being on a different filesystem not supported by init-script-builder.sh" +} + + + +target="/sbin/init" +targetOther="/boot/init-other-configurations-contents.txt" + +tmp="$target.tmp" +tmpOther="$targetOther.tmp" + + +configurationCounter=0 +numAlienEntries=`cat < $tmp + echo "# older configurations: $targetOther" >> $tmp + chmod +x $tmp + } + + echo -e "$content\n\n" >> $tmpOther +} + + +mkdir -p /boot /sbin + +addEntry "NixOS - Default" $defaultConfig "" + +# Add all generations of the system profile to the menu, in reverse +# (most recent to least recent) order. +for link in $((ls -d $defaultConfig/fine-tune/* ) | sort -n); do + date=$(stat --printf="%y\n" $link | sed 's/\..*//') + addEntry "NixOS - variation" $link "" +done + +for generation in $( + (cd /nix/var/nix/profiles && ls -d system-*-link) \ + | sed 's/system-\([0-9]\+\)-link/\1/' \ + | sort -n -r); do + link=/nix/var/nix/profiles/system-$generation-link + date=$(stat --printf="%y\n" $link | sed 's/\..*//') + kernelVersion=$(cd $(dirname $(readlink -f $link/kernel))/lib/modules && echo *) + addEntry "NixOS - Configuration $generation ($date - $kernelVersion)" $link "$generation ($date)" +done + +mv $tmpOther $targetOther +mv $tmp $target diff --git a/modules/installer/init-script/init-script.nix b/modules/installer/init-script/init-script.nix new file mode 100644 index 000000000000..ff656b1c4429 --- /dev/null +++ b/modules/installer/init-script/init-script.nix @@ -0,0 +1,51 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + initScriptBuilder = pkgs.substituteAll { + src = ./init-script-builder.sh; + isExecutable = true; + inherit (pkgs) bash; + path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; + }; + +in + +{ + + ###### interface + + options = { + + boot.loader.initScript = { + + enable = mkOption { + default = true; + description = '' + Some systems require a /sbin/init script which is started. + Or having it makes starting NixOS easier. + This applies to some kind of hosting services and user mode linux. + + Additionaly this script will create + /boot/init-other-configurations-contents.txt containing + contents of remaining configurations. You can copy paste them into + /sbin/init manually running a recue system or such. + ''; + }; + }; + + }; + + + ###### implementation + + config = { + + system.build.initScriptBuilder = + if config.boot.loader.initScript.enable then initScriptBuilder else ""; + + }; + +} diff --git a/modules/module-list.nix b/modules/module-list.nix index 62f8638020cb..702822f506ab 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -15,6 +15,7 @@ ./hardware/network/rt73.nix ./hardware/pcmcia.nix ./installer/grub/grub.nix + ./installer/init-script/init-script.nix ./installer/generations-dir/generations-dir.nix ./installer/tools/nixos-checkout.nix ./installer/tools/tools.nix diff --git a/modules/system/activation/switch-to-configuration.sh b/modules/system/activation/switch-to-configuration.sh index 86775ad62a81..2a8e29bb841d 100644 --- a/modules/system/activation/switch-to-configuration.sh +++ b/modules/system/activation/switch-to-configuration.sh @@ -49,6 +49,8 @@ if [ "$action" = "switch" -o "$action" = "boot" ]; then else echo "Warning: don't know how to make this configuration bootable; please enable a boot loader." 1>&2 fi + + @initScriptBuilder@ @out@ fi # Activate the new configuration. diff --git a/modules/system/activation/top-level.nix b/modules/system/activation/top-level.nix index d2c20e909293..2fdaa6fd945a 100644 --- a/modules/system/activation/top-level.nix +++ b/modules/system/activation/top-level.nix @@ -108,6 +108,7 @@ let kernelParams = config.boot.kernelParams ++ config.boot.extraKernelParams; menuBuilder = config.system.build.menuBuilder; + initScriptBuilder = config.system.build.initScriptBuilder; # Most of these are needed by grub-install. path = [ pkgs.coreutils