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
|
|
|
|
|
2008-07-02 20:06:34 +02:00
|
|
|
firmwareLoader = substituteAll {
|
|
|
|
src = ./udev-firmware-loader.sh;
|
|
|
|
path = "${stdenv.coreutils}/bin";
|
|
|
|
isExecutable = true;
|
|
|
|
inherit firmwareDirs;
|
|
|
|
};
|
|
|
|
|
|
|
|
nixRules = writeText "10-nix.rules" ''
|
|
|
|
|
|
|
|
# Miscellaneous devices.
|
|
|
|
KERNEL=="sonypi", MODE="0666"
|
|
|
|
KERNEL=="kvm", MODE="0666"
|
|
|
|
KERNEL=="kqemu", NAME="%k", MODE="0666"
|
|
|
|
|
|
|
|
# Create a symlink for the CD-ROM device.
|
|
|
|
#KERNEL=="hd[a-z]", BUS=="ide", SYSFS{removable}=="1", SYSFS{device/media}=="cdrom", SYMLINK+="cdrom cdrom-%k"
|
|
|
|
#KERNEL=="sr[0-9]", BUS=="scsi", SYMLINK+="cdrom cdrom-%k"
|
|
|
|
|
|
|
|
# ALSA sound devices.
|
|
|
|
KERNEL=="controlC[0-9]*", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
KERNEL=="hwC[D0-9]*", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
KERNEL=="pcmC[D0-9cp]*", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
KERNEL=="midiC[D0-9]*", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
KERNEL=="timer", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
KERNEL=="seq", NAME="snd/%k", MODE="${sndMode}"
|
|
|
|
|
|
|
|
# Firmware loading.
|
|
|
|
SUBSYSTEM=="firmware", ACTION=="add", RUN+="${firmwareLoader}"
|
|
|
|
|
|
|
|
'';
|
|
|
|
|
2007-03-04 00:20:08 +01:00
|
|
|
# Perform substitutions in all udev rules files.
|
|
|
|
udevRules = stdenv.mkDerivation {
|
|
|
|
name = "udev-rules";
|
2008-07-02 20:06:34 +02:00
|
|
|
#src = cleanSource ./udev-rules;
|
|
|
|
buildCommand = ''
|
2007-03-04 00:20:08 +01:00
|
|
|
ensureDir $out
|
2008-07-02 20:06:34 +02:00
|
|
|
ln -s ${nixRules} $out/${nixRules.name}
|
2007-07-22 04:07:02 +02:00
|
|
|
shopt -s nullglob
|
2008-07-02 20:06:34 +02:00
|
|
|
cp ${udev}/etc/udev/rules.d/50-udev-default.rules $out/
|
|
|
|
cp ${udev}/etc/udev/rules.d/60-persistent-storage.rules $out/
|
|
|
|
cp ${udev}/etc/udev/rules.d/95-udev-late.rules $out/
|
2007-07-22 04:07:02 +02:00
|
|
|
for i in ${toString extraUdevPkgs}; do
|
|
|
|
for j in $i/etc/udev/rules.d/*; do
|
|
|
|
ln -s $j $out/$(basename $j)
|
|
|
|
done
|
|
|
|
done
|
2008-07-02 20:06:34 +02:00
|
|
|
''; # */
|
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
|
2008-07-01 10:28:56 +02:00
|
|
|
${udev}/sbin/udevadm trigger
|
|
|
|
${udev}/sbin/udevadm settle # wait for udev to finish
|
2008-06-20 18:09:48 +02:00
|
|
|
touch ${devicesCreated}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill udev, let Upstart restart and monitor it. (This is nasty,
|
2008-07-01 10:28:56 +02:00
|
|
|
# but we have to run `udevadm trigger' first. Maybe we can use
|
2008-06-20 18:09:48 +02:00
|
|
|
# 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
|
|
|
|
2008-07-02 20:06:34 +02:00
|
|
|
passthru = {inherit udevRules;};
|
2006-12-13 13:17:38 +01:00
|
|
|
}
|