rustdesk-flutter: add pipewire gstreame plugin (#379587)
[NixPkgs.git] / pkgs / os-specific / linux / rfkill / udev.nix
blob9d5ce46533e29a748237698ab7950afc736cb1f1
2   lib,
3   stdenv,
4   replaceVarsWith,
5 }:
7 # Provides a facility to hook into rfkill changes.
9 # Exemplary usage:
11 # Add this package to udev.packages, e.g.:
12 #   udev.packages = [ pkgs.rfkill_udev ];
14 # Add a hook script in the managed etc directory, e.g.:
15 #   etc."rfkill.hook" = {
16 #     mode = "0755";
17 #     text = ''
18 #       #!${pkgs.runtimeShell}
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 #   }
28 # Note: this package does not need the binaries
29 # in the rfkill package.
31 let
32   rfkillHook = replaceVarsWith {
33     replacements = { inherit (stdenv) shell; };
34     isExecutable = true;
35     src = ./rfkill-hook.sh;
36   };
38 stdenv.mkDerivation {
39   name = "rfkill-udev";
41   dontUnpack = true;
42   dontBuild = true;
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
50     mkdir -p "$out/bin/";
51     cp ${rfkillHook} "$out/bin/rfkill-hook.sh"
52   '';
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   };