From f51a0b053d1df26996d6cd3686570ce9f6b45188 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 10:16:55 +1100 Subject: flutter.buildFlutterApplication: Allow building for the Web --- doc/languages-frameworks/dart.section.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'doc') 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"; -- cgit 1.4.1 From 3b33435d02dbe0f41829e97d8880c9f3d4bc60b2 Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Thu, 18 Jan 2024 14:20:03 +1100 Subject: 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(-) (limited to 'doc') 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; }; }) -- cgit 1.4.1 From 64f9fa0d2c0ace8013a56cc15a86fea16c64f57b Mon Sep 17 00:00:00 2001 From: hacker1024 Date: Fri, 19 Jan 2024 11:07:33 +1100 Subject: buildFlutterApplication: Change flutterHostPlatform to targetFlutterPlatform --- doc/languages-frameworks/dart.section.md | 6 +++--- .../networking/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(-) (limited to 'doc') 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 { }; -- cgit 1.4.1