From 7613ae950ac35b9fb21e679c383a9ffff1cb73b0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 24 Jun 2012 19:02:34 -0400 Subject: [PATCH 01/11] Fix booting on EC2 The kill command in ash doesn't know the "--" syntax, but doesn't need it either. --- modules/virtualisation/amazon-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/virtualisation/amazon-image.nix b/modules/virtualisation/amazon-image.nix index 1891f816671..203c9a724ce 100644 --- a/modules/virtualisation/amazon-image.nix +++ b/modules/virtualisation/amazon-image.nix @@ -83,7 +83,7 @@ with pkgs.lib; # Force udev to exit to prevent random "Device or resource busy # while trying to open /dev/xvda" errors from fsck. udevadm control --exit || true - kill -9 -- -1 + kill -9 -1 ''; # Mount all formatted ephemeral disks and activate all swap devices. From a85555cd2731338c1046d3f6d65fe283ae054502 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Jun 2012 16:08:19 -0400 Subject: [PATCH 02/11] Remove the obsolete --no-pull option from the nixos-rebuild man page --- doc/manual/man-nixos-rebuild.xml | 33 ++++++++------------------------ 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/doc/manual/man-nixos-rebuild.xml b/doc/manual/man-nixos-rebuild.xml index 0b55540126c..625e8ac7a0c 100644 --- a/doc/manual/man-nixos-rebuild.xml +++ b/doc/manual/man-nixos-rebuild.xml @@ -173,12 +173,11 @@ $ ./result/bin/run-*-vm - This operation merely fetches the latest manifest in the - Nixpkgs channel to speed up subsequent - nix-env operations. This is useful if you - are not using nix-channel but still want to - use pre-built binary packages. It doesn’t reconfigure the - system at all. + This operation fetches the latest manifest in the Nixpkgs + channel to speed up subsequent nix-env + operations. This is useful if you are not using + nix-channel but still want to use pre-built + binary packages. It doesn’t reconfigure the system @@ -206,21 +205,6 @@ $ ./result/bin/run-*-vm - - - - Normally, nixos-rebuild calls - nix-pull to obtain the set of available - pre-built binaries in the Nixpkgs channel. This option causes - the call to nix-pull to be skipped. Note - that the result of previous invocations of - nix-pull may still be available in - /nix/var/nix/manifests, so to disable the - use of pre-built binaries, you should clear that directory in - addition to using . - - - @@ -236,10 +220,9 @@ $ ./result/bin/run-*-vm - Equivalent to - . - This option is useful if you call - nixos-rebuild frequently (e.g. if you’re + Equivalent to + . This option is useful if you + call nixos-rebuild frequently (e.g. if you’re hacking on a NixOS module). From cc357c7e64c9568d62eed74a9f1de952aa2d8ec8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Jun 2012 16:17:34 -0400 Subject: [PATCH 03/11] =?UTF-8?q?nixos-rebuild:=20Add=20a=20convenience=20?= =?UTF-8?q?option=20=E2=80=98--upgrade=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is equivalent to running ‘nix-channel --update nixos’ before running ‘nixos-rebuild’. --- doc/manual/man-nixos-rebuild.xml | 9 ++++++ modules/installer/tools/nixos-rebuild.sh | 35 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/doc/manual/man-nixos-rebuild.xml b/doc/manual/man-nixos-rebuild.xml index 625e8ac7a0c..383334d82e1 100644 --- a/doc/manual/man-nixos-rebuild.xml +++ b/doc/manual/man-nixos-rebuild.xml @@ -28,6 +28,7 @@ + @@ -195,6 +196,14 @@ $ ./result/bin/run-*-vm + + + + Fetch the latest version of NixOS from the NixOS + channel. + + + diff --git a/modules/installer/tools/nixos-rebuild.sh b/modules/installer/tools/nixos-rebuild.sh index b62da16c7b7..29927f8a126 100644 --- a/modules/installer/tools/nixos-rebuild.sh +++ b/modules/installer/tools/nixos-rebuild.sh @@ -22,6 +22,7 @@ The operation is one of the following: Options: + --upgrade fetch the latest version of NixOS before rebuilding --install-grub (re-)install the Grub bootloader --pull do a nix-pull to get the latest NixOS channel manifest @@ -51,43 +52,47 @@ action= pullManifest= buildNix=1 rollback= +upgrade= while test "$#" -gt 0; do i="$1"; shift 1 case "$i" in --help) showSyntax - ;; + ;; switch|boot|test|build|dry-run|build-vm|build-vm-with-bootloader|pull) action="$i" - ;; + ;; --install-grub) export NIXOS_INSTALL_GRUB=1 - ;; + ;; --pull) pullManifest=1 - ;; + ;; --no-build-nix) buildNix= - ;; + ;; --rollback) rollback=1 - ;; + ;; + --upgrade) + upgrade=1 + ;; --show-trace|--no-build-hook|--keep-failed|-K|--keep-going|-k|--verbose|-v|--fallback) extraBuildFlags="$extraBuildFlags $i" - ;; + ;; --max-jobs|-j|--cores|-I) j="$1"; shift 1 extraBuildFlags="$extraBuildFlags $i $j" - ;; + ;; --fast) buildNix= extraBuildFlags="$extraBuildFlags --show-trace" - ;; + ;; *) echo "$0: unknown option \`$i'" exit 1 - ;; + ;; esac done @@ -129,13 +134,19 @@ if [ -n "$pullManifest" -o "$action" = pull ]; then done fi -if [ "$action" = pull ]; then exit 0; fi +if [ "$action" = pull ]; then exit 0; fi + + +# If ‘--upgrade’ is given, run ‘nix-channel --update nixos’. +if [ -n "$upgrade" ]; then + nix-channel --update nixos +fi # First build Nix, since NixOS may require a newer version than the # current one. Of course, the same goes for Nixpkgs, but Nixpkgs is # more conservative. -if test -n "$buildNix"; then +if [ -n "$buildNix" ]; then echo "building Nix..." >&2 if ! nix-build '' -A config.environment.nix -o $tmpDir/nix $extraBuildFlags > /dev/null; then if ! nix-build '' -A nixFallback -o $tmpDir/nix $extraBuildFlags > /dev/null; then From e64bdda52b29e78ac893571c651209cd9f45f0de Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Jun 2012 09:35:53 -0400 Subject: [PATCH 04/11] Don't use weird 777 permissions on unmounted /dev/shm --- modules/system/boot/stage-2-init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/boot/stage-2-init.sh b/modules/system/boot/stage-2-init.sh index cc0f8befae8..c252b221dfb 100644 --- a/modules/system/boot/stage-2-init.sh +++ b/modules/system/boot/stage-2-init.sh @@ -84,7 +84,7 @@ done # More special file systems, initialise required directories. -mkdir -m 0777 /dev/shm +mkdir -m 0755 /dev/shm mount -t tmpfs -o "rw,nosuid,nodev,size=@devShmSize@" tmpfs /dev/shm mkdir -m 0755 -p /dev/pts mount -t devpts -o mode=0600,gid=@ttyGid@ none /dev/pts From 061a9988405e280757c4eea3730647ada90edb36 Mon Sep 17 00:00:00 2001 From: Mathijs Kwik Date: Sun, 24 Jun 2012 10:06:28 +0200 Subject: [PATCH 05/11] luks root: c-style for-loop -> seq The ash shell no longer supports this bash-specific syntax. This left systems that use luksroot unable to boot. --- modules/system/boot/luksroot.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/boot/luksroot.nix b/modules/system/boot/luksroot.nix index ff11d284ef8..edbf11214da 100644 --- a/modules/system/boot/luksroot.nix +++ b/modules/system/boot/luksroot.nix @@ -11,7 +11,7 @@ let # available as a function. if ! test -e ${device}; then echo -n "waiting 10 seconds for device ${device} to appear..." - for ((try = 0; try < 10; try++)); do + for try in $(seq 0 9); do sleep 1 if test -e ${device}; then break; fi echo -n . From bb5d2d53fea606a05a417c1c95b8feb4a073a57b Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Wed, 27 Jun 2012 09:43:54 -0400 Subject: [PATCH 06/11] try isn't used, so use the more compatct seq 10 --- modules/system/boot/luksroot.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/system/boot/luksroot.nix b/modules/system/boot/luksroot.nix index edbf11214da..0e28a882da5 100644 --- a/modules/system/boot/luksroot.nix +++ b/modules/system/boot/luksroot.nix @@ -11,7 +11,7 @@ let # available as a function. if ! test -e ${device}; then echo -n "waiting 10 seconds for device ${device} to appear..." - for try in $(seq 0 9); do + for try in $(seq 10); do sleep 1 if test -e ${device}; then break; fi echo -n . From dbe2325603420a89aa030994138bb54167fab81d Mon Sep 17 00:00:00 2001 From: David Guibert Date: Wed, 27 Jun 2012 20:41:07 +0200 Subject: [PATCH 07/11] fix the grep pattern finding programs called by absolute paths in udev rules. --- modules/services/hardware/udev.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/services/hardware/udev.nix b/modules/services/hardware/udev.nix index 0b63d7543ea..3bbf24bb379 100644 --- a/modules/services/hardware/udev.nix +++ b/modules/services/hardware/udev.nix @@ -73,7 +73,7 @@ let echo "OK" echo -n "Checking that all programs call by absolute paths in udev rules exist ... " - import_progs=$(grep 'IMPORT{program}="/' $out/* | + import_progs=$(grep 'IMPORT{program}="\/' $out/* | sed -e 's/.*IMPORT{program}="\([^ "]*\)[ "].*/\1/' | uniq) run_progs=$(grep -v '^[[:space:]]*#' $out/* | grep 'RUN+="/' | sed -e 's/.*RUN+="\([^ "]*\)[ "].*/\1/' | uniq) From 5b7c019e2a5b320589d9d7401ac072e5a0a1dffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Wed, 27 Jun 2012 21:36:46 +0200 Subject: [PATCH 08/11] nixos-rebuild: make 'pull' fail in case it did not pull anything. --- modules/installer/tools/nixos-rebuild.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/installer/tools/nixos-rebuild.sh b/modules/installer/tools/nixos-rebuild.sh index 29927f8a126..98b46cb7cdb 100644 --- a/modules/installer/tools/nixos-rebuild.sh +++ b/modules/installer/tools/nixos-rebuild.sh @@ -125,9 +125,13 @@ fi # Pull the manifests defined in the configuration (the "manifests" # attribute). Wonderfully hacky. if [ -n "$pullManifest" -o "$action" = pull ]; then + set -o pipefail manifests=$(nix-instantiate --eval-only --xml --strict '' -A manifests \ | grep ' Date: Wed, 27 Jun 2012 21:56:29 +0200 Subject: [PATCH 09/11] nixos-rebuild: fail if any case of pull fails. --- modules/installer/tools/nixos-rebuild.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/installer/tools/nixos-rebuild.sh b/modules/installer/tools/nixos-rebuild.sh index 98b46cb7cdb..22aa847e192 100644 --- a/modules/installer/tools/nixos-rebuild.sh +++ b/modules/installer/tools/nixos-rebuild.sh @@ -130,7 +130,7 @@ if [ -n "$pullManifest" -o "$action" = pull ]; then | grep ' Date: Wed, 27 Jun 2012 22:26:27 +0200 Subject: [PATCH 10/11] system-tarball-pc: not use boot.initrd.extraTools anymore Eelco removed the option recently, making the default initrd have the full busybox. I saw this evaluation error in the hydra nixos trunk page. --- modules/installer/cd-dvd/system-tarball-pc.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/installer/cd-dvd/system-tarball-pc.nix b/modules/installer/cd-dvd/system-tarball-pc.nix index ddad520c446..2bc6ce78d94 100644 --- a/modules/installer/cd-dvd/system-tarball-pc.nix +++ b/modules/installer/cd-dvd/system-tarball-pc.nix @@ -158,9 +158,6 @@ in services.openssh.enable = true; jobs.openssh.startOn = pkgs.lib.mkOverrideTemplate 50 {} ""; - # To have a nicer initrd, even though the initrd can't mount an nfsroot now - boot.initrd.withExtraTools = true; - # To be able to use the systemTarball to catch troubles. boot.crashDump = { enable = true; From 76c74cd7c718da9d3cc6e1d76fb78a86c363406c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 28 Jun 2012 10:55:44 -0400 Subject: [PATCH 11/11] initrd: Detect filesystem type before doing fsck/mount BusyBox doesn't handle the "auto" filesystem type very well: fsck will just ignore such filesystems, and mount will only work properly if the required kernel module is already loaded. Therefore, use blkid to determine the filesystem type. Also generate an /etc/fstab in the initrd rootfs on the fly. This is useful if you're dropped into an emergency shell since it allows you to say "fsck /dev/sda1" or "mount /dev/sda" and have the right thing happen. --- modules/installer/cd-dvd/iso-image.nix | 4 ++- modules/system/boot/stage-1-init.sh | 38 ++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index 7b050f8dd6a..cf76151c2ae 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -205,7 +205,9 @@ in else [ config.boot.kernelPackages.aufs ]; - boot.initrd.kernelModules = [ "aufs" "squashfs" "iso9660" "loop" ]; + boot.initrd.availableKernelModules = [ "aufs" "squashfs" "iso9660" ]; + + boot.initrd.kernelModules = [ "loop" ]; boot.kernelModules = pkgs.stdenv.lib.optional config.isoImage.makeEfiBootable "efivars"; diff --git a/modules/system/boot/stage-1-init.sh b/modules/system/boot/stage-1-init.sh index 33eaee826aa..cc12ccaa738 100644 --- a/modules/system/boot/stage-1-init.sh +++ b/modules/system/boot/stage-1-init.sh @@ -184,21 +184,28 @@ onACPower() { # Check the specified file system, if appropriate. checkFS() { + local device="$1" + local fsType="$2" + # Only check block devices. - if ! test -b "$device"; then return 0; fi - - FSTYPE=$(blkid -o value -s TYPE "$device" || true) + if [ ! -b "$device" ]; then return 0; fi # Don't check ROM filesystems. - if test "$FSTYPE" = iso9660 -o "$FSTYPE" = udf; then return 0; fi + if [ "$fsType" = iso9660 -o "$fsType" = udf ]; then return 0; fi + + # If we couldn't figure out the FS type, then skip fsck. + if [ "$fsType" = auto ]; then + echo 'cannot check filesystem with type "auto"!' + return 0 + fi # Optionally, skip fsck on journaling filesystems. This option is # a hack - it's mostly because e2fsck on ext3 takes much longer to # recover the journal than the ext3 implementation in the kernel # does (minutes versus seconds). if test -z "@checkJournalingFS@" -a \ - \( "$FSTYPE" = ext3 -o "$FSTYPE" = ext4 -o "$FSTYPE" = reiserfs \ - -o "$FSTYPE" = xfs -o "$FSTYPE" = jfs \) + \( "$fsType" = ext3 -o "$fsType" = ext4 -o "$fsType" = reiserfs \ + -o "$fsType" = xfs -o "$fsType" = jfs \) then return 0 fi @@ -210,7 +217,9 @@ checkFS() { return 0 fi - FSTAB_FILE="/etc/mtab" fsck -V -C -a "$device" + echo "checking $device..." + + fsck -V -a "$device" fsckResult=$? if test $(($fsckResult | 2)) = $fsckResult; then @@ -240,7 +249,16 @@ mountFS() { local options="$3" local fsType="$4" - checkFS "$device" + if [ "$fsType" = auto ]; then + fsType=$(blkid -o value -s TYPE "$device") + if [ -z "$fsType" ]; then fsType=auto; fi + fi + + echo "$device /mnt-root$mountPoint $fsType $options" >> /etc/fstab + + checkFS "$device" "$fsType" + + echo "mounting $device on $mountPoint..." mkdir -p "/mnt-root$mountPoint" || true @@ -250,7 +268,7 @@ mountFS() { if [ "$fsType" = "nfs" ]; then nfsmount "$device" "/mnt-root$mountPoint" && break else - mount -t "$fsType" -o "$options" "$device" "/mnt-root$mountPoint" && break + mount "/mnt-root$mountPoint" && break fi if [ "$fsType" != cifs -o "$n" -ge 10 ]; then fail; break; fi echo "retrying..." @@ -311,8 +329,6 @@ while read -u 3 mountPoint; do # doing something with $device right now. udevadm settle || true - echo "mounting $device on $mountPoint..." - mountFS "$device" "$mountPoint" "$options" "$fsType" done