From 7e76b12d57ba7bcb77e178fbfb60b5597f061f52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai-Drosi=20C=C3=A2ju?= Date: Sat, 9 Oct 2021 10:07:54 +0300 Subject: [PATCH] nixos/waydroid: init --- nixos/modules/module-list.nix | 1 + nixos/modules/virtualisation/waydroid.nix | 66 +++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 nixos/modules/virtualisation/waydroid.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index f701f38c9dd..ab0673dbb5c 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1178,6 +1178,7 @@ ./virtualisation/virtualbox-guest.nix ./virtualisation/virtualbox-host.nix ./virtualisation/vmware-guest.nix + ./virtualisation/waydroid.nix ./virtualisation/xen-dom0.nix ./virtualisation/xe-guest-utilities.nix ] diff --git a/nixos/modules/virtualisation/waydroid.nix b/nixos/modules/virtualisation/waydroid.nix new file mode 100644 index 00000000000..854ab056dbb --- /dev/null +++ b/nixos/modules/virtualisation/waydroid.nix @@ -0,0 +1,66 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.virtualisation.waydroid; + kernelPackages = config.boot.kernelPackages; + waydroidGbinderConf = pkgs.writeText "waydroid.conf" '' + [Protocol] + /dev/binder = aidl2 + /dev/vndbinder = aidl2 + /dev/hwbinder = hidl + + [ServiceManager] + /dev/binder = aidl2 + /dev/vndbinder = aidl2 + /dev/hwbinder = hidl + ''; + +in { + + options.virtualisation.waydroid = { + enable = mkEnableOption "Waydroid"; + }; + + config = mkIf cfg.enable { + assertions = singleton { + assertion = versionAtLeast (getVersion config.boot.kernelPackages.kernel) "4.18"; + message = "Waydroid needs user namespace support to work properly"; + }; + + system.requiredKernelConfig = with config.lib.kernelConfig; [ + (isEnabled "ANDROID_BINDER_IPC") + (isEnabled "ANDROID_BINDERFS") + (isEnabled "ASHMEM") + ]; + + environment.etc."gbinder.d/waydroid.conf".source = waydroidGbinderConf; + + environment.systemPackages = with pkgs; [ waydroid ]; + + networking.firewall.trustedInterfaces = [ "waydroid0" ]; + + virtualisation.lxc.enable = true; + + systemd.services.waydroid-container = { + description = "Waydroid Container"; + + wantedBy = [ "multi-user.target" ]; + + path = with pkgs; [ getent iptables iproute kmod nftables util-linux which ]; + + unitConfig = { + ConditionPathExists = "/var/lib/waydroid/lxc/waydroid"; + }; + + serviceConfig = { + ExecStart = "${pkgs.waydroid}/bin/waydroid container start"; + ExecStop = "${pkgs.waydroid}/bin/waydroid container stop"; + ExecStopPost = "${pkgs.waydroid}/bin/waydroid session stop"; + }; + }; + }; + +}