at 24.11-pre 1.9 kB view raw
1{ config, lib, pkgs, ... }: 2 3let 4 cfg = config.virtualisation.waydroid; 5 kCfg = config.lib.kernelConfig; 6 kernelPackages = config.boot.kernelPackages; 7 waydroidGbinderConf = pkgs.writeText "waydroid.conf" '' 8 [Protocol] 9 /dev/binder = aidl2 10 /dev/vndbinder = aidl2 11 /dev/hwbinder = hidl 12 13 [ServiceManager] 14 /dev/binder = aidl2 15 /dev/vndbinder = aidl2 16 /dev/hwbinder = hidl 17 ''; 18 19in 20{ 21 22 options.virtualisation.waydroid = { 23 enable = lib.mkEnableOption "Waydroid"; 24 }; 25 26 config = lib.mkIf cfg.enable { 27 assertions = lib.singleton { 28 assertion = lib.versionAtLeast (lib.getVersion config.boot.kernelPackages.kernel) "4.18"; 29 message = "Waydroid needs user namespace support to work properly"; 30 }; 31 32 system.requiredKernelConfig = [ 33 (kCfg.isEnabled "ANDROID_BINDER_IPC") 34 (kCfg.isEnabled "ANDROID_BINDERFS") 35 (kCfg.isEnabled "MEMFD_CREATE") 36 ]; 37 38 /* NOTE: we always enable this flag even if CONFIG_PSI_DEFAULT_DISABLED is not on 39 as reading the kernel config is not always possible and on kernels where it's 40 already on it will be no-op 41 */ 42 boot.kernelParams = [ "psi=1" ]; 43 44 environment.etc."gbinder.d/waydroid.conf".source = waydroidGbinderConf; 45 46 environment.systemPackages = with pkgs; [ waydroid ]; 47 48 networking.firewall.trustedInterfaces = [ "waydroid0" ]; 49 50 virtualisation.lxc.enable = true; 51 52 systemd.services.waydroid-container = { 53 description = "Waydroid Container"; 54 55 wantedBy = [ "multi-user.target" ]; 56 57 serviceConfig = { 58 ExecStart = "${pkgs.waydroid}/bin/waydroid -w container start"; 59 ExecStop = "${pkgs.waydroid}/bin/waydroid container stop"; 60 ExecStopPost = "${pkgs.waydroid}/bin/waydroid session stop"; 61 }; 62 }; 63 64 systemd.tmpfiles.rules = [ 65 "d /var/lib/misc 0755 root root -" # for dnsmasq.leases 66 ]; 67 }; 68 69}