1{
2 lib,
3 stdenv,
4 replaceVarsWith,
5 udevCheckHook,
6}:
7
8# Provides a facility to hook into rfkill changes.
9#
10# Exemplary usage:
11#
12# Add this package to udev.packages, e.g.:
13# udev.packages = [ pkgs.rfkill_udev ];
14#
15# Add a hook script in the managed etc directory, e.g.:
16# etc."rfkill.hook" = {
17# mode = "0755";
18# text = ''
19# #!${pkgs.runtimeShell}
20#
21# if [ "$RFKILL_STATE" -eq "1" ]; then
22# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-on
23# else
24# exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-off
25# fi
26# '';
27# }
28
29# Note: this package does not need the binaries
30# in the rfkill package.
31
32let
33 rfkillHook = replaceVarsWith {
34 replacements = { inherit (stdenv) shell; };
35 isExecutable = true;
36 src = ./rfkill-hook.sh;
37 };
38in
39stdenv.mkDerivation {
40 name = "rfkill-udev";
41
42 nativeBuildInputs = [
43 udevCheckHook
44 ];
45
46 doInstallCheck = true;
47
48 dontUnpack = true;
49 dontBuild = true;
50
51 installPhase = ''
52 mkdir -p "$out/etc/udev/rules.d/";
53 cat > "$out/etc/udev/rules.d/90-rfkill.rules" << EOF
54 SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="$out/bin/rfkill-hook.sh"
55 EOF
56
57 mkdir -p "$out/bin/";
58 cp ${rfkillHook} "$out/bin/rfkill-hook.sh"
59 '';
60
61 meta = with lib; {
62 homepage = "http://wireless.kernel.org/en/users/Documentation/rfkill";
63 description = "Rules+hook for udev to catch rfkill state changes";
64 mainProgram = "rfkill-hook.sh";
65 platforms = platforms.linux;
66 license = licenses.mit;
67 };
68}