-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.bak.nix
456 lines (425 loc) · 15.5 KB
/
flake.bak.nix
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
{
description = "Simple DEV Shell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
phps.url = "github:loophp/nix-shell";
android-nixpkgs.url = "github:tadfisher/android-nixpkgs";
android-nixpkgs.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils, phps, android-nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (
system:
let
sys = system;
l = nixpkgs.lib // builtins;
supportedSystems = [ "x86_64-linux" "aarch64-darwin" ];
forAllSystems = f: l.genAttrs supportedSystems
(system: f system (
import nixpkgs {
inherit system;
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
}
));
replace = rec {
replacer = a: b: str: nixpkgs.lib.strings.stringAsChars (x: if x == a then b else x) str;
dotToDash = replacer "." "-";
semicolonToDash = replacer ";" "-";
underscoreToDash = replacer "_" "-";
withDoubleQuote = str: ''"${str}"'';
};
nodejsVersion = 18;
javaVersion = 19;
androidBuildToolsVersion = "33.0.0";
androidPlatformsVersion = 33;
androidNDKVersion = "23.1.7779620";
createEmulator = pkgs:
let
inherit (pkgs.stdenv) isAarch64;
arch = if isAarch64 then "arm64-v8a" else "x86-64";
cpuArch = if isAarch64 then "arm64" else "x86-64";
in
rec
{
inherit cpuArch;
name = "dvt_${toString androidPlatformsVersion}";
abi.type = arch;
packages = "system-images;android-${toString androidPlatformsVersion};${tag.id};${abi.type}";
sysdir = "$ANDROID_SDK_ROOT/system-images/android-${toString androidPlatformsVersion}/${tag.id}/${abi.type}/";
tag.id = "google_apis_playstore";
avdRootPath = "$HOME/.android/avd";
avdPath = "${avdRootPath}/${name}.avd";
avdConfigIni = "${avdPath}/config.ini";
};
overlays = [
android-nixpkgs.overlays.default
(final: prev: rec {
nodejs = prev."nodejs-${toString nodejsVersion}_x";
yarn = prev.yarn.override { inherit nodejs; };
jdk = pkgs."jdk${toString javaVersion}";
gradle = prev.gradle.override {
java = jdk;
};
ruby = prev.ruby.withPackages (p: [ p.cocoapods ]);
androidSdk = let emulator = createEmulator prev; in
prev.androidSdk (s: [
s.platform-tools
s.cmdline-tools-latest
s.tools
s.patcher-v4
s.extras-google-google-play-services
s.emulator
s."build-tools-${replace.dotToDash androidBuildToolsVersion}"
s."ndk-${replace.dotToDash androidNDKVersion}"
s."platforms-android-${toString androidPlatformsVersion}"
s."${replace.underscoreToDash (replace.semicolonToDash emulator.packages)}"
]);
})
];
pkgs = import nixpkgs {
inherit overlays system;
config.allowUnfree = true;
config.android_sdk.accept_license = true;
};
run = pkg: "${pkgs.${pkg}}/bin/${pkg}";
scripts = let emulator = createEmulator pkgs; in
with pkgs; [
(writeScriptBin "helpme" ''
__usage="
👋 Welcome to react-native development environment. 🚀
If you see this message, it means your are inside the Nix shell ❄️.
[Info]===============================================================>
Env:
- JAVA_HOME: $JAVA_HOME
- ANDROID_HOME: $ANDROID_HOME
- ANDROID_SDK_ROOT: $ANDROID_SDK_ROOT
- ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT
Android Emulator:
- name: ${emulator.name}
- packages: ${emulator.packages}
Android SDK packages:
- build-tools: ${androidBuildToolsVersion}
- platforms-android: ${toString androidPlatformsVersion}
- ndk: ${androidNDKVersion}
Command available:
- start: start the project 🛹
- create-emulator: create emulator (default: android)
- align-emulator: align dev environment with AVD configurations
- gen-properties: generate local.properties in <currentDir>/android
- helpme: show this messages
Report/Help:
- https://github.com/eFishery/dvt
[Info]===============================================================>
"
echo "$__usage"
'')
# check dependencies
(writeScriptBin "check-react-native" ''
until ${run "yarn"} react-native -v > /dev/null 2>&1; do
echo "install dependencies..."
${run "yarn"} install || (echo failed instll dependencies with yarn; exit 1)
echo ""
read -p "Do you want to create an android emulator? [y/n]: " __is_create_emulator
[[ $__is_create_emulator == "y" ]] && create-emulator && align-emulator
sleep 0.5
done
'')
# align emulator configuration for sync system-images location and relateds.
(writeScriptBin "align-emulator" ''
[[ -f ${emulator.avdConfigIni} ]] && (
cat <<EOF > ${emulator.avdConfigIni}
PlayStore.enabled = enable
abi.type = ${emulator.abi.type}
avd.ini.encoding = UTF-8
skin.name = 1080x1920
hw.lcd.density = 480
hw.keyboard = yes
hw.cpu.arch = ${emulator.cpuArch}
image.sysdir.1 = ${emulator.sysdir}
tag.display = Google Play
tag.id = ${emulator.tag.id}
disk.dataPartition.size = 6442450944
EOF
echo "🚀 Updated emulator (${emulator.name}) configurations."
)
'')
# create emulator
(writeScriptBin "create-emulator" ''
echo "no" | ${androidSdk}/bin/avdmanager \
--clear-cache -s \
create avd -f \
-n ${emulator.name} \
-p ${emulator.avdPath} \
-g ${emulator.tag.id} \
-b ${emulator.abi.type} \
-k ${replace.withDoubleQuote emulator.packages} \
|| (echo "❌ Fail: to create emulator"; exit 1)
'')
# TODO: delete emulator
# (writeScriptBin "delete-emulator" ''
# Try your self here!
# '')
# start react-native metro bundler
(writeScriptBin "start" ''
check-react-native
align-emulator
$PWD/node_modules/.bin/react-native start $@
'')
# gen-properties
(writeScriptBin "gen-properties" ''
cat <<EOF > ./android/local.properties
sdk.dir=$ANDROID_SDK_ROOT
ndk.dir=$ANDROID_NDK_ROOT
EOF || (echo "are you sure in the right project directory?"; exit 1)
'')
];
in
{
devShells.Android = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodejs
yarn
jdk
gradle
ruby
androidSdk
watchman
flutter
at-spi2-core.dev
clang
cmake
dbus.dev
gtk3
libdatrie
libepoxy.dev
util-linux.dev
libselinux
libsepol
libthai
libxkbcommon
ninja
pcre
pcre2.dev
pkg-config
xorg.libXdmcp
xorg.libXtst
android-studio
] ++ scripts;
ANDROID_NDK_ROOT = "${pkgs.androidSdk.outPath}/share/android-sdk/ndk/${androidNDKVersion}";
FLUTTER_ROOT = pkgs.flutter;
LD_LIBRARY_PATH = "${pkgs.libepoxy}/lib";
CHROME_EXECUTABLE = "google-chrome-stable";
ANDROID_STUDIO = pkgs.android-studio;
ANDROID_JAVA_HOME = pkgs.jdk.home;
shellHook = ''
helpme
if ! [ -d $HOME/.cache/flutter/ ]
then
mkdir $HOME/.cache/flutter/
fi
ln -f -s ${pkgs.flutter}/bin/cache/dart-sdk $HOME/.cache/flutter/
'';
};
devShells.C = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive];
buildInputs = with pkgs; [
at-spi2-core.dev
clang
cmake
dbus.dev
gtk3
libdatrie
libepoxy.dev
util-linux.dev
libselinux
libsepol
libthai
libxkbcommon
ninja
pcre
pcre2.dev
pkg-config
xorg.libXdmcp
xorg.libXtst
];
shellHook = with pkgs; ''
echo "Anda menggunakan C Compiler versi $(clang --version)"
'';
};
devShells.Java = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive];
buildInputs = with pkgs; [
jdk
];
shellHook = with pkgs; ''
echo "Anda menggunakan Java versi $(java --version)"
'';
};
devShells.NodeJS14 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodejs-14_x
nodePackages.yarn
nodePackages.prettier
nodePackages.typescript
nodePackages.prisma
openssl
];
shellHook = with pkgs; ''
export PRISMA_MIGRATION_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"
export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"
export PATH=~/.npm-packages/bin:$PATH
export NODE_PATH=~/.npm-packages/lib/node_modules
echo "Anda menggunakan NodeJS versi $(node -v)"
'';
};
devShells.NodeJS16 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodejs-16_x
nodePackages.yarn
nodePackages.prettier
nodePackages.typescript
nodePackages.prisma
openssl
];
shellHook = with pkgs; ''
export PRISMA_MIGRATION_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"
export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"
export PATH=~/.npm-packages/bin:$PATH
export NODE_PATH=~/.npm-packages/lib/node_modules
echo "Anda menggunakan NodeJS versi $(node -v)"
'';
};
devShells.NodeJS18 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodejs
nodePackages.yarn
nodePackages.prettier
nodePackages.typescript
nodePackages.prisma
openssl
];
shellHook = with pkgs; ''
export PRISMA_MIGRATION_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"
export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"
export PATH=~/.npm-packages/bin:$PATH
export NODE_PATH=~/.npm-packages/lib/node_modules
echo "Anda menggunakan NodeJS versi $(node -v)"
'';
};
devShells.NodeJS19 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
nodejs-19_x
nodePackages.yarn
nodePackages.prettier
nodePackages.typescript
nodePackages.prisma
openssl
];
shellHook = with pkgs; ''
export PRISMA_MIGRATION_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"
export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"
export PATH=~/.npm-packages/bin:$PATH
export NODE_PATH=~/.npm-packages/lib/node_modules
echo "Anda menggunakan NodeJS versi $(node -v)"
'';
};
devShells.Python38 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
python38
python38Packages.pip
python38Packages.virtualenv
poetry
];
shellHook = with pkgs; ''
echo "Anda menggunakan Python versi $(python --version)"
'';
};
devShells.Python39 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
python39
python39Packages.pip
python39Packages.virtualenv
poetry
];
shellHook = with pkgs; ''
echo "Anda menggunakan Python versi $(python --version)"
'';
};
devShells.Python310 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
python310
python310Packages.pip
python310Packages.virtualenv
poetry
];
shellHook = with pkgs; ''
echo "Anda menggunakan Python versi $(python --version)"
'';
};
devShells.Python311 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with pkgs; [
python311
python311Packages.pip
python311Packages.virtualenv
poetry
];
shellHook = with pkgs; ''
echo "Anda menggunakan Python versi $(python --version)"
'';
};
devShells.PHP81 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with phps.packages.${sys}; [
env-php81
];
shellHook = with pkgs; ''
echo "Anda menggunakan PHP versi $(php --version)"
echo "Anda menggunakan Composer versi $(composer --version)"
'';
};
devShells.PHP74 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with phps.packages.${sys}; [
env-php74
];
shellHook = with pkgs; ''
echo "Anda menggunakan PHP versi $(php --version)"
echo "Anda menggunakan Composer versi $(composer --version)"
'';
};
devShells.PHP56 = pkgs.mkShell {
nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = with phps.packages.${sys}; [
env-php56
];
shellHook = with pkgs; ''
echo "Anda menggunakan PHP versi $(php --version)"
echo "Anda menggunakan Composer versi $(composer --version)"
'';
};
});
}