Merge pull request #141076 from CajuM/waydroid-module

authored by Maciej Krüger and committed by GitHub 83c93c8e c935f5e0

+67
+1
nixos/modules/module-list.nix
··· 1189 1189 ./virtualisation/virtualbox-guest.nix 1190 1190 ./virtualisation/virtualbox-host.nix 1191 1191 ./virtualisation/vmware-guest.nix 1192 + ./virtualisation/waydroid.nix 1192 1193 ./virtualisation/xen-dom0.nix 1193 1194 ./virtualisation/xe-guest-utilities.nix 1194 1195 ]
+66
nixos/modules/virtualisation/waydroid.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + 7 + cfg = config.virtualisation.waydroid; 8 + kernelPackages = config.boot.kernelPackages; 9 + waydroidGbinderConf = pkgs.writeText "waydroid.conf" '' 10 + [Protocol] 11 + /dev/binder = aidl2 12 + /dev/vndbinder = aidl2 13 + /dev/hwbinder = hidl 14 + 15 + [ServiceManager] 16 + /dev/binder = aidl2 17 + /dev/vndbinder = aidl2 18 + /dev/hwbinder = hidl 19 + ''; 20 + 21 + in { 22 + 23 + options.virtualisation.waydroid = { 24 + enable = mkEnableOption "Waydroid"; 25 + }; 26 + 27 + config = mkIf cfg.enable { 28 + assertions = singleton { 29 + assertion = versionAtLeast (getVersion config.boot.kernelPackages.kernel) "4.18"; 30 + message = "Waydroid needs user namespace support to work properly"; 31 + }; 32 + 33 + system.requiredKernelConfig = with config.lib.kernelConfig; [ 34 + (isEnabled "ANDROID_BINDER_IPC") 35 + (isEnabled "ANDROID_BINDERFS") 36 + (isEnabled "ASHMEM") 37 + ]; 38 + 39 + environment.etc."gbinder.d/waydroid.conf".source = waydroidGbinderConf; 40 + 41 + environment.systemPackages = with pkgs; [ waydroid ]; 42 + 43 + networking.firewall.trustedInterfaces = [ "waydroid0" ]; 44 + 45 + virtualisation.lxc.enable = true; 46 + 47 + systemd.services.waydroid-container = { 48 + description = "Waydroid Container"; 49 + 50 + wantedBy = [ "multi-user.target" ]; 51 + 52 + path = with pkgs; [ getent iptables iproute kmod nftables util-linux which ]; 53 + 54 + unitConfig = { 55 + ConditionPathExists = "/var/lib/waydroid/lxc/waydroid"; 56 + }; 57 + 58 + serviceConfig = { 59 + ExecStart = "${pkgs.waydroid}/bin/waydroid container start"; 60 + ExecStop = "${pkgs.waydroid}/bin/waydroid container stop"; 61 + ExecStopPost = "${pkgs.waydroid}/bin/waydroid session stop"; 62 + }; 63 + }; 64 + }; 65 + 66 + }