2007-07-22 04:07:02 +02:00
|
|
|
{ stdenv, writeText, substituteAll, cleanSource, udev, procps, firmwareDirs
|
|
|
|
, extraUdevPkgs ? []
|
2008-01-02 11:07:52 +01:00
|
|
|
, sndMode ? "0600"
|
2007-07-22 04:07:02 +02:00
|
|
|
}:
|
2006-12-13 15:24:33 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2007-03-04 00:20:08 +01:00
|
|
|
# Perform substitutions in all udev rules files.
|
|
|
|
udevRules = stdenv.mkDerivation {
|
|
|
|
name = "udev-rules";
|
|
|
|
src = cleanSource ./udev-rules;
|
|
|
|
firmwareLoader = substituteAll {
|
|
|
|
src = ./udev-firmware-loader.sh;
|
|
|
|
path = "${stdenv.coreutils}/bin";
|
|
|
|
isExecutable = true;
|
|
|
|
inherit firmwareDirs;
|
|
|
|
};
|
2008-01-02 11:07:52 +01:00
|
|
|
inherit sndMode;
|
2007-03-04 00:20:08 +01:00
|
|
|
buildCommand = "
|
|
|
|
buildCommand= # urgh
|
|
|
|
ensureDir $out
|
|
|
|
for i in $src/*; do
|
|
|
|
substituteAll $i $out/$(basename $i)
|
|
|
|
done
|
2007-07-22 04:07:02 +02:00
|
|
|
shopt -s nullglob
|
|
|
|
for i in ${toString extraUdevPkgs}; do
|
|
|
|
for j in $i/etc/udev/rules.d/*; do
|
|
|
|
ln -s $j $out/$(basename $j)
|
|
|
|
done
|
|
|
|
done
|
2007-03-04 00:20:08 +01:00
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
# The udev configuration file
|
2008-02-04 11:52:58 +01:00
|
|
|
conf = writeText "udev.conf" ''
|
|
|
|
udev_rules="${udevRules}"
|
|
|
|
#udev_log="debug"
|
|
|
|
'';
|
2006-12-13 15:24:33 +01:00
|
|
|
|
2007-04-02 17:00:31 +02:00
|
|
|
# Dummy file indicating whether we've run udevtrigger/udevsettle.
|
|
|
|
# Since that *recreates* all device nodes with default permissions,
|
|
|
|
# it's not nice to do that when a user is logged in (it messes up
|
|
|
|
# the permissions set by pam_devperm).
|
|
|
|
# !!! Actually, this makes the udev configuration less declarative;
|
|
|
|
# changes may not take effect until the user reboots. We should
|
|
|
|
# find a better way to preserve the permissions of logged-in users.
|
|
|
|
devicesCreated = "/var/run/devices-created";
|
|
|
|
|
2006-12-13 15:24:33 +01:00
|
|
|
in
|
2006-12-13 13:17:38 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
name = "udev";
|
|
|
|
|
2008-06-20 18:09:48 +02:00
|
|
|
job = ''
|
|
|
|
start on startup
|
|
|
|
stop on shutdown
|
|
|
|
|
|
|
|
env UDEV_CONFIG_FILE=${conf}
|
|
|
|
|
|
|
|
start script
|
|
|
|
echo "" > /proc/sys/kernel/hotplug
|
|
|
|
|
|
|
|
# Get rid of possible old udev processes.
|
|
|
|
${procps}/bin/pkill -u root "^udevd$" || true
|
|
|
|
|
|
|
|
# Start udev.
|
|
|
|
${udev}/sbin/udevd --daemon
|
|
|
|
|
|
|
|
# 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).
|
|
|
|
if ! test -e ${devicesCreated}; then
|
|
|
|
${udev}/sbin/udevtrigger
|
|
|
|
${udev}/sbin/udevsettle # wait for udev to finish
|
|
|
|
touch ${devicesCreated}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill udev, let Upstart restart and monitor it. (This is nasty,
|
|
|
|
# but we have to run udevtrigger first. Maybe we can use
|
|
|
|
# Upstart's `binary' keyword, but it isn't implemented yet.)
|
|
|
|
if ! ${procps}/bin/pkill -u root "^udevd$"; then
|
|
|
|
echo "couldn't stop udevd"
|
|
|
|
fi
|
|
|
|
|
|
|
|
while ${procps}/bin/pgrep -u root "^udevd$"; do
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
initctl emit new-devices
|
|
|
|
end script
|
|
|
|
|
|
|
|
respawn ${udev}/sbin/udevd
|
|
|
|
'';
|
2006-12-13 13:17:38 +01:00
|
|
|
|
|
|
|
}
|