-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathflake.nix
More file actions
123 lines (103 loc) · 3.71 KB
/
flake.nix
File metadata and controls
123 lines (103 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
description = "A basic flake for Flutter development with Nix and NixOS";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
utils.url = "github:limwa/nix-flake-utils";
# For hardware-accelerated Android emulator on NixOS
limwa.url = "github:limwa/nix-registry";
limwa.inputs.nixpkgs.follows = "nixpkgs";
# Needed for shell.nix
flake-compat.url = "github:edolstra/flake-compat";
};
outputs = {
self,
nixpkgs,
utils,
limwa,
...
}:
utils.lib.mkFlakeWith {
forEachSystem = system: rec {
outputs = utils.lib.forSystem self system;
pkgs = import nixpkgs {
inherit system;
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
overlays = [
# For hardware-accelerated Android emulator on NixOS
limwa.overlays.android
];
};
# Reuse the same Android SDK, JDK and Flutter versions across all derivations
androidComposition = pkgs.androidenv.composeAndroidPackages {
includeNDK = "if-supported";
buildToolsVersions = ["35.0.0"];
cmakeVersions = ["3.22.1"];
platformVersions = ["36" "35" "34"];
ndkVersions = ["28.2.13676358"];
};
flutter = pkgs.flutter;
jdks = with pkgs; [jdk21 jdk17];
};
} {
formatter = {pkgs, ...}: pkgs.alejandra;
devShells = utils.lib.invokeAttrs {
default = {outputs, ...}: outputs.devShells.flutter;
# Flutter development shell
flutter = {
pkgs,
androidComposition,
flutter,
jdks,
...
}: let
jdk = builtins.elemAt jdks 0;
buildToolsVersion = pkgs.lib.getVersion (builtins.elemAt androidComposition.build-tools 0);
in
pkgs.mkShell rec {
meta.description = "A development shell with Flutter and an Android SDK installation";
env = {
# Android environment variables
ANDROID_HOME = "${androidComposition.androidsdk}/libexec/android-sdk";
# Java environment variables
JAVA_HOME = "${jdk}";
GRADLE_OPTS = pkgs.lib.concatStringsSep " " [
"-Dorg.gradle.project.android.aapt2FromMavenOverride=${env.ANDROID_HOME}/build-tools/${buildToolsVersion}/aapt2"
# KMS pls ;w;
# https://github.com/gradle/gradle/issues/33307
"-Dorg.gradle.project.org.gradle.java.installations.auto-detect=false"
"-Dorg.gradle.project.org.gradle.java.installations.auto-download=false"
"-Dorg.gradle.project.org.gradle.java.installations.paths=${pkgs.lib.concatStringsSep "," jdks}"
];
};
packages = [
androidComposition.androidsdk
flutter
jdk
];
shellHook = ''
export PATH="${env.ANDROID_HOME}/build-tools/${buildToolsVersion}:$PATH"
'';
};
};
packages = utils.lib.invokeAttrs {
emulator = {pkgs, ...}:
pkgs.limwa.android.wrapEmulatorWith {
useHardwareGraphics = "vulkan";
} (
pkgs.androidenv.emulateApp {
name = "uni-emulator";
deviceName = "uni_emulator";
platformVersion = "36";
abiVersion = "x86_64";
systemImageType = "google_apis_playstore";
# Specify user home to speed up boot times and avoid creating
# a lot of avd instances taking up disk space
androidUserHome = "\$HOME/.android";
}
);
};
};
}