flutter-flake/flake.nix

75 lines
2.3 KiB
Nix
Raw Normal View History

2022-05-09 18:31:18 +02:00
{
outputs = { self }: {
templates.android = {
path = ./android;
description =
"A flake for getting a dev shell with Android SDK & Flutter using flutter-flake";
};
lib = let
optional = q: x: optList q [ x ];
optList = q: xs: if q then xs else [ ];
optStr = q: str:
if q then ''
${str}
'' else
"";
guard = q: k: if q then k else null;
in {
get-devShell = { nixpkgs, pkgs ? import nixpkgs {
inherit system;
config = nixpkgsConfig;
}, system, nixpkgsConfig ? { }, enable-android ? false
, enable-linuxDesktop ? false, enable-web ? true
, enable-windowsDesktop ? false, enable-macDesktop ? false
, enable-ios ? false
, chromeExecutable ? pkgs.ungoogled-chromium + "/bin/chromium" }:
let
androidComposition = pkgs.androidenv.composeAndroidPackages {
platformToolsVersion = "31.0.3";
toolsVersion = "26.1.1";
};
flutter-deps = optional enable-android androidComposition.androidsdk
2022-05-09 19:34:07 +02:00
++ optList enable-linuxDesktop (with pkgs; [
clang
cmake
ninja
pkg-config
gtk3.dev
pcre
epoxy
glib
2022-05-09 20:45:16 +02:00
xorg.libX11
2022-05-09 19:34:07 +02:00
]);
2022-05-09 18:31:18 +02:00
flutter-fhs = pkgs.buildFHSUserEnv {
name = "flutter";
targetPkgs = (_: flutter-deps);
runScript = pkgs.flutter + "/bin/flutter";
};
in if enable-ios || enable-macDesktop || enable-windowsDesktop then
builtins.throw ''
iOS, macOS and Windows are not supported currently. Feel free to contribute.
''
else
2022-05-09 18:56:04 +02:00
assert !enable-ios;
assert !enable-macDesktop;
assert !enable-windowsDesktop;
2022-05-09 18:31:18 +02:00
pkgs.mkShell {
packages = with pkgs; [ flutter-fhs ] ++ flutter-deps;
shellHook = optStr enable-android ''
2022-05-09 18:56:04 +02:00
flutter config --enable-android
2022-05-09 18:31:18 +02:00
flutter config --android-sdk ${androidComposition.androidsdk}/libexec/android-sdk
2022-05-09 18:56:04 +02:00
'' + optStr enable-linuxDesktop ''
flutter config --enable-linux-desktop
2022-05-09 18:58:34 +02:00
'' + optStr enable-web ''
2022-05-09 18:56:04 +02:00
export CHROME_EXECUTABLE=${chromeExecutable}
2022-05-09 18:31:18 +02:00
'';
};
};
};
}