From 19dbd21f4b63586179746a0db0e644000cb575eb Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 18 Feb 2024 23:08:50 +0300 Subject: [PATCH] host/home: add android sdk --- Makefile | 8 +++--- flake.nix | 2 +- home/users/jan/default.nix | 4 +++ nixos/hosts/home/default.nix | 53 +++++++++++++++++++++++++++++++++++- 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index f69a8ae..52e7fd8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -NIX_RUN := sudo nix run .\# +NIX_RUN := nix run .\# NIX_LOCK := nix flake lock DEPS_MY := \ @@ -34,14 +34,14 @@ define machine_rule .PHONY: $(1) $(1): ; systemctl --user reset-failed - $$(NIX_RUN)switch/$(1) + sudo $$(NIX_RUN)switch/$(1) .PHONY: rollback-$(1) rollback-$(1): - $$(NIX_RUN)rollback/$(1) + sudo $$(NIX_RUN)rollback/$(1) .PHONY: test-$(1) -test-$(1): ; $$(NIX_RUN)test/$(1) +test-$(1): ; sudo $$(NIX_RUN)test/$(1) endef define vps_rule diff --git a/flake.nix b/flake.nix index cb66d77..686e30b 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ (hostname: machine: pkgs.writeShellScript "deploy-${hostname}" '' ${nixos-rebuild}/bin/nixos-rebuild switch \ --flake .#${hostname} \ - --target-host ${machine.config.deployment.targetHost} \ + --target-host root@${machine.config.deployment.targetHost} \ $@ '') vpsMachines); diff --git a/home/users/jan/default.nix b/home/users/jan/default.nix index c056e17..8e2cd23 100644 --- a/home/users/jan/default.nix +++ b/home/users/jan/default.nix @@ -29,6 +29,8 @@ in (lib.mkIf config.virtualisation.docker.enable "docker") (lib.mkIf config.services.transmission.enable "transmission") (lib.mkIf config.services.kubo.enable "ipfs") + (lib.mkIf config.programs.adb.enable "adbusers") + (lib.mkIf config.programs.adb.enable "plugdev") ]; shell = pkgs.zsh; hashedPasswordFile = config.age.secrets.users-jan-passfile.path; @@ -36,6 +38,8 @@ in openssh.authorizedKeys.keys = data.publicKeys.users.jan; }; + users.groups.plugdev = lib.mkIf config.programs.adb.enable { }; + home-manager.users.jan = { lib, ... }: { imports = [ inputs.wired.homeManagerModules.default diff --git a/nixos/hosts/home/default.nix b/nixos/hosts/home/default.nix index b29e463..05b7cc9 100644 --- a/nixos/hosts/home/default.nix +++ b/nixos/hosts/home/default.nix @@ -1,5 +1,6 @@ { config, pkgs, ... }: + { imports = [ # Include the results of the hardware scan. @@ -48,7 +49,12 @@ # enable bluetooth hardware.bluetooth.enable = true; - local.nix.allowUnfreePackages = [ "cnijfilter2" "memtest86" ]; + nixpkgs.config.allowUnfree = true; + local.nix.allowUnfreePackages = [ + "cnijfilter2" + "memtest86" + "android-sdk-cmdline-tools" + ]; services.openssh.enable = true; @@ -118,4 +124,49 @@ # 3D printing local.octoprint.enable = true; + + # Android + programs.adb.enable = true; + programs.java = { + enable = true; + package = pkgs.jdk17; + }; + + nixpkgs.config.android_sdk.accept_license = true; + + environment.variables = + let + buildToolsVersion = "33.0.2"; + androidComposition = pkgs.unstable.androidenv.composeAndroidPackages { + platformToolsVersion = "34.0.5"; + buildToolsVersions = [ buildToolsVersion ]; + includeEmulator = false; + emulatorVersion = "34.1.9"; + platformVersions = [ "29" "30" "33" ]; + includeSources = false; + includeSystemImages = false; + systemImageTypes = [ "google_apis_playstore" ]; + abiVersions = [ "armeabi-v7a" "arm64-v8a" ]; + cmakeVersions = [ "3.10.2" ]; + includeNDK = true; + ndkVersions = [ "23.2.8568313" ]; + useGoogleAPIs = false; + useGoogleTVAddOns = false; + includeExtras = [ + "extras;google;gcm" + ]; + }; + in + rec { + ANDROID_SDK_ROOT = "${androidComposition.androidsdk}/libexec/android-sdk"; + ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle"; + + # Use the same buildToolsVersion here + # GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${buildToolsVersion}/aapt2"; + # JAVA_HOME = pkgs.jdk17.home; + }; + + services.udev.extraRules = '' + SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666", GROUP="plugdev" + ''; }