diff --git a/modules/services/hardware/udev.nix b/modules/services/hardware/udev.nix index 798b9a4e381..af653f59c88 100644 --- a/modules/services/hardware/udev.nix +++ b/modules/services/hardware/udev.nix @@ -44,19 +44,6 @@ let # called by 50-firmware.rules works properly. echo 'ENV{FIRMWARE_DIRS}="${toString config.hardware.firmware}"' >> $out/00-path.rules - # Fix some paths in the standard udev rules. - for i in $out/*.rules; do - substituteInPlace $i \ - --replace /sbin/modprobe ${modprobe}/sbin/modprobe \ - --replace /sbin/blkid ${pkgs.utillinux}/sbin/blkid \ - --replace /sbin/mdadm ${pkgs.mdadm}/sbin/madm - done - - # If auto-configuration is disabled, then remove - # udev's 80-drivers.rules file, which contains rules for - # automatically calling modprobe. - ${if !config.boot.hardwareScan then "rm $out/80-drivers.rules" else ""} - # Add the udev rules from other packages. for i in ${toString cfg.packages}; do for j in $i/*/udev/rules.d/*; do @@ -64,6 +51,21 @@ let done done + # Fix some paths in the standard udev rules. Hacky. + for i in $out/*.rules; do + substituteInPlace $i \ + --replace /sbin/modprobe ${modprobe}/sbin/modprobe \ + --replace /sbin/blkid ${pkgs.utillinux}/sbin/blkid \ + --replace /sbin/mdadm ${pkgs.mdadm}/sbin/madm \ + --replace '$env{DM_SBIN_PATH}/blkid' ${pkgs.utillinux}/sbin/blkid \ + --replace 'ENV{DM_SBIN_PATH}="/sbin"' 'ENV{DM_SBIN_PATH}="${pkgs.lvm2}/sbin"' + done + + # If auto-configuration is disabled, then remove + # udev's 80-drivers.rules file, which contains rules for + # automatically calling modprobe. + ${if !config.boot.hardwareScan then "rm $out/80-drivers.rules" else ""} + # Use the persistent device rules (naming for CD/DVD and # network devices) stored in # /var/lib/udev/rules.d/70-persistent-{cd,net}.rules. These are @@ -186,8 +188,12 @@ in '' # Let udev create device nodes for all modules that have already # been loaded into the kernel (or for which support is built into - # the kernel). + # the kernel). The `STARTUP' variable is needed to force + # the LVM rules to create device nodes. See + # http://www.mail-archive.com/fedora-devel-list@redhat.com/msg10261.html + ${udev}/sbin/udevadm control --env=STARTUP=1 ${udev}/sbin/udevadm trigger + ${udev}/sbin/udevadm control --env=STARTUP= ${udev}/sbin/udevadm settle # wait for udev to finish initctl emit -n new-devices diff --git a/modules/tasks/lvm.nix b/modules/tasks/lvm.nix index d5204f1deba..8b60cd4c0b9 100644 --- a/modules/tasks/lvm.nix +++ b/modules/tasks/lvm.nix @@ -6,32 +6,10 @@ config = { - jobs.lvm = - { startOn = "started udev or new-devices"; - - script = - '' - # Load the device mapper. - ${config.system.sbin.modprobe}/sbin/modprobe dm_mod || true - - ${pkgs.lvm2}/sbin/dmsetup mknodes - - # Scan for block devices that might contain LVM physical volumes - # and volume groups. - ${pkgs.lvm2}/sbin/vgscan --mknodes - - # Make all logical volumes on all volume groups available, i.e., - # make them appear in /dev. - ${pkgs.lvm2}/sbin/vgchange --available y - - initctl emit -n new-devices - ''; - - task = true; - }; - environment.systemPackages = [ pkgs.lvm2 ]; + services.udev.packages = [ pkgs.lvm2 ]; + }; }