summary refs log tree commit diff
path: root/pkgs/os-specific/linux/rfkill
diff options
context:
space:
mode:
authorArie Middelkoop <amiddelk@gmail.com>2012-02-24 01:35:59 +0000
committerArie Middelkoop <amiddelk@gmail.com>2012-02-24 01:35:59 +0000
commit1b2d50c14f7e1a319e5c167810179a3e0e6397e3 (patch)
treeedefea4d8857a9a8057400084eeb3a657ce926b1 /pkgs/os-specific/linux/rfkill
parented813f3955595ffd594570f74f406f3b6319610a (diff)
downloadnixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar.gz
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar.bz2
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar.lz
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar.xz
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.tar.zst
nixpkgs-1b2d50c14f7e1a319e5c167810179a3e0e6397e3.zip
rfkill udev package.
svn path=/nixpkgs/trunk/; revision=32532
Diffstat (limited to 'pkgs/os-specific/linux/rfkill')
-rwxr-xr-xpkgs/os-specific/linux/rfkill/rfkill-hook.sh19
-rw-r--r--pkgs/os-specific/linux/rfkill/udev.nix49
2 files changed, 68 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/rfkill/rfkill-hook.sh b/pkgs/os-specific/linux/rfkill/rfkill-hook.sh
new file mode 100755
index 00000000000..d07c7298183
--- /dev/null
+++ b/pkgs/os-specific/linux/rfkill/rfkill-hook.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# Executes a hook in case of a change to the
+# rfkill state. The hook can be passed as
+# environment variable, or present as executable
+# file.
+
+if [ -z "$RFKILL_STATE" ]; then
+  echo "rfkill-hook: error: RFKILL_STATE variable not set"
+  exit 1
+fi
+
+if [ -x /var/run/current-system/etc/rfkill.hook ]; then
+  exec /var/run/current-system/etc/rfkill.hook
+elif [ ! -z "$RFKILL_HOOK" ]; then
+  exec $RFKILL_HOOK
+else
+  echo "rfkill-hook: $RFKILL_STATE"
+fi
\ No newline at end of file
diff --git a/pkgs/os-specific/linux/rfkill/udev.nix b/pkgs/os-specific/linux/rfkill/udev.nix
new file mode 100644
index 00000000000..6cf6e4adfa0
--- /dev/null
+++ b/pkgs/os-specific/linux/rfkill/udev.nix
@@ -0,0 +1,49 @@
+{ stdenv }:
+
+# Provides a facility to hook into rfkill changes.
+#
+# Exemplary usage:
+#
+# Add this package to udev.packages, e.g.:
+#   udev.packages = [ pkgs.rfkill_udev ];
+#
+# Add a hook script in the managed etc directory, e.g.:
+#   etc = [
+#     { source = pkgs.writeScript "rtfkill.hook" ''
+#         #!/bin/sh
+#
+#         if [ "$RFKILL_STATE" -eq "1" ]; then
+#           exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-on
+#         else
+#           exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-off
+#         fi
+#       '';
+#       target = "rfkill.hook";
+#     }
+
+# Note: this package does not need the binaries
+# in the rfkill package.
+
+stdenv.mkDerivation {
+  name = "rfkill-udev";
+
+  unpackPhase = "true";
+  dontBuild = true;
+
+  installPhase = ''
+    ensureDir "$out/etc/udev/rules.d/";
+    cat > "$out/etc/udev/rules.d/90-rfkill.rules" << EOF
+      SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="$out/bin/rfkill-hook.sh" 
+    EOF
+
+    ensureDir "$out/bin/";
+    cp ${./rfkill-hook.sh} "$out/bin/rfkill-hook.sh"
+    chmod +x "$out/bin/rfkill-hook.sh";
+  '';
+
+  meta = {
+    homepage = http://wireless.kernel.org/en/users/Documentation/rfkill;
+    description = "Rules+hook for udev to catch rfkill state changes";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
\ No newline at end of file