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