-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
flutter: Packaging the Flutter engine #201574
Comments
Turns out it's just the example What I have so far{ stdenv
, lib
, fetchgit
, fetchFromGitHub
, writeText
, writeShellScriptBin
, python310
, git
, openssh
}:
let
depot_tools = fetchgit {
url = "https://chromium.googlesource.com/chromium/tools/depot_tools.git";
rev = "25cf78395cd77e11b13c1bd26124e0a586c19166";
sha256 = "sha256-Qn0rqX2+wYpbyfwYzeaFsbsLvuGV6+S9GWrH3EqaHmU=";
};
gclient = writeShellScriptBin "gclient" ''
${python310.withPackages (py: with py; [ google-auth-httplib2 ])}/bin/python ${depot_tools}/gclient.py "$@"
'';
ssh = writeShellScriptBin "ssh" ''
if [ ! -f id_rsa ]; then
${openssh}/bin/ssh-keygen -t rsa -N "" -f id_rsa > /dev/null
fi
${openssh}/bin/ssh -i id_rsa.pub -o StrictHostKeyChecking=no "$@"
'';
src = stdenv.mkDerivation rec {
pname = "flutter-engine-sources";
version = "857bd6b74c5eb56151bfafe91e7fa6a82b6fee25";
nativeBuildInputs = [ gclient git ssh ];
unpackPhase = ''
runHook preUnpack
mkdir engine && cd engine
ln -s ${
writeText ".gclient" ''
solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "[email protected]:flutter/engine.git@${version}",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]
''
} .gclient
gclient sync
runHook postUnpack
'';
outputHashAlgo = "sha256";
outputHash = lib.fakeSha256;
};
in
stdenv.mkDerivation {
pname = "flutter-engine";
inherit (src) version;
inherit src;
} |
what exactly is the benefit of a source build? misleading, we dont need push access we just need a bit cleaned up /*
https://github.com/NixOS/nixpkgs/issues/201574
*/
{ stdenv
, lib
, fetchgit
, fetchFromGitHub
, writeShellScriptBin
, python3
, git
, cacert
, ninja
}:
let
depot_tools = fetchgit {
url = "https://chromium.googlesource.com/chromium/tools/depot_tools";
rev = "30e3ce8b1c670be00c4957fe773ffb8ff986ed8f";
sha256 = "sha256-R9CX/xzvLiOVQmAsviTFUFv6DiStxa0b6O0zHNaH6SY=";
};
gclient = writeShellScriptBin "gclient" ''
${python3.withPackages (py: with py; [ google-auth-httplib2 ])}/bin/python ${depot_tools}/gclient.py "$@"
'';
in
stdenv.mkDerivation rec {
pname = "flutter-engine";
version = "981fe92ab998d655abded58f1f0ef2a8daeadd02";
# https://github.com/flutter/engine
src = fetchFromGitHub {
owner = "flutter";
repo = "engine";
rev = version;
sha256 = "sha256-9uY7Q8ZR51vB7vsjEPGAWyvhOKRfdj5B8o0KwypwdTY=";
};
# only fetching the sources takes 1 hour ...
deps = stdenv.mkDerivation {
inherit src;
name = "${pname}-${version}-deps";
nativeBuildInputs = [
gclient
git
cacert # fix: error:16000069:STORE routines::unregistered scheme
];
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = ""; # TODO
# TODO copy less? copy only some folders, then merge with source
buildPhase = ''
(
set -x
gclient config https://github.com/flutter/engine
gclient sync --revision engine@${version} --shallow --verbose
cp -r . $out
)
'';
};
postUnpack = ''
(
cd $sourceRoot
echo TODO merge with source. copy or symlink ${deps}
exit 1
)
'';
nativeBuildInputs = [
ninja
];
/*
TODO
https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-macos-or-linux
this will take forever ...
*/
buildPhase = ''
./flutter/tools/gn --unoptimized # to prepare your build files.
ninja -C out/host_debug_unopt # to build a desktop unoptimized binary.
'';
} this currently throws
|
I came here as I'm currently looking to package google/pigweed using nix (via a search for cipd). I think cipd can be built from source relatively easily and could potentially be packaged in nix itself. e.g.
Will fetch and build cipd. |
building cipd with buildGoModule is like 20 lines of nix code https://ryantm.github.io/nixpkgs/languages-frameworks/go/ |
I didn't realize that cipd was a simple Go program, but I did notice that it was statically linked. I've been retrieving it by parsing the depot_tools version metadata like so: let
depot_tools = fetchgit {
url = "https://chromium.googlesource.com/chromium/tools/depot_tools.git";
rev = "25cf78395cd77e11b13c1bd26124e0a586c19166";
sha256 = "sha256-Qn0rqX2+wYpbyfwYzeaFsbsLvuGV6+S9GWrH3EqaHmU=";
};
cipd =
let
cipdVersion = builtins.readFile "${depot_tools}/cipd_client_version";
cipdHashes = builtins.listToAttrs (
map
(line:
let
segments = builtins.split " +" line;
in
{ name = builtins.head segments; value = lib.last segments; })
(lib.filter (line: !(lib.hasPrefix "#" line || line == "")) (lib.splitString "\n" (builtins.readFile "${depot_tools}/cipd_client_version.digests")))
);
cipdPlatform =
if stdenv.isDarwin then
(if stdenv.isAarch64 then "mac-arm64" else "mac-amd64")
else
(if stdenv.isAarch64 then "linux-arm64" else "linux-amd64");
cipdBinary = fetchurl {
name = "cipd-${cipdPlatform}-${cipdVersion}-unwrapped";
url = "https://chrome-infra-packages.appspot.com/client?platform=${cipdPlatform}&version=${cipdVersion}";
sha256 = cipdHashes.${cipdPlatform};
};
in
runCommandLocal "cipd-${cipdPlatform}-${cipdVersion}" { } "mkdir -p $out/bin; install -m 755 ${cipdBinary} $out/bin/cipd";
gclient = writeShellScriptBin "gclient" ''
${python310.withPackages (py: with py; [ google-auth-httplib2 ])}/bin/python ${depot_tools}/gclient.py "$@"
'';
in
# ... |
The Flutter SDK fetches many executable components from Google's servers at runtime. These all have FHS dependencies. By building the Flutter SDK manually, we can make sure everything is linked to Nix store libraries and is available offline. Other alternatives would be to do one of the following:
The former seems tricky to implement, and the latter requires somehow curating a list of all external components. I don't think these are enumerated in any one place. A FHS user environment is sub-optimal, because parts of the Flutter engine are copied into apps built with Flutter. This would mean that all packaged Flutter apps would have to be patched with |
thats bad, but does not justify a source build.
gclient spends ONE HOUR just to fetch all the sources ... i collected some links in https://nixos.wiki/wiki/Gn im not saying that source build is a bad idea |
I've been working on this and was able to build the embedded engine on host but not inside of Nix. Yesterday, I managed to pull all dependencies and "lock" them in with Nix. Currently working on trying to build the actual engine in Nix. |
I managed to successfully compile the embedded engine completely in Nix. I've got issues with reproduction because of |
IIRC there is a way to make .git directories reproducible, I'll see if I can find what I've done before soon. |
|
Yes, and that's why I am working on being able to build without
|
I have resolved all errors but now I am stuck with this error:
|
Project description
At the moment, the Flutter package uses the prebuilt engine from Google, downloaded by the SDK.
This is not ideal, as prebuilt engine artifacts require patching for Nix(OS) compatibility.
It'd be great if we could build the Flutter engine from source.
Useful references:
Metadata
(cc: @mkg20001 @dotlambda)
The text was updated successfully, but these errors were encountered: