|
| 1 | +{ config, pkgs, lib, ... }: |
| 2 | +let |
| 3 | + vuinputd = pkgs.rustPlatform.buildRustPackage { |
| 4 | + pname = "vuinputd"; |
| 5 | + version = "0.3.2-git"; |
| 6 | + |
| 7 | + buildType = "debug"; |
| 8 | + |
| 9 | + nativeBuildInputs = [ |
| 10 | + pkgs.pkg-config |
| 11 | + pkgs.rustPlatform.bindgenHook |
| 12 | + # breakpointHook |
| 13 | + ]; |
| 14 | + |
| 15 | + buildInputs = [pkgs.udev pkgs.fuse3]; |
| 16 | + |
| 17 | + src = pkgs.fetchFromGitHub { |
| 18 | + owner = "joleuger"; |
| 19 | + repo = "vuinputd"; |
| 20 | + rev = "8c40fdc12005319ea16dceb752a8822abfc6039a"; |
| 21 | + hash = "sha256-8Q34B04BngZqRLyixeFq8F1t5wFnk6JpaG3EEbgKRcU="; |
| 22 | + }; |
| 23 | + |
| 24 | + cargoHash = "sha256-nJw9bRh6Yn9g1H5SeoT6zxgZLCqV3AtAs9gMfE+P+CU="; |
| 25 | + |
| 26 | + # Recent versions of fuse3 can also have libfuse_* types |
| 27 | + postPatch = '' |
| 28 | + substituteInPlace cuse-lowlevel/build.rs \ |
| 29 | + --replace-fail '.allowlist_type("(?i)^fuse.*")' '.allowlist_type("(?i)^(fuse|libfuse).*")' |
| 30 | + ''; |
| 31 | + |
| 32 | + postInstall = '' |
| 33 | + mkdir -p $out/lib/udev/rules.d |
| 34 | + mkdir $out/lib/udev/hwdb.d |
| 35 | + cp vuinputd/udev/*.rules $out/lib/udev/rules.d/ |
| 36 | + cp vuinputd/udev/*.hwdb $out/lib/udev/hwdb.d/ |
| 37 | + ''; |
| 38 | +}; |
| 39 | +in |
| 40 | +{ |
| 41 | + environment.systemPackages = with pkgs; [ |
| 42 | + vim |
| 43 | + pkg-config |
| 44 | + udev |
| 45 | + fuse3 |
| 46 | + git |
| 47 | + rustc |
| 48 | + cargo |
| 49 | + bubblewrap # for testing |
| 50 | + |
| 51 | + vuinputd |
| 52 | + ]; |
| 53 | + |
| 54 | + systemd.services.vuinputd = { |
| 55 | + enable = true; |
| 56 | + wantedBy = ["multi-user.target"]; |
| 57 | + unitConfig = { |
| 58 | + Description = "Virtual input (/dev/vuinput) daemon"; |
| 59 | + }; |
| 60 | + serviceConfig = { |
| 61 | + Type = "exec"; |
| 62 | + ExecStartPre = pkgs.writeShellScript "mount-tmpfs-dev-input" '' |
| 63 | + mkdir -p /run/vuinputd/vuinput/dev-input |
| 64 | + ${pkgs.util-linux}/bin/mount -t tmpfs -o rw,dev,nosuid tpmfs /run/vuinputd/vuinput/dev-input |
| 65 | + ''; |
| 66 | + ExecStart = "${lib.getExe vuinputd} --major 120 --minor 414795 --placement on-host"; |
| 67 | + ExecStopPost = pkgs.writeShellScript "umount-dev-input" '' |
| 68 | + ${pkgs.util-linux}/bin/umount /run/vuinputd/vuinput/dev-input |
| 69 | + ''; |
| 70 | + Restart = "on-failure"; |
| 71 | + DeviceAllow = "char-* rwm"; |
| 72 | + |
| 73 | + Environment = [ |
| 74 | + "RUST_LOG=debug" |
| 75 | + ]; |
| 76 | + }; |
| 77 | + }; |
| 78 | + systemd.services.vuinputd-chmod = { |
| 79 | + unitConfig.Description = "Chmod 666 the /dev/vuinput"; |
| 80 | + wantedBy = ["vuinputd.service"]; |
| 81 | + after = ["vuinputd.service"]; |
| 82 | + |
| 83 | + serviceConfig = { |
| 84 | + ExecStart = pkgs.writeShellScript "chmod-vuinput" '' |
| 85 | + sleep 2 && chmod 666 /dev/vuinput |
| 86 | + ''; |
| 87 | + }; |
| 88 | + }; |
| 89 | +} |
| 90 | + |
0 commit comments