From 119df37858b853440f9ff4827563813997006b23 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 4 Mar 2007 01:16:24 +0000 Subject: [PATCH] * Generate a wrapper around modprobe that sets MODULE_DIR. This is important for /proc/sys/kernel/modprobe, i.e., modprobing by the kernel. svn path=/nixos/trunk/; revision=8164 --- system/activate-configuration.sh | 8 ++++++++ system/modprobe | 3 +++ system/system.nix | 14 ++++++++++++-- system/upstart.nix | 19 ++++++++++++------- upstart-jobs/alsa.nix | 5 ++--- upstart-jobs/hardware-scan.nix | 9 +++------ upstart-jobs/lvm.nix | 5 ++--- upstart-jobs/network-interfaces.nix | 7 ++----- upstart-jobs/ntpd.nix | 5 ++--- upstart-jobs/swraid.nix | 6 +++--- 10 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 system/modprobe diff --git a/system/activate-configuration.sh b/system/activate-configuration.sh index addeeb2f8208..d7360f274863 100644 --- a/system/activate-configuration.sh +++ b/system/activate-configuration.sh @@ -36,6 +36,14 @@ mkdir -m 0755 -p $mountPoint/bin ln -sfn @shell@ $mountPoint/bin/sh +# Allow the kernel to find our wrapped modprobe (which searches in the +# right location in the Nix store for kernel modules). We need this +# when the kernel (or some module) auto-loads a module. +# !!! maybe this should only happen at boot time, since we shouldn't +# use modules that don't match the running kernel. +echo @modprobe@/sbin/modprobe > /proc/sys/kernel/modprobe + + # Various log directories. mkdir -m 0755 -p /var/run diff --git a/system/modprobe b/system/modprobe new file mode 100644 index 000000000000..5971880f0648 --- /dev/null +++ b/system/modprobe @@ -0,0 +1,3 @@ +#! @shell@ +export MODULE_DIR=@kernel@/lib/modules +exec @module_init_tools@/sbin/modprobe "$@" diff --git a/system/system.nix b/system/system.nix index e032bad07ab3..03ec3b1c3a4c 100644 --- a/system/system.nix +++ b/system/system.nix @@ -131,9 +131,18 @@ rec { (map (mod: mod + "/lib") nssModules)); + # Wrapper around modprobe to set the path to the modules. + modprobe = pkgs.substituteAll { + dir = "sbin"; + src = ./modprobe; + isExecutable = true; + inherit (pkgs) kernel module_init_tools; + }; + + # The services (Upstart) configuration for the system. upstartJobs = import ./upstart.nix { - inherit config pkgs nix nssModulesPath; + inherit config pkgs nix modprobe nssModulesPath; }; @@ -155,6 +164,7 @@ rec { # The packages you want in the boot environment. systemPathList = [ + modprobe # must take precedence over module_init_tools pkgs.bash pkgs.bzip2 pkgs.coreutils @@ -220,7 +230,7 @@ rec { src = ./activate-configuration.sh; isExecutable = true; - inherit etc wrapperDir systemPath; + inherit etc wrapperDir systemPath modprobe; inherit (pkgs) kernel; readOnlyRoot = config.get ["boot" "readOnlyRoot"]; hostName = config.get ["networking" "hostName"]; diff --git a/system/upstart.nix b/system/upstart.nix index fc694eefc133..eb185a2b204b 100644 --- a/system/upstart.nix +++ b/system/upstart.nix @@ -1,4 +1,4 @@ -{config, pkgs, nix, nssModulesPath}: +{config, pkgs, nix, modprobe, nssModulesPath}: let @@ -31,17 +31,19 @@ import ../upstart-jobs/gather.nix { # Makes LVM logical volumes available. (import ../upstart-jobs/lvm.nix { - inherit (pkgs) kernel module_init_tools lvm2; + inherit modprobe; + inherit (pkgs) lvm2; }) # Activate software RAID arrays. (import ../upstart-jobs/swraid.nix { - inherit (pkgs) kernel module_init_tools mdadm; + inherit modprobe; + inherit (pkgs) mdadm; }) # Hardware scan; loads modules for PCI devices. (import ../upstart-jobs/hardware-scan.nix { - inherit (pkgs) kernel module_init_tools; + inherit modprobe; doHardwareScan = config.get ["boot" "hardwareScan"]; kernelModules = config.get ["boot" "kernelModules"]; }) @@ -60,7 +62,8 @@ import ../upstart-jobs/gather.nix { # Network interfaces. (import ../upstart-jobs/network-interfaces.nix { - inherit (pkgs) nettools kernel module_init_tools wirelesstools; + inherit modprobe; + inherit (pkgs) nettools wirelesstools; nameservers = config.get ["networking" "nameservers"]; defaultGateway = config.get ["networking" "defaultGateway"]; interfaces = config.get ["networking" "interfaces"]; @@ -113,7 +116,8 @@ import ../upstart-jobs/gather.nix { # NTP daemon. ++ optional ["services" "ntp" "enable"] (import ../upstart-jobs/ntpd.nix { - inherit (pkgs) ntp kernel module_init_tools glibc pwdutils writeText; + inherit modprobe; + inherit (pkgs) ntp glibc pwdutils writeText; servers = config.get ["services" "ntp" "servers"]; }) @@ -136,7 +140,8 @@ import ../upstart-jobs/gather.nix { # ALSA sound support. ++ optional ["sound" "enable"] (import ../upstart-jobs/alsa.nix { - inherit (pkgs) kernel module_init_tools alsaUtils; + inherit modprobe; + inherit (pkgs) alsaUtils; }) # Handles the reboot/halt events. diff --git a/upstart-jobs/alsa.nix b/upstart-jobs/alsa.nix index de258a8770b1..1b018b2259a8 100644 --- a/upstart-jobs/alsa.nix +++ b/upstart-jobs/alsa.nix @@ -1,4 +1,4 @@ -{kernel, module_init_tools, alsaUtils}: +{modprobe, alsaUtils}: let @@ -16,9 +16,8 @@ stop on shutdown start script # Load some additional modules. - export MODULE_DIR=${kernel}/lib/modules/ for mod in snd_pcm_oss; do - ${module_init_tools}/sbin/modprobe $mod || true + ${modprobe}/sbin/modprobe $mod || true done # Restore the sound state. diff --git a/upstart-jobs/hardware-scan.nix b/upstart-jobs/hardware-scan.nix index 6cca5f7562f5..80b7f440b76d 100644 --- a/upstart-jobs/hardware-scan.nix +++ b/upstart-jobs/hardware-scan.nix @@ -1,5 +1,4 @@ -# !!! Don't like it that I have to pass the kernel here. -{kernel, module_init_tools, doHardwareScan, kernelModules}: +{modprobe, doHardwareScan, kernelModules}: { name = "hardware-scan"; @@ -8,11 +7,9 @@ start on udev script - export MODULE_DIR=${kernel}/lib/modules/ - for i in ${toString kernelModules}; do echo \"Loading kernel module $i...\" - ${module_init_tools}/sbin/modprobe $i || true + ${modprobe}/sbin/modprobe $i || true done if test -n \"${toString doHardwareScan}\" -a ! -e /var/run/safemode; then @@ -20,7 +17,7 @@ script # Try to load modules for all PCI devices. for i in /sys/bus/pci/devices/*/modalias; do echo \"Trying to load a module for $(basename $(dirname $i))...\" - ${module_init_tools}/sbin/modprobe $(cat $i) || true + ${modprobe}/sbin/modprobe $(cat $i) || true echo \"\" done diff --git a/upstart-jobs/lvm.nix b/upstart-jobs/lvm.nix index 558b80cd6514..ee6e842564c3 100644 --- a/upstart-jobs/lvm.nix +++ b/upstart-jobs/lvm.nix @@ -1,4 +1,4 @@ -{kernel, module_init_tools, lvm2}: +{modprobe, lvm2}: { name = "lvm"; @@ -10,8 +10,7 @@ start on udev script # Load the device mapper. - export MODULE_DIR=${kernel}/lib/modules/ - ${module_init_tools}/sbin/modprobe dm_mod || true + ${modprobe}/sbin/modprobe dm_mod || true # Scan for block devices that might contain LVM physical volumes # and volume groups. diff --git a/upstart-jobs/network-interfaces.nix b/upstart-jobs/network-interfaces.nix index 66548b1354d8..a40ced8a90cb 100644 --- a/upstart-jobs/network-interfaces.nix +++ b/upstart-jobs/network-interfaces.nix @@ -1,5 +1,4 @@ -# !!! Don't like it that I have to pass the kernel here. -{ nettools, kernel, module_init_tools, wirelesstools +{ nettools, modprobe, wirelesstools , nameservers, defaultGateway, interfaces }: @@ -22,9 +21,7 @@ start on hardware-scan stop on shutdown start script - export MODULE_DIR=${kernel}/lib/modules/ - - ${module_init_tools}/sbin/modprobe af_packet + ${modprobe}/sbin/modprobe af_packet for i in $(cd /sys/class/net && ls -d *); do echo \"Bringing up network device $i...\" diff --git a/upstart-jobs/ntpd.nix b/upstart-jobs/ntpd.nix index 39e5eb9023f3..1a043106d17a 100644 --- a/upstart-jobs/ntpd.nix +++ b/upstart-jobs/ntpd.nix @@ -1,4 +1,4 @@ -{ntp, kernel, module_init_tools, glibc, pwdutils, writeText, servers}: +{ntp, modprobe, glibc, pwdutils, writeText, servers}: let @@ -37,8 +37,7 @@ start script chown ${ntpUser} ${stateDir} # Needed to run ntpd as an unprivileged user. - export MODULE_DIR=${kernel}/lib/modules/ - ${module_init_tools}/sbin/modprobe capability + ${modprobe}/sbin/modprobe capability ${ntp}/bin/ntpd -q -g ${ntpFlags} diff --git a/upstart-jobs/swraid.nix b/upstart-jobs/swraid.nix index 3a3328eb1f0b..5cf7d82e3833 100644 --- a/upstart-jobs/swraid.nix +++ b/upstart-jobs/swraid.nix @@ -1,4 +1,4 @@ -{kernel, module_init_tools, mdadm}: +{modprobe, mdadm}: let @@ -16,9 +16,9 @@ start on udev script # Load the necessary RAID personalities. - export MODULE_DIR=${kernel}/lib/modules/ + # !!! hm, doesn't the kernel load these automatically? for mod in raid0 raid1 raid5; do - ${module_init_tools}/sbin/modprobe $mod || true + ${modprobe}/sbin/modprobe $mod || true done # Scan /proc/partitions for RAID devices.