Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 60 additions & 5 deletions nix/dart/vodozemac/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,73 @@
{ lib, flake-parts-lib, ... }:
importingFlake: {
options.perSystem = flake-parts-lib.mkPerSystemOption (
{ pkgs, ... }:
{ config, pkgs, ... }:
let
# The very package `packages.famedly-vodozemac` is built from, called
# again rather than read off `self'`: reaching into the flake's own
# packages from inside an option declaration would make the projects
# depend on config that is derived from the projects.
vodozemac = pkgs.callPackage ./native.nix { };
vodozemac = pkgs.callPackage ./native.nix {
source = pkgs.callPackage ./source.nix {
inherit (config.famedly.standards.dart.vodozemac) version hash cargoHash;
};
};
in
{
options.famedly.standards.dart.vodozemac = {
version = lib.mkOption {
description = ''
Which dart-vodozemac release to build the bindings from.

Keep it equal to the `vodozemac` — or `flutter_vodozemac` —
constraint in the project's `pubspec.yaml`. The Dart package that
calls these bindings is generated from this very release, and a
project talking to bindings it was not generated against fails when
a call is made rather than when it is built, so a pre-commit hook
compares the two.

The default is the release we would like everyone on. A project that
cannot follow yet sets its own, together with both hashes below,
which is why they are options at all: nothing forces two projects
onto one version of a dependency.
'';

type = lib.types.str;
default = "0.5.0";
};

hash = lib.mkOption {
description = ''
Hash of the release's source tree, which changes with `version`.
Nix names the value it expected when this one disagrees.
'';

type = lib.types.str;
default = "sha256-H3g0is/+Cf3xBqqxw6qCjZSv5ZjftNSQP4hdwwEsOrs=";
};

cargoHash = lib.mkOption {
description = ''
Hash of the crate's vendored dependencies, which changes with the
release's `Cargo.lock`. One lockfile, so one vendor: which
dependencies a target links is decided when it is built, not when
they are resolved, and both targets share this.
'';

type = lib.types.str;
default = "sha256-eKKrcroV2yl/FV2WmgZWFPO5MPAGz0xCvpr0fgIuGZ4=";
};
};

options.famedly.standards.dart.projects = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule (
{ config, ... }:
{
options.vodozemac.enable = lib.mkEnableOption ''
the vodozemac bindings for this project.
the vodozemac bindings for this project. Which release they are
built from is `famedly.standards.dart.vodozemac.version`, since
the bindings are built once for the repository.

Points `flutter_rust_bridge`'s library lookup at the nix-built
library, so `vod.init` finds it without the project having to
Expand Down Expand Up @@ -54,11 +105,15 @@ importingFlake: {
needed = lib.any (project: project.vodozemac.enable) (
lib.attrValues config.famedly.standards.dart.projects
);

source = pkgs.callPackage ./source.nix {
inherit (config.famedly.standards.dart.vodozemac) version hash cargoHash;
};
in
lib.mkMerge [
(lib.mkIf (config.famedly.standards.dart.projects != { }) {
packages.famedly-vodozemac = pkgs.callPackage ./native.nix { };
packages.famedly-vodozemac-web = pkgs.callPackage ./web.nix { };
packages.famedly-vodozemac = pkgs.callPackage ./native.nix { inherit source; };
packages.famedly-vodozemac-web = pkgs.callPackage ./web.nix { inherit source; };
})

# The lookup itself goes through `runtime.env`; this only makes entering
Expand Down
5 changes: 1 addition & 4 deletions nix/dart/vodozemac/native.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
callPackage,
fixDarwinDylibNames,
lib,
rustPlatform,
source,
stdenv,
}:

let
source = callPackage ./source.nix { };
in
rustPlatform.buildRustPackage {
pname = "famedly-vodozemac";

Expand Down
22 changes: 12 additions & 10 deletions nix/dart/vodozemac/source.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
# native library and the WebAssembly module are the same crate compiled twice,
# and a version that drifted between them fails at the first call and not
# before.
{ fetchFromGitHub }:
{
fetchFromGitHub,
version,
hash,
cargoHash,
}:

let
# Keep in sync with the `vodozemac` constraint in consumers' `pubspec.yaml`,
# which a pre-commit hook checks. The tags follow the Flutter plugin.
version = "0.5.0";

src = fetchFromGitHub {
owner = "famedly";
repo = "dart-vodozemac";

# The repository is a Flutter plugin; its tags follow that plugin's version,
# which for the releases we build is the Dart package's as well.
tag = version;
hash = "sha256-H3g0is/+Cf3xBqqxw6qCjZSv5ZjftNSQP4hdwwEsOrs=";

inherit hash;
};
in
{
inherit version src;
inherit version src cargoHash;

# The repository is a Flutter plugin; only the crate is interesting to us.
sourceRoot = "${src.name}/rust";

# One lockfile, so one vendor for both targets.
cargoHash = "sha256-eKKrcroV2yl/FV2WmgZWFPO5MPAGz0xCvpr0fgIuGZ4=";

meta = {
description = "Dart bindings for the vodozemac Matrix cryptography library";
homepage = "https://github.com/famedly/dart-vodozemac";
Expand Down
4 changes: 1 addition & 3 deletions nix/dart/vodozemac/web.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
{
binaryen,
buildPackages,
callPackage,
cargo,
lib,
removeReferencesTo,
rustPlatform,
rustc,
source,
stdenv,
symlinkJoin,
wasm-bindgen-cli_0_2_100,
Expand All @@ -21,8 +21,6 @@
}:

let
source = callPackage ./source.nix { };

# The stem `wasm-bindgen` writes, and the name the Dart package looks up.
crate = "vodozemac_bindings_dart";

Expand Down