From 1b2d50c14f7e1a319e5c167810179a3e0e6397e3 Mon Sep 17 00:00:00 2001 From: Arie Middelkoop Date: Fri, 24 Feb 2012 01:35:59 +0000 Subject: rfkill udev package. svn path=/nixpkgs/trunk/; revision=32532 --- pkgs/os-specific/linux/rfkill/rfkill-hook.sh | 19 +++++++++++ pkgs/os-specific/linux/rfkill/udev.nix | 49 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 pkgs/os-specific/linux/rfkill/rfkill-hook.sh create mode 100644 pkgs/os-specific/linux/rfkill/udev.nix (limited to 'pkgs/os-specific/linux/rfkill') 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 -- cgit 1.4.1