summary refs log tree commit diff
diff options
context:
space:
mode:
authorMihai-Drosi Câju <cajum.bugs@yandex.com>2021-10-09 10:07:54 +0300
committerMaciej Krüger <mkg20001@gmail.com>2021-11-06 08:57:57 +0100
commit7e76b12d57ba7bcb77e178fbfb60b5597f061f52 (patch)
treed0934a66c007b128edd15218a42d5c838856aca2
parenteb88cf6eed8d910f91974ad5810f12b6097ac92f (diff)
downloadnixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar.gz
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar.bz2
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar.lz
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar.xz
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.tar.zst
nixpkgs-7e76b12d57ba7bcb77e178fbfb60b5597f061f52.zip
nixos/waydroid: init
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/virtualisation/waydroid.nix66
2 files changed, 67 insertions, 0 deletions
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";
+      };
+    };
+  };
+
+}