Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions nixos/modules/virtualisation/anbox.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let

cfg = config.virtualisation.anbox;
kernelPackages = config.boot.kernelPackages;
useAnboxModules = kernelPackages.kernelOlder "5.0";
addrOpts = v: addr: pref: name: {
address = mkOption {
default = addr;
Expand Down Expand Up @@ -73,13 +74,17 @@ in

environment.systemPackages = with pkgs; [ anbox ];

boot.kernelModules = [ "ashmem_linux" "binder_linux" ];
boot.extraModulePackages = [ kernelPackages.anbox ];
# Mainline ashmem/binder drivers not available as modules
boot.kernelModules = optionals useAnboxModules [ "ashmem_linux" "binder_linux" ];
boot.extraModulePackages = optional useAnboxModules kernelPackages.anbox;

services.udev.extraRules = ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this stay but put behind a conditional for useAnboxModules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell these rules don't do anything anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't recall but they either don't run or anbox works correctly with the default mode anyways.

KERNEL=="ashmem", NAME="%k", MODE="0666"
KERNEL=="binder*", NAME="%k", MODE="0666"
'';
systemd.mounts = optional (!useAnboxModules) {
requiredBy = [ "anbox-container-manager.service" ];
description = "Anbox Binder File System";
what = "binder";
where = "/dev/binderfs";
type = "binder";
};

virtualisation.lxc.enable = true;
networking.bridges.anbox0.interfaces = [];
Expand Down Expand Up @@ -129,7 +134,8 @@ in
--container-network-gateway=${cfg.ipv4.gateway.address} \
--container-network-dns-servers=${cfg.ipv4.dns} \
--use-rootfs-overlay \
--privileged
--privileged \
--daemon
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you have to add Type=fork if you use daemon here?
You are adding it only to avoid the warning or any other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add it to avoid the warning but the process doesn't fork anyways, or at least doesn't exit.

'';
};
};
Expand Down
37 changes: 37 additions & 0 deletions nixos/tests/anbox.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import ./make-test-python.nix ({ pkgs, ... }:

{
name = "anbox";
meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ mvnetbiz ];
};

machine = { pkgs, config, ... }: {
imports = [
./common/user-account.nix
./common/x11.nix
];

environment.systemPackages = with pkgs; [ android-tools ];

test-support.displayManager.auto.user = "alice";

virtualisation.anbox.enable = true;
virtualisation.memorySize = 2500;
};

testScript = { nodes, ... }: let
user = nodes.machine.config.users.users.alice;
bus = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${toString user.uid}/bus";
in ''
machine.wait_for_x()

machine.wait_until_succeeds(
"sudo -iu alice ${bus} anbox wait-ready"
)

machine.wait_until_succeeds("adb shell true")

print(machine.succeed("adb devices"))
'';
})
10 changes: 9 additions & 1 deletion pkgs/os-specific/linux/anbox/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,15 @@ stdenv.mkDerivation rec {
libcap
libdwarf
libGL
lxc
# Broken with lxc 4.0.7 or later
# https://github.com/anbox/anbox/issues/1801
(lxc.overrideAttrs (old: rec {
version = "4.0.6";
src = fetchurl {
url = "https://linuxcontainers.org/downloads/lxc/lxc-${version}.tar.gz";
sha256 = "0qz4l7mlhq7hx53q606qgvkyzyr01glsw290v8ppzvxn1fydlrci";
};
}))
mesa
properties-cpp
protobuf protobufc
Expand Down
6 changes: 6 additions & 0 deletions pkgs/os-specific/linux/kernel/common-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,12 @@ let

X86_AMD_PLATFORM_DEVICE = yes;

ASHMEM = { optional = true; tristate = whenAtLeast "5.0" "y";};
ANDROID = { optional = true; tristate = whenAtLeast "5.0" "y";};
ANDROID_BINDER_IPC = { optional = true; tristate = whenAtLeast "5.0" "y";};
ANDROID_BINDERFS = { optional = true; tristate = whenAtLeast "5.0" "y";};
ANDROID_BINDER_DEVICES = { optional = true; freeform = whenAtLeast "5.0" "binder,hwbinder,vndbinder";};

} // optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "aarch64-linux") {
# Enable CPU/memory hotplug support
# Allows you to dynamically add & remove CPUs/memory to a VM client running NixOS without requiring a reboot
Expand Down