From 196a0a5b2d17e46943931405c11df2ebf2382e26 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 10:13:57 +1100 Subject: [PATCH 1/8] buildDartApplication: Add custom outputs to the end of the list --- pkgs/build-support/dart/build-dart-application/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/dart/build-dart-application/default.nix b/pkgs/build-support/dart/build-dart-application/default.nix index f9a49fec3a2d..c99b8bbf325e 100644 --- a/pkgs/build-support/dart/build-dart-application/default.nix +++ b/pkgs/build-support/dart/build-dart-application/default.nix @@ -87,7 +87,7 @@ let dartCompileCommand dartOutputType dartRuntimeCommand dartCompileFlags dartJitFlags; - outputs = args.outputs or [ ] ++ [ "out" "pubcache" ]; + outputs = [ "out" "pubcache" ] ++ args.outputs or [ ]; dartEntryPoints = if (dartEntryPoints != null) From b43ee05f4e99bfe8b834d3c37508bbf00f5df539 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 10:15:35 +1100 Subject: [PATCH 2/8] dartHooks.dartInstallHook: Allow disabling cache installation independently --- .../hooks/dart-install-hook.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh index 888e12a07d83..fbaee6bc1d7a 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh +++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh @@ -19,15 +19,25 @@ dartInstallHook() { fi done < <(_getDartEntryPoints) - # Install the package_config.json file. - mkdir -p "$pubcache" - cp .dart_tool/package_config.json "$pubcache/package_config.json" - runHook postInstall echo "Finished dartInstallHook" } +dartInstallCacheHook() { + echo "Executing dartInstallCacheHook" + + # Install the package_config.json file. + mkdir -p "$pubcache" + cp .dart_tool/package_config.json "$pubcache/package_config.json" + + echo "Finished dartInstallCacheHook" +} + if [ -z "${dontDartInstall-}" ] && [ -z "${installPhase-}" ]; then installPhase=dartInstallHook fi + +if [ -z "${dontDartInstallCache-}" ]; then + postInstallHooks+=(dartInstallCacheHook) +fi \ No newline at end of file From f51a0b053d1df26996d6cd3686570ce9f6b45188 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 10:16:55 +1100 Subject: [PATCH 3/8] flutter.buildFlutterApplication: Allow building for the Web --- doc/languages-frameworks/dart.section.md | 3 + pkgs/build-support/flutter/default.nix | 268 ++++++++++-------- .../development/compilers/flutter/default.nix | 7 +- 3 files changed, 151 insertions(+), 127 deletions(-) diff --git a/doc/languages-frameworks/dart.section.md b/doc/languages-frameworks/dart.section.md index fca87fa70e4e..9de9a1304c6e 100644 --- a/doc/languages-frameworks/dart.section.md +++ b/doc/languages-frameworks/dart.section.md @@ -103,6 +103,9 @@ flutter.buildFlutterApplication { pname = "firmware-updater"; version = "unstable-2023-04-30"; + # To build for the Web, use the flutterHostPlatform argument. + # flutterHostPlatform = "web"; + src = fetchFromGitHub { owner = "canonical"; repo = "firmware-updater"; diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index 4d00e177370e..55a234405c6a 100644 --- a/pkgs/build-support/flutter/default.nix +++ b/pkgs/build-support/flutter/default.nix @@ -17,134 +17,160 @@ { pubGetScript ? "flutter pub get" , flutterBuildFlags ? [ ] +, flutterHostPlatform ? "linux" , extraWrapProgramArgs ? "" , ... }@args: -(buildDartApplication.override { - dart = flutter; -}) (args // { - sdkSetupScript = '' - # Pub needs SSL certificates. Dart normally looks in a hardcoded path. - # https://github.com/dart-lang/sdk/blob/3.1.0/runtime/bin/security_context_linux.cc#L48 - # - # Dart does not respect SSL_CERT_FILE... - # https://github.com/dart-lang/sdk/issues/48506 - # ...and Flutter does not support --root-certs-file, so the path cannot be manually set. - # https://github.com/flutter/flutter/issues/56607 - # https://github.com/flutter/flutter/issues/113594 - # - # libredirect is of no use either, as Flutter does not pass any - # environment variables (including LD_PRELOAD) to the Pub process. - # - # Instead, Flutter is patched to allow the path to the Dart binary used for - # Pub commands to be overriden. - export NIX_FLUTTER_PUB_DART="${runCommand "dart-with-certs" { nativeBuildInputs = [ makeWrapper ]; } '' - mkdir -p "$out/bin" - makeWrapper ${flutter.dart}/bin/dart "$out/bin/dart" \ - --add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt" - ''}/bin/dart" +let + hostPlatforms = rec { + universal = args // { + sdkSetupScript = '' + # Pub needs SSL certificates. Dart normally looks in a hardcoded path. + # https://github.com/dart-lang/sdk/blob/3.1.0/runtime/bin/security_context_linux.cc#L48 + # + # Dart does not respect SSL_CERT_FILE... + # https://github.com/dart-lang/sdk/issues/48506 + # ...and Flutter does not support --root-certs-file, so the path cannot be manually set. + # https://github.com/flutter/flutter/issues/56607 + # https://github.com/flutter/flutter/issues/113594 + # + # libredirect is of no use either, as Flutter does not pass any + # environment variables (including LD_PRELOAD) to the Pub process. + # + # Instead, Flutter is patched to allow the path to the Dart binary used for + # Pub commands to be overriden. + export NIX_FLUTTER_PUB_DART="${runCommand "dart-with-certs" { nativeBuildInputs = [ makeWrapper ]; } '' + mkdir -p "$out/bin" + makeWrapper ${flutter.dart}/bin/dart "$out/bin/dart" \ + --add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt" + ''}/bin/dart" - export HOME="$NIX_BUILD_TOP" - flutter config --no-analytics &>/dev/null # mute first-run - flutter config --enable-linux-desktop >/dev/null - ''; + export HOME="$NIX_BUILD_TOP" + flutter config --no-analytics &>/dev/null # mute first-run + flutter config --enable-linux-desktop >/dev/null + ''; - inherit pubGetScript; + inherit pubGetScript; - sdkSourceBuilders = { - # https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/sdk/flutter.dart#L81 - "flutter" = name: runCommand "flutter-sdk-${name}" { passthru.packageRoot = "."; } '' - for path in '${flutter}/packages/${name}' '${flutter}/bin/cache/pkg/${name}'; do - if [ -d "$path" ]; then - ln -s "$path" "$out" - break + sdkSourceBuilders = { + # https://github.com/dart-lang/pub/blob/68dc2f547d0a264955c1fa551fa0a0e158046494/lib/src/sdk/flutter.dart#L81 + "flutter" = name: runCommand "flutter-sdk-${name}" { passthru.packageRoot = "."; } '' + for path in '${flutter}/packages/${name}' '${flutter}/bin/cache/pkg/${name}'; do + if [ -d "$path" ]; then + ln -s "$path" "$out" + break + fi + done + + if [ ! -e "$out" ]; then + echo 1>&2 'The Flutter SDK does not contain the requested package: ${name}!' + exit 1 + fi + ''; + }; + + extraPackageConfigSetup = '' + # https://github.com/flutter/flutter/blob/3.13.8/packages/flutter_tools/lib/src/dart/pub.dart#L755 + if [ "$('${yq}/bin/yq' '.flutter.generate // false' pubspec.yaml)" = "true" ]; then + '${jq}/bin/jq' '.packages |= . + [{ + name: "flutter_gen", + rootUri: "flutter_gen", + languageVersion: "2.12", + }]' "$out" | '${moreutils}/bin/sponge' "$out" fi - done + ''; + }; - if [ ! -e "$out" ]; then - echo 1>&2 'The Flutter SDK does not contain the requested package: ${name}!' - exit 1 - fi - ''; + linux = universal // { + outputs = universal.outputs or [ ] ++ [ "debug" ]; + + nativeBuildInputs = (universal.nativeBuildInputs or [ ]) ++ [ + wrapGAppsHook + + # Flutter requires pkg-config for Linux desktop support, and many plugins + # attempt to use it. + # + # It is available to the `flutter` tool through its wrapper, but it must be + # added here as well so the setup hook adds plugin dependencies to the + # pkg-config search paths. + pkg-config + ]; + + buildInputs = (universal.buildInputs or [ ]) ++ [ glib ]; + + dontDartBuild = true; + buildPhase = universal.buildPhase or '' + runHook preBuild + + mkdir -p build/flutter_assets/fonts + + flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") flutterBuildFlags)} + + runHook postBuild + ''; + + dontDartInstall = true; + installPhase = universal.installPhase or '' + runHook preInstall + + built=build/linux/*/release/bundle + + mkdir -p $out/bin + mv $built $out/app + + for f in $(find $out/app -iname "*.desktop" -type f); do + install -D $f $out/share/applications/$(basename $f) + done + + for f in $(find $out/app -maxdepth 1 -type f); do + ln -s $f $out/bin/$(basename $f) + done + + # make *.so executable + find $out/app -iname "*.so" -type f -exec chmod +x {} + + + # remove stuff like /build/source/packages/ubuntu_desktop_installer/linux/flutter/ephemeral + for f in $(find $out/app -executable -type f); do + if patchelf --print-rpath "$f" | grep /build; then # this ignores static libs (e,g. libapp.so) also + echo "strip RPath of $f" + newrp=$(patchelf --print-rpath $f | sed -r "s|/build.*ephemeral:||g" | sed -r "s|/build.*profile:||g") + patchelf --set-rpath "$newrp" "$f" + fi + done + + runHook postInstall + ''; + + dontWrapGApps = true; + extraWrapProgramArgs = '' + ''${gappsWrapperArgs[@]} \ + ${extraWrapProgramArgs} + ''; + }; + + web = universal // { + dontDartBuild = true; + buildPhase = universal.buildPhase or '' + runHook preBuild + + mkdir -p build/flutter_assets/fonts + + flutter build web -v --release ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") flutterBuildFlags)} + + runHook postBuild + ''; + + dontDartInstall = true; + installPhase = universal.installPhase or '' + runHook preInstall + + cp -r build/web "$out" + + runHook postInstall + ''; + }; }; - - extraPackageConfigSetup = '' - # https://github.com/flutter/flutter/blob/3.13.8/packages/flutter_tools/lib/src/dart/pub.dart#L755 - if [ "$('${yq}/bin/yq' '.flutter.generate // false' pubspec.yaml)" = "true" ]; then - '${jq}/bin/jq' '.packages |= . + [{ - name: "flutter_gen", - rootUri: "flutter_gen", - languageVersion: "2.12", - }]' "$out" | '${moreutils}/bin/sponge' "$out" - fi - ''; - - nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ - wrapGAppsHook - - # Flutter requires pkg-config for Linux desktop support, and many plugins - # attempt to use it. - # - # It is available to the `flutter` tool through its wrapper, but it must be - # added here as well so the setup hook adds plugin dependencies to the - # pkg-config search paths. - pkg-config - ]; - - buildInputs = (args.buildInputs or [ ]) ++ [ glib ]; - - dontDartBuild = true; - buildPhase = args.buildPhase or '' - runHook preBuild - - mkdir -p build/flutter_assets/fonts - - flutter build linux -v --release --split-debug-info="$debug" ${builtins.concatStringsSep " " (map (flag: "\"${flag}\"") flutterBuildFlags)} - - runHook postBuild - ''; - - dontDartInstall = true; - installPhase = args.installPhase or '' - runHook preInstall - - built=build/linux/*/release/bundle - - mkdir -p $out/bin - mv $built $out/app - - for f in $(find $out/app -iname "*.desktop" -type f); do - install -D $f $out/share/applications/$(basename $f) - done - - for f in $(find $out/app -maxdepth 1 -type f); do - ln -s $f $out/bin/$(basename $f) - done - - # make *.so executable - find $out/app -iname "*.so" -type f -exec chmod +x {} + - - # remove stuff like /build/source/packages/ubuntu_desktop_installer/linux/flutter/ephemeral - for f in $(find $out/app -executable -type f); do - if patchelf --print-rpath "$f" | grep /build; then # this ignores static libs (e,g. libapp.so) also - echo "strip RPath of $f" - newrp=$(patchelf --print-rpath $f | sed -r "s|/build.*ephemeral:||g" | sed -r "s|/build.*profile:||g") - patchelf --set-rpath "$newrp" "$f" - fi - done - - # Install the package_config.json file. - # This is normally done by dartInstallHook, but we disable it. - mkdir -p "$pubcache" - cp .dart_tool/package_config.json "$pubcache/package_config.json" - - runHook postInstall - ''; - - dontWrapGApps = true; - extraWrapProgramArgs = '' - ''${gappsWrapperArgs[@]} \ - ${extraWrapProgramArgs} - ''; -}) +in +(buildDartApplication.override { dart = flutter.override { supportedTargetFlutterPlatforms = [ "universal" flutterHostPlatform ]; }; }) + hostPlatforms.${flutterHostPlatform} or "Unsupported Flutter host platform: ${flutterHostPlatform}" diff --git a/pkgs/development/compilers/flutter/default.nix b/pkgs/development/compilers/flutter/default.nix index 29d5d415b8a0..6d2d90466033 100644 --- a/pkgs/development/compilers/flutter/default.nix +++ b/pkgs/development/compilers/flutter/default.nix @@ -51,12 +51,7 @@ let (mkCustomFlutter args).overrideAttrs (prev: next: { passthru = next.passthru // rec { inherit wrapFlutter mkCustomFlutter mkFlutter; - buildFlutterApplication = callPackage ../../../build-support/flutter { - # Package a minimal version of Flutter that only uses Linux desktop release artifacts. - flutter = (wrapFlutter (mkCustomFlutter args)).override { - supportedTargetFlutterPlatforms = [ "universal" "linux" ]; - }; - }; + buildFlutterApplication = callPackage ../../../build-support/flutter { flutter = wrapFlutter (mkCustomFlutter args); }; }; }); From 62029c27a11a5be1953345a55587c42a3ddacd1b Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 11:38:10 +1100 Subject: [PATCH 4/8] fluffychat-web: init at 1.14.1 --- .../instant-messengers/fluffychat/default.nix | 59 +++++++++++++------ pkgs/top-level/all-packages.nix | 2 + 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/pkgs/applications/networking/instant-messengers/fluffychat/default.nix b/pkgs/applications/networking/instant-messengers/fluffychat/default.nix index bdd41c4cfa64..7375ac078142 100644 --- a/pkgs/applications/networking/instant-messengers/fluffychat/default.nix +++ b/pkgs/applications/networking/instant-messengers/fluffychat/default.nix @@ -1,4 +1,5 @@ { lib +, fetchzip , fetchFromGitHub , imagemagick , mesa @@ -7,13 +8,15 @@ , pulseaudio , makeDesktopItem , gnome + +, flutterHostPlatform ? "linux" }: let libwebrtcRpath = lib.makeLibraryPath [ mesa libdrm ]; in -flutter313.buildFlutterApplication rec { - pname = "fluffychat"; +flutter313.buildFlutterApplication (rec { + pname = "fluffychat-${flutterHostPlatform}"; version = "1.14.1"; src = fetchFromGitHub { @@ -30,6 +33,25 @@ flutter313.buildFlutterApplication rec { wakelock_windows = "sha256-Dfwe3dSScD/6kvkP67notcbb+EgTQ3kEYcH7wpra2dI="; }; + inherit flutterHostPlatform; + + meta = with lib; { + description = "Chat with your friends (matrix client)"; + homepage = "https://fluffychat.im/"; + license = licenses.agpl3Plus; + maintainers = with maintainers; [ mkg20001 gilice ]; + platforms = [ "x86_64-linux" "aarch64-linux" ]; + sourceProvenance = [ sourceTypes.fromSource ]; + }; +} // lib.optionalAttrs (flutterHostPlatform == "linux") { + nativeBuildInputs = [ imagemagick ]; + + runtimeDependencies = [ pulseaudio ]; + + extraWrapProgramArgs = "--prefix PATH : ${gnome.zenity}/bin"; + + env.NIX_LDFLAGS = "-rpath-link ${libwebrtcRpath}"; + desktopItem = makeDesktopItem { name = "Fluffychat"; exec = "@out@/bin/fluffychat"; @@ -39,9 +61,6 @@ flutter313.buildFlutterApplication rec { categories = [ "Chat" "Network" "InstantMessaging" ]; }; - nativeBuildInputs = [ imagemagick ]; - runtimeDependencies = [ pulseaudio ]; - extraWrapProgramArgs = "--prefix PATH : ${gnome.zenity}/bin"; postInstall = '' FAV=$out/app/data/flutter_assets/assets/favicon.png ICO=$out/share/icons @@ -59,15 +78,21 @@ flutter313.buildFlutterApplication rec { patchelf --add-rpath ${libwebrtcRpath} $out/app/lib/libwebrtc.so ''; - - env.NIX_LDFLAGS = "-rpath-link ${libwebrtcRpath}"; - - meta = with lib; { - description = "Chat with your friends (matrix client)"; - homepage = "https://fluffychat.im/"; - license = licenses.agpl3Plus; - maintainers = with maintainers; [ mkg20001 gilice ]; - platforms = [ "x86_64-linux" "aarch64-linux" ]; - sourceProvenance = [ sourceTypes.fromSource ]; - }; -} +} // lib.optionalAttrs (flutterHostPlatform == "web") { + prePatch = + # https://github.com/krille-chan/fluffychat/blob/v1.17.1/scripts/prepare-web.sh + let + # Use Olm 1.3.2, the oldest version, for FluffyChat 1.14.1 which depends on olm_flutter 1.2.0. + # In the future, this should be changed to use self.pubspecLock.dependencyVersions.flutter_olm as the script does. + olmVersion = "1.3.2"; + olmJs = fetchzip { + url = "https://github.com/famedly/olm/releases/download/v${olmVersion}/olm.zip"; + stripRoot = false; + hash = "sha256-Vl3Cp2OaYzM5CPOOtTHtUb1W48VXePzOV6FeiIzyD1Y="; + }; + in + '' + rm -r assets/js/package + cp -r '${olmJs}/javascript' assets/js/package + ''; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4a86175d934a..dc6396632d63 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3850,6 +3850,8 @@ with pkgs; fluffychat = callPackage ../applications/networking/instant-messengers/fluffychat { }; + fluffychat-web = fluffychat.override { flutterHostPlatform = "web"; }; + fxlinuxprintutil = callPackage ../tools/misc/fxlinuxprintutil { }; gbl = callPackage ../tools/archivers/gbl { From 046da09ddd8bc3a332c49d0a52ab736fd7e52ab6 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 11:59:38 +1100 Subject: [PATCH 5/8] flutter.buildFlutterApplication: Properly throw unsupported host platform error --- pkgs/build-support/flutter/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index 55a234405c6a..ff02d907bd5d 100644 --- a/pkgs/build-support/flutter/default.nix +++ b/pkgs/build-support/flutter/default.nix @@ -173,4 +173,4 @@ let }; in (buildDartApplication.override { dart = flutter.override { supportedTargetFlutterPlatforms = [ "universal" flutterHostPlatform ]; }; }) - hostPlatforms.${flutterHostPlatform} or "Unsupported Flutter host platform: ${flutterHostPlatform}" + hostPlatforms.${flutterHostPlatform} or (throw "Unsupported Flutter host platform: ${flutterHostPlatform}") From e3b2edadef90b55a6c4c9dcb486e5cc16bca0b87 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 12:17:43 +1100 Subject: [PATCH 6/8] dartHooks.dartInstallHook: Add trailing newline --- .../dart/build-dart-application/hooks/dart-install-hook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh b/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh index fbaee6bc1d7a..349a0dfdef0e 100644 --- a/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh +++ b/pkgs/build-support/dart/build-dart-application/hooks/dart-install-hook.sh @@ -40,4 +40,4 @@ fi if [ -z "${dontDartInstallCache-}" ]; then postInstallHooks+=(dartInstallCacheHook) -fi \ No newline at end of file +fi From 3b33435d02dbe0f41829e97d8880c9f3d4bc60b2 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 14:20:03 +1100 Subject: [PATCH 7/8] flutter.buildFlutterApplication: Add multiShell attribute --- doc/languages-frameworks/dart.section.md | 15 ++++++++++++++- pkgs/build-support/flutter/default.nix | 11 +++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/languages-frameworks/dart.section.md b/doc/languages-frameworks/dart.section.md index 9de9a1304c6e..c12076b8c6cf 100644 --- a/doc/languages-frameworks/dart.section.md +++ b/doc/languages-frameworks/dart.section.md @@ -80,6 +80,8 @@ Do _not_ use `dart run `, as this will attempt to download depende ### Usage with nix-shell {#ssec-dart-applications-nix-shell} +#### Using dependencies from the Nix store {#ssec-dart-applications-nix-shell-deps} + As `buildDartApplication` provides dependencies instead of `pub get`, Dart needs to be explicitly told where to find them. Run the following commands in the source directory to configure Dart appropriately. @@ -120,4 +122,15 @@ flutter.buildFlutterApplication { ### Usage with nix-shell {#ssec-dart-flutter-nix-shell} -See the [Dart documentation](#ssec-dart-applications-nix-shell) for nix-shell instructions. +Flutter-specific `nix-shell` usage notes are included here. See the [Dart documentation](#ssec-dart-applications-nix-shell) for general `nix-shell` instructions. + +#### Entering the shell {#ssec-dart-flutter-nix-shell-enter} + +By default, dependencies for only the `flutterHostPlatform` are available in the +build environment. This is useful for keeping closures small, but be problematic +during development. It's common, for example, to build Web apps for Linux during +development to take advantage of native features such as stateful hot reload. + +To enter a shell with all the usual target platforms available, use the `multiShell` attribute. + +e.g. `nix-shell '' -A fluffychat-web.multiShell`. diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index ff02d907bd5d..dd49ca4fe229 100644 --- a/pkgs/build-support/flutter/default.nix +++ b/pkgs/build-support/flutter/default.nix @@ -23,7 +23,7 @@ }@args: let - hostPlatforms = rec { + builderArgs = rec { universal = args // { sdkSetupScript = '' # Pub needs SSL certificates. Dart normally looks in a hardcoded path. @@ -170,7 +170,10 @@ let runHook postInstall ''; }; - }; + }.${flutterHostPlatform} or (throw "Unsupported Flutter host platform: ${flutterHostPlatform}"); + + minimalFlutter = flutter.override { supportedTargetFlutterPlatforms = [ "universal" flutterHostPlatform ]; }; + + buildAppWith = flutter: buildDartApplication.override { dart = flutter; }; in -(buildDartApplication.override { dart = flutter.override { supportedTargetFlutterPlatforms = [ "universal" flutterHostPlatform ]; }; }) - hostPlatforms.${flutterHostPlatform} or (throw "Unsupported Flutter host platform: ${flutterHostPlatform}") +buildAppWith minimalFlutter (builderArgs // { passthru = builderArgs.passthru or { } // { multiShell = buildAppWith flutter builderArgs; }; }) From 64f9fa0d2c0ace8013a56cc15a86fea16c64f57b Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Fri, 19 Jan 2024 11:07:33 +1100 Subject: [PATCH 8/8] buildFlutterApplication: Change flutterHostPlatform to targetFlutterPlatform --- doc/languages-frameworks/dart.section.md | 6 +++--- .../instant-messengers/fluffychat/default.nix | 10 +++++----- pkgs/build-support/flutter/default.nix | 6 +++--- pkgs/top-level/all-packages.nix | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/languages-frameworks/dart.section.md b/doc/languages-frameworks/dart.section.md index c12076b8c6cf..58ee2d5050ac 100644 --- a/doc/languages-frameworks/dart.section.md +++ b/doc/languages-frameworks/dart.section.md @@ -105,8 +105,8 @@ flutter.buildFlutterApplication { pname = "firmware-updater"; version = "unstable-2023-04-30"; - # To build for the Web, use the flutterHostPlatform argument. - # flutterHostPlatform = "web"; + # To build for the Web, use the targetFlutterPlatform argument. + # targetFlutterPlatform = "web"; src = fetchFromGitHub { owner = "canonical"; @@ -126,7 +126,7 @@ Flutter-specific `nix-shell` usage notes are included here. See the [Dart docume #### Entering the shell {#ssec-dart-flutter-nix-shell-enter} -By default, dependencies for only the `flutterHostPlatform` are available in the +By default, dependencies for only the `targetFlutterPlatform` are available in the build environment. This is useful for keeping closures small, but be problematic during development. It's common, for example, to build Web apps for Linux during development to take advantage of native features such as stateful hot reload. diff --git a/pkgs/applications/networking/instant-messengers/fluffychat/default.nix b/pkgs/applications/networking/instant-messengers/fluffychat/default.nix index 7375ac078142..cfe0bb8e8ab2 100644 --- a/pkgs/applications/networking/instant-messengers/fluffychat/default.nix +++ b/pkgs/applications/networking/instant-messengers/fluffychat/default.nix @@ -9,14 +9,14 @@ , makeDesktopItem , gnome -, flutterHostPlatform ? "linux" +, targetFlutterPlatform ? "linux" }: let libwebrtcRpath = lib.makeLibraryPath [ mesa libdrm ]; in flutter313.buildFlutterApplication (rec { - pname = "fluffychat-${flutterHostPlatform}"; + pname = "fluffychat-${targetFlutterPlatform}"; version = "1.14.1"; src = fetchFromGitHub { @@ -33,7 +33,7 @@ flutter313.buildFlutterApplication (rec { wakelock_windows = "sha256-Dfwe3dSScD/6kvkP67notcbb+EgTQ3kEYcH7wpra2dI="; }; - inherit flutterHostPlatform; + inherit targetFlutterPlatform; meta = with lib; { description = "Chat with your friends (matrix client)"; @@ -43,7 +43,7 @@ flutter313.buildFlutterApplication (rec { platforms = [ "x86_64-linux" "aarch64-linux" ]; sourceProvenance = [ sourceTypes.fromSource ]; }; -} // lib.optionalAttrs (flutterHostPlatform == "linux") { +} // lib.optionalAttrs (targetFlutterPlatform == "linux") { nativeBuildInputs = [ imagemagick ]; runtimeDependencies = [ pulseaudio ]; @@ -78,7 +78,7 @@ flutter313.buildFlutterApplication (rec { patchelf --add-rpath ${libwebrtcRpath} $out/app/lib/libwebrtc.so ''; -} // lib.optionalAttrs (flutterHostPlatform == "web") { +} // lib.optionalAttrs (targetFlutterPlatform == "web") { prePatch = # https://github.com/krille-chan/fluffychat/blob/v1.17.1/scripts/prepare-web.sh let diff --git a/pkgs/build-support/flutter/default.nix b/pkgs/build-support/flutter/default.nix index dd49ca4fe229..5d7cd7d984c1 100644 --- a/pkgs/build-support/flutter/default.nix +++ b/pkgs/build-support/flutter/default.nix @@ -17,7 +17,7 @@ { pubGetScript ? "flutter pub get" , flutterBuildFlags ? [ ] -, flutterHostPlatform ? "linux" +, targetFlutterPlatform ? "linux" , extraWrapProgramArgs ? "" , ... }@args: @@ -170,9 +170,9 @@ let runHook postInstall ''; }; - }.${flutterHostPlatform} or (throw "Unsupported Flutter host platform: ${flutterHostPlatform}"); + }.${targetFlutterPlatform} or (throw "Unsupported Flutter host platform: ${targetFlutterPlatform}"); - minimalFlutter = flutter.override { supportedTargetFlutterPlatforms = [ "universal" flutterHostPlatform ]; }; + minimalFlutter = flutter.override { supportedTargetFlutterPlatforms = [ "universal" targetFlutterPlatform ]; }; buildAppWith = flutter: buildDartApplication.override { dart = flutter; }; in diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dc6396632d63..eda026645d13 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3850,7 +3850,7 @@ with pkgs; fluffychat = callPackage ../applications/networking/instant-messengers/fluffychat { }; - fluffychat-web = fluffychat.override { flutterHostPlatform = "web"; }; + fluffychat-web = fluffychat.override { targetFlutterPlatform = "web"; }; fxlinuxprintutil = callPackage ../tools/misc/fxlinuxprintutil { };