Skip to content
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

dart: Use Nix instead of Pub #263345

Merged
merged 32 commits into from
Jan 5, 2024
Merged

dart: Use Nix instead of Pub #263345

merged 32 commits into from
Jan 5, 2024

Conversation

hacker1024
Copy link
Member

@hacker1024 hacker1024 commented Oct 25, 2023

Description of changes

This PR removes fetchDartDeps in favour of a new pub2nix library. Instead of using Pub to generate a large fixed-output derivation, the pubspec.lock file is parsed, and a derivation is made for each individual package.

This improves the user experience significantly:

  • Dependency derivations can be shared between applications
  • The vendorHash is no longer needed (though Git dependencies still do need manual hashes)
  • There's no need to work around Pub's difficult Git and package caching behaviour

This PR builds on #262789, so for review, this comparison between the branches is appropriate. This can be changed if we decide against #262789, though - nothing relies on it directly.

All existing Dart and Flutter packages build and run, with the exception of dart-sass-embedded, which was already broken with Dart 3. I've removed it in this PR, as it has been discontinued upstream and merged into the regular dart-sass package.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@NixOS/flutter

@hacker1024
Copy link
Member Author

Result of nixpkgs-review pr 263345 run on aarch64-linux 1

4 packages marked as broken and skipped:
  • rstudio
  • rstudio-server
  • rstudioServerWrapper
  • rstudioWrapper
26 packages built:
  • dart-sass
  • dart-sass.pubcache
  • discourse
  • discourseAllPlugins
  • domine
  • domine.pubcache
  • expidus.file-manager
  • expidus.file-manager.pubcache
  • firmware-updater
  • firmware-updater.pubcache
  • fluffychat
  • fluffychat.pubcache
  • flutter
  • flutter-unwrapped
  • hover
  • protoc-gen-dart
  • protoc-gen-dart.pubcache
  • python310Packages.nbdev
  • python310Packages.nbdev.dist
  • python311Packages.nbdev
  • python311Packages.nbdev.dist
  • quarto
  • quartoMinimal
  • shopware-cli
  • yubioath-flutter
  • yubioath-flutter.pubcache

@hacker1024
Copy link
Member Author

I have added a mechanism to customise Dart package derivations. If any packages require patches, they can now be easily added.

Setup hooks have replaced the old package override mechanism, and can be used to do things like set environment variables and add to the FFI runtime dependency list. We should have probably done this from the beginning, but now it's even easier as the setup hooks can be built into the package derivations themselves.

These changes allow the dependency list JSON file to be removed.

@hacker1024

This comment was marked as outdated.

@hacker1024

This comment was marked as outdated.

@hacker1024
Copy link
Member Author

Result of nixpkgs-review pr 263345 run on x86_64-linux 1

30 packages built:
  • dart-sass
  • dart-sass.pubcache
  • discourse
  • discourseAllPlugins
  • domine
  • domine.pubcache
  • expidus.file-manager
  • expidus.file-manager.pubcache
  • firmware-updater
  • firmware-updater.pubcache
  • fluffychat
  • fluffychat.pubcache
  • flutter
  • flutter-unwrapped
  • hover
  • protoc-gen-dart
  • protoc-gen-dart.pubcache
  • python310Packages.nbdev
  • python310Packages.nbdev.dist
  • python311Packages.nbdev
  • python311Packages.nbdev.dist
  • quarto
  • quartoMinimal
  • rstudio
  • rstudio-server
  • rstudioServerWrapper
  • rstudioWrapper
  • shopware-cli
  • yubioath-flutter
  • yubioath-flutter.pubcache

Copy link
Contributor

@FlafyDev FlafyDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! this solution is way nicer to use than a vendor hash.

comments:

  1. pub2nix still requires git hashes. But currently we have to specify a separate hash for every git dependency. Maybe it'd be better to have a single fixed-output derivation to get all the git dependencies and thus use only a single hash?

  2. Maybe add instructions to convert the pubspec.lock to json? Not sure when Nix would say that, though. And it's quite simple to do anyway.


mkHostedDependencySource = name: details:
let
archive = fetchurl {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use fetchTarBall?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added disclaimer why not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other reason is that the hash in the pubspec.lock is for the archive itself. There's no way to determine the recursive hash of the contents in advance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Is this correct then?

  # The hash in `pubspec.lock` is for the archive itself.
  # If we use `fetchTarball` instead of `fetchurl`, we'll need to input the hash for the files after extraction, which we don't have.
  # Additionally, `fetchTarball` fails with "tarball contains an unexpected number of top-level files".
  # https://discourse.nixos.org/t/fetchtarball-with-multiple-top-level-directories-fails/20556

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

pkgs/build-support/dart/build-dart-application/default.nix Outdated Show resolved Hide resolved
pkgs/build-support/dart/build-dart-application/default.nix Outdated Show resolved Hide resolved
pkgs/build-support/dart/build-dart-application/default.nix Outdated Show resolved Hide resolved
@mkg20001
Copy link
Member

@FlafyDev do you want to rebase this to another branch? I can then force push it to this one.

This still fails to build as it uses an old version of the protobuf package, though.
@FlafyDev
Copy link
Contributor

FlafyDev commented Dec 26, 2023

@mkg20001 I've rebased this PR on this branch
It was a bit tricky so I hope I did it right.

discourse and discourseAllPlugins don't build on master. It's not due to this PR.

This is the nixpkgs review for 32e3ea1:

Result of nixpkgs-review run on x86_64-linux 1

2 packages failed to build:
  • discourse
  • discourseAllPlugins
32 packages built:
  • dart-sass
  • dart-sass.pubcache
  • domine
  • domine.pubcache
  • expidus.file-manager
  • expidus.file-manager.pubcache
  • firmware-updater
  • firmware-updater.pubcache
  • fluffychat
  • fluffychat.pubcache
  • flutter
  • flutter-unwrapped
  • hover
  • intiface-central
  • intiface-central.pubcache
  • localsend
  • localsend.pubcache
  • protoc-gen-dart
  • protoc-gen-dart.pubcache
  • python310Packages.nbdev
  • python310Packages.nbdev.dist
  • python311Packages.nbdev
  • python311Packages.nbdev.dist
  • quarto
  • quartoMinimal
  • rstudio
  • rstudio-server
  • rstudioServerWrapper
  • rstudioWrapper
  • shopware-cli
  • yubioath-flutter
  • yubioath-flutter.pubcache

EDIT: Added a few more commits to that branch based on my suggestions. Shouldn't impact nixpkgs-review's result.

Copy link
Contributor

@FlafyDev FlafyDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub2nix still requires git hashes. But currently we have to specify a separate hash for every git dependency. Maybe it'd be better to have a single fixed-output derivation to get all the git dependencies and thus use only a single hash?

I think this would be a bit complicated to do. Probably better to keep it to a future PR if necessary. Also if we make an update script for buildDartApplication and buildFlutterApplication it wouldn't really matter.

Maybe add instructions to convert the pubspec.lock to json? Not sure when Nix would say that, though. And it's quite simple to do anyway.

I still think this is necessary, but better to keep it to a different PR.

@hacker1024
Copy link
Member Author

I think this would be a bit complicated to do. Probably better to keep it to a future PR if necessary. Also if we make an update script for buildDartApplication and buildFlutterApplication it wouldn't really matter.

I'm not too keen in the idea of reducing granularity for just a little convenience. IIRC, running a build with blank hashes and --keep-all should be enough to get all the hashes in one hit.

This would also require custom fetching logic, as I don't think there's any off-the-shelf solution to make a FOD out of multiple Git repositories.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/3200

@mkg20001
Copy link
Member

mkg20001 commented Jan 5, 2024

Result of nixpkgs-review pr 263345 run on x86_64-linux 1

2 packages failed to build:
  • discourse
  • discourseAllPlugins
32 packages built:
  • dart-sass
  • dart-sass.pubcache
  • domine
  • domine.pubcache
  • expidus.file-manager
  • expidus.file-manager.pubcache
  • firmware-updater
  • firmware-updater.pubcache
  • fluffychat
  • fluffychat.pubcache
  • flutter
  • flutter-unwrapped (flutterPackages.stable)
  • hover
  • intiface-central
  • intiface-central.pubcache
  • localsend
  • localsend.pubcache
  • protoc-gen-dart
  • protoc-gen-dart.pubcache
  • python310Packages.nbdev
  • python310Packages.nbdev.dist
  • python311Packages.nbdev
  • python311Packages.nbdev.dist
  • quarto
  • quartoMinimal
  • rstudio
  • rstudio-server
  • rstudioServerWrapper
  • rstudioWrapper
  • shopware-cli
  • yubioath-flutter
  • yubioath-flutter.pubcache

@NickCao NickCao merged commit 349e0c2 into NixOS:master Jan 5, 2024
23 checks passed
@shyim
Copy link
Member

shyim commented Jan 11, 2024

This PR seems to break dart compile on Darwin. #279772

@shirok1
Copy link
Contributor

shirok1 commented Jan 11, 2024

I think the SDK version parsing in pubspec.yaml is broken:

Screenshot 2024-01-12 at 04 02 46 image

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/hugo-missing-dependency-already-packaged-but-broken-dart-sass-embedded/39693/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants