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