From 03ebb883d18fb438de0bc27f4a209383adfa3419 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 Mar 2012 14:37:58 +0000 Subject: [PATCH] * Modularize filesystem support. Filesystems such as btrfs and reiserfs now have separate modules that are conditional on boot.supportedFilesystems and boot.initrd.supportedFilesystems. By default, these include the filesystems specified in the fsType attribute in fileSystems. Ext2/3/4 support is currently unconditional. Also unbreak the installer test (http://hydra.nixos.org/build/2272302). svn path=/nixos/trunk/; revision=32954 --- modules/config/system-path.nix | 1 - modules/module-list.nix | 5 + modules/profiles/base.nix | 5 +- modules/services/misc/autofs.nix | 4 +- .../network-filesystems/nfs-kernel.nix | 2 +- modules/system/boot/kernel.nix | 3 - modules/system/boot/stage-1.nix | 19 ---- modules/tasks/filesystems.nix | 98 +++++++------------ modules/tasks/filesystems/btrfs.nix | 38 +++++++ modules/tasks/filesystems/ext.nix | 22 +++++ modules/tasks/filesystems/nfs.nix | 25 +++++ modules/tasks/filesystems/reiserfs.nix | 25 +++++ 12 files changed, 159 insertions(+), 88 deletions(-) create mode 100644 modules/tasks/filesystems/btrfs.nix create mode 100644 modules/tasks/filesystems/ext.nix create mode 100644 modules/tasks/filesystems/nfs.nix create mode 100644 modules/tasks/filesystems/reiserfs.nix diff --git a/modules/config/system-path.nix b/modules/config/system-path.nix index d989ddf4b919..ce27eb35dd9f 100644 --- a/modules/config/system-path.nix +++ b/modules/config/system-path.nix @@ -17,7 +17,6 @@ let requiredPackages = [ config.system.sbin.modprobe # must take precedence over module_init_tools - config.system.sbin.mount # must take precedence over util-linux config.system.build.upstart config.environment.nix pkgs.acl diff --git a/modules/module-list.nix b/modules/module-list.nix index 7d42571d0fa6..5a1459f52268 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -114,6 +114,7 @@ ./services/networking/cntlm.nix ./services/networking/ddclient.nix ./services/networking/dhclient.nix + #./services/networking/dhcpcd.nix ./services/networking/dhcpd.nix ./services/networking/dnsmasq.nix ./services/networking/ejabberd.nix @@ -198,6 +199,10 @@ ./system/upstart/upstart.nix ./tasks/cpu-freq.nix ./tasks/filesystems.nix + ./tasks/filesystems/btrfs.nix + ./tasks/filesystems/ext.nix + ./tasks/filesystems/nfs.nix + ./tasks/filesystems/reiserfs.nix ./tasks/kbd.nix ./tasks/lvm.nix ./tasks/network-interfaces.nix diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index d67e7ca67343..d6412e09a5f0 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -31,7 +31,6 @@ # Tools to create / manipulate filesystems. pkgs.ntfsprogs # for resizing NTFS partitions - pkgs.btrfsProgs pkgs.dosfstools pkgs.xfsprogs pkgs.jfsutils @@ -50,4 +49,8 @@ pkgs.bvi # binary editor pkgs.joe ]; + + # Include support for various filesystems. + boot.supportedFilesystems = [ "btrfs" "reiserfs" ]; + } diff --git a/modules/services/misc/autofs.nix b/modules/services/misc/autofs.nix index eb3105e3a09a..e55c213ed21a 100644 --- a/modules/services/misc/autofs.nix +++ b/modules/services/misc/autofs.nix @@ -6,8 +6,6 @@ let cfg = config.services.autofs; - mount = config.system.sbin.mount; - autoMaster = pkgs.writeText "auto.master" cfg.autoMaster; in @@ -114,7 +112,7 @@ in unescapeSpaces(){ sed 's/\\040/ /g'; } sed -n 's@^\s*\(\([^\\ ]\|\\ \)*\)\s.*@\1@p' ${autoMaster} | sed 's/[\\]//' | while read mountPoint; do sed -n "s@[^ ]\+\s\+\($(echo "$mountPoint"| escapeSpaces)[^ ]*\).*@\1@p" /proc/mounts | sort -r | unescapeSpaces| while read smountP; do - ${mount}/bin/umount -l "$smountP" || true + ${pkgs.utillinux}/bin/umount -l "$smountP" || true done done ''; diff --git a/modules/services/network-filesystems/nfs-kernel.nix b/modules/services/network-filesystems/nfs-kernel.nix index 8ed22edf01e1..1ebc268ecf8f 100644 --- a/modules/services/network-filesystems/nfs-kernel.nix +++ b/modules/services/network-filesystems/nfs-kernel.nix @@ -151,7 +151,7 @@ in ${config.system.sbin.modprobe}/sbin/modprobe nfsd || true ${pkgs.sysvtools}/bin/mountpoint -q /proc/fs/nfsd \ - || ${config.system.sbin.mount}/bin/mount -t nfsd none /proc/fs/nfsd + || ${pkgs.utillinux}/bin/mount -t nfsd none /proc/fs/nfsd ${optionalString cfg.server.createMountPoints '' diff --git a/modules/system/boot/kernel.nix b/modules/system/boot/kernel.nix index c8ed496d8ae8..ea5a300fbce6 100644 --- a/modules/system/boot/kernel.nix +++ b/modules/system/boot/kernel.nix @@ -148,9 +148,6 @@ let kernel = config.boot.kernelPackages.kernel; in "ide_disk" "ide_generic" - # Filesystems. - "ext2" "ext3" "ext4" - # Support USB keyboards, in case the boot fails and we only have # a USB keyboard. "uhci_hcd" diff --git a/modules/system/boot/stage-1.nix b/modules/system/boot/stage-1.nix index bc27c9f80ffa..5a74ea84f38b 100644 --- a/modules/system/boot/stage-1.nix +++ b/modules/system/boot/stage-1.nix @@ -153,17 +153,6 @@ let cp -v ${pkgs.coreutils}/bin/sleep $out/bin cp -v ${pkgs.coreutils}/bin/ln $out/bin - # Copy e2fsck and friends. - cp -v ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin - cp -v ${pkgs.e2fsprogs}/sbin/tune2fs $out/bin - cp -v ${pkgs.reiserfsprogs}/sbin/reiserfsck $out/bin - ln -sv e2fsck $out/bin/fsck.ext2 - ln -sv e2fsck $out/bin/fsck.ext3 - ln -sv e2fsck $out/bin/fsck.ext4 - ln -sv reiserfsck $out/bin/fsck.reiserfs - - cp -pdv ${pkgs.e2fsprogs}/lib/lib*.so.* $out/lib - # Copy dmsetup and lvm. cp -v ${pkgs.lvm2}/sbin/dmsetup $out/bin/dmsetup cp -v ${pkgs.lvm2}/sbin/lvm $out/bin/lvm @@ -189,11 +178,6 @@ let cp ${kernelPackages.splashutils}/${kernelPackages.splashutils.helperName} $out/bin/splash_helper ''} - # Copy nfsmount if there is any NFS mounts required for boot. - ${optionalString (filter (fs: fs.fsType == "nfs" && (fs.mountPoint == "/" || fs.neededForBoot)) fileSystems != []) '' - cp -v ${pkgs.klibc}/lib/klibc/bin.static/nfsmount $out/bin - ''} - ${config.boot.initrd.extraUtilsCommands} # Run patchelf to make the programs refer to the copied libraries. @@ -223,13 +207,10 @@ let export LD_LIBRARY_PATH=$out/lib $out/bin/mount --version | grep "mount from" $out/bin/umount --version | grep "umount " - $out/bin/e2fsck -V 2>&1 | grep "e2fsck " - $out/bin/tune2fs 2> /dev/null | grep "tune2fs " $out/bin/udevadm --version $out/bin/blkid -v 2>&1 | tee -a $out/log | grep "blkid from util-linux" $out/bin/dmsetup --version 2>&1 | tee -a $out/log | grep "version:" LVM_SYSTEM_DIR=$out $out/bin/lvm version 2>&1 | tee -a $out/log | grep "LVM" - $out/bin/reiserfsck -V $out/bin/mdadm --version $out/bin/basename --version $out/bin/modprobe --version diff --git a/modules/tasks/filesystems.nix b/modules/tasks/filesystems.nix index 59e1137852a6..75cec61fd6cb 100644 --- a/modules/tasks/filesystems.nix +++ b/modules/tasks/filesystems.nix @@ -2,37 +2,6 @@ with pkgs.lib; -let - usingSome = fsname: any (fs: fs.fsType == fsname) config.fileSystems; - usingSomeStage1 = fsname: any (fs: fs.fsType == fsname && - (fs.mountPoint == "/" || fs.neededForBoot)) config.fileSystems; - - usingBtrfs = usingSome "btrfs"; - usingBtrfsStage1 = usingSomeStage1 "btrfs"; - - usingReiserfs = usingSome "reiserfs"; - usingReiserfsStage1 = usingSomeStage1 "reiserfs"; - - # Packages that provide fsck backends. - fsPackages = [ pkgs.e2fsprogs pkgs.dosfstools ] - ++ optional usingReiserfs pkgs.btrfsProgs - ++ optional usingBtrfs pkgs.btrfsProgs; - - fsKernelModules = optional usingBtrfsStage1 [ "btrfs" "crc32c" ] - ++ optional usingReiserfsStage1 [ "reiserfs" ]; - - fsExtraUtilsCommands = optionalString usingBtrfsStage1 '' - cp -v ${pkgs.btrfsProgs}/bin/btrfsck $out/bin - cp -v ${pkgs.btrfsProgs}/bin/btrfs $out/bin - ln -sv btrfsck $out/bin/fsck.btrfs - ''; - - fsPostDeviceCommands = optionalString usingBtrfsStage1 '' - btrfs device scan - ''; - -in - { ###### interface @@ -54,7 +23,7 @@ in } ]; - description = " + description = '' The file systems to be mounted. It must include an entry for the root directory (mountPoint = \"/\"). Each entry in the list is an attribute set with the following fields: @@ -72,7 +41,7 @@ in autocreate forces mountPoint to be created with mkdir -p . - "; + ''; type = types.nullOr (types.list types.optionSet); @@ -81,36 +50,28 @@ in mountPoint = mkOption { example = "/mnt/usb"; type = types.uniq types.string; - description = " - Location of the mounted the file system. - "; + description = "Location of the mounted the file system."; }; device = mkOption { default = null; example = "/dev/sda"; type = types.uniq (types.nullOr types.string); - description = " - Location of the device. - "; + description = "Location of the device."; }; label = mkOption { default = null; example = "root-partition"; type = types.uniq (types.nullOr types.string); - description = " - Label of the device (if any). - "; + description = "Label of the device (if any)."; }; fsType = mkOption { default = "auto"; example = "ext3"; type = types.uniq types.string; - description = " - Type of the file system. - "; + description = "Type of the file system."; }; options = mkOption { @@ -124,10 +85,10 @@ in autocreate = mkOption { default = false; type = types.bool; - description = " + description = '' Automatically create the mount point defined in . - "; + ''; }; noCheck = mkOption { @@ -138,12 +99,24 @@ in }; }; - system.sbin.mount = mkOption { + system.fsPackages = mkOption { internal = true; - default = pkgs.utillinux; - description = " - Package containing mount and umount. - "; + default = [ ]; + description = "Packages supplying file system mounters and checkers."; + }; + + boot.supportedFilesystems = mkOption { + default = [ ]; + example = [ "btrfs" ]; + type = types.list types.string; + description = "Names of supported filesystem types."; + }; + + boot.initrd.supportedFilesystems = mkOption { + default = [ ]; + example = [ "btrfs" ]; + type = types.list types.string; + description = "Names of supported filesystem types in the initial ramdisk."; }; }; @@ -153,10 +126,19 @@ in config = { + boot.supportedFilesystems = + map (fs: fs.fsType) config.fileSystems; + + boot.initrd.supportedFilesystems = + map (fs: fs.fsType) + (filter (fs: fs.mountPoint == "/" || fs.neededForBoot) config.fileSystems); + # Add the mount helpers to the system path so that `mount' can find them. + system.fsPackages = [ pkgs.dosfstools ]; + environment.systemPackages = - [ pkgs.ntfs3g pkgs.cifs_utils pkgs.nfsUtils pkgs.mountall ] - ++ fsPackages; + [ pkgs.ntfs3g pkgs.cifs_utils pkgs.mountall ] + ++ config.system.fsPackages; environment.etc = singleton { source = pkgs.writeText "fstab" @@ -183,10 +165,6 @@ in target = "fstab"; }; - boot.initrd.extraUtilsCommands = fsExtraUtilsCommands; - boot.initrd.postDeviceCommands = fsPostDeviceCommands; - boot.initrd.kernelModules = fsKernelModules; - jobs.mountall = { startOn = "started udev" # !!! The `started nfs-kernel-statd' condition shouldn't be @@ -198,12 +176,12 @@ in task = true; + path = [ pkgs.utillinux ] ++ config.system.fsPackages; + script = '' exec > /dev/console 2>&1 echo "mounting filesystems..." - export PATH=${config.system.sbin.mount}/bin:${makeSearchPath "sbin" ([pkgs.utillinux] ++ fsPackages)}:$PATH - ${optionalString usingBtrfs "${pkgs.btrfsProgs}/bin/btrfs device scan"} ${pkgs.mountall}/sbin/mountall ''; }; diff --git a/modules/tasks/filesystems/btrfs.nix b/modules/tasks/filesystems/btrfs.nix new file mode 100644 index 000000000000..c526b9677cf1 --- /dev/null +++ b/modules/tasks/filesystems/btrfs.nix @@ -0,0 +1,38 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + inInitrd = any (fs: fs == "btrfs") config.boot.initrd.supportedFilesystems; + +in + +{ + config = mkIf (any (fs: fs == "btrfs") config.boot.supportedFilesystems) { + + system.fsPackages = [ pkgs.btrfsProgs ]; + + boot.initrd.kernelModules = mkIf inInitrd [ "btrfs" "crc32c" ]; + + boot.initrd.extraUtilsCommands = mkIf inInitrd + '' + cp -v ${pkgs.btrfsProgs}/bin/btrfsck $out/bin + cp -v ${pkgs.btrfsProgs}/bin/btrfs $out/bin + ln -sv btrfsck $out/bin/fsck.btrfs + ''; + + boot.initrd.postDeviceCommands = mkIf inInitrd + '' + btrfs device scan + ''; + + # !!! This is broken. There should be a udev rule to do this when + # new devices are discovered. + jobs.udev.postStart = + '' + ${pkgs.btrfsProgs}/bin/btrfs device scan + ''; + + }; +} diff --git a/modules/tasks/filesystems/ext.nix b/modules/tasks/filesystems/ext.nix new file mode 100644 index 000000000000..93cdef4c664d --- /dev/null +++ b/modules/tasks/filesystems/ext.nix @@ -0,0 +1,22 @@ +{ config, pkgs, ... }: + +{ + config = { + + system.fsPackages = [ pkgs.e2fsprogs ]; + + boot.initrd.kernelModules = [ "ext2" "ext3" "ext4" ]; + + boot.initrd.extraUtilsCommands = + '' + # Copy e2fsck and friends. + cp -v ${pkgs.e2fsprogs}/sbin/e2fsck $out/bin + cp -v ${pkgs.e2fsprogs}/sbin/tune2fs $out/bin + ln -sv e2fsck $out/bin/fsck.ext2 + ln -sv e2fsck $out/bin/fsck.ext3 + ln -sv e2fsck $out/bin/fsck.ext4 + cp -pdv ${pkgs.e2fsprogs}/lib/lib*.so.* $out/lib + ''; + + }; +} diff --git a/modules/tasks/filesystems/nfs.nix b/modules/tasks/filesystems/nfs.nix new file mode 100644 index 000000000000..546b63687211 --- /dev/null +++ b/modules/tasks/filesystems/nfs.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + inInitrd = any (fs: fs == "nfs") config.boot.initrd.supportedFilesystems; + +in + +{ + config = { + + system.fsPackages = [ pkgs.nfsUtils ]; + + boot.initrd.kernelModules = mkIf inInitrd [ "nfs" ]; + + boot.initrd.extraUtilsCommands = mkIf inInitrd + '' + # !!! Uh, why don't we just install mount.nfs? + cp -v ${pkgs.klibc}/lib/klibc/bin.static/nfsmount $out/bin + ''; + + }; +} diff --git a/modules/tasks/filesystems/reiserfs.nix b/modules/tasks/filesystems/reiserfs.nix new file mode 100644 index 000000000000..f8c6a7000040 --- /dev/null +++ b/modules/tasks/filesystems/reiserfs.nix @@ -0,0 +1,25 @@ +{ config, pkgs, ... }: + +with pkgs.lib; + +let + + inInitrd = any (fs: fs == "reiserfs") config.boot.initrd.supportedFilesystems; + +in + +{ + config = mkIf (any (fs: fs == "reiserfs") config.boot.supportedFilesystems) { + + system.fsPackages = [ pkgs.reiserfsprogs ]; + + boot.initrd.kernelModules = mkIf inInitrd [ "reiserfs" ]; + + boot.initrd.extraUtilsCommands = mkIf inInitrd + '' + cp -v ${pkgs.reiserfsprogs}/sbin/reiserfsck $out/bin + ln -sv reiserfsck $out/bin/fsck.reiserfs + ''; + + }; +}