1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
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
21in {
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}