diff --git a/.forgejo/workflows/update-flake-hashes.yml b/.forgejo/workflows/update-flake-hashes.yml index 57b0bd601..baf9b4b0a 100644 --- a/.forgejo/workflows/update-flake-hashes.yml +++ b/.forgejo/workflows/update-flake-hashes.yml @@ -45,6 +45,9 @@ jobs: rm new_toolchain_hash.txt + - name: Update rocksdb + run: nix run .#update-rocksdb + - name: Show diff run: git diff flake.nix nix diff --git a/nix/default.nix b/nix/default.nix index 742e34d5a..a49df0826 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -4,5 +4,6 @@ ./packages ./devshell.nix ./fmt.nix + ./rocksdb-updater.nix ]; } diff --git a/nix/packages/continuwuity.nix b/nix/packages/continuwuity.nix index c10312947..51a34b849 100644 --- a/nix/packages/continuwuity.nix +++ b/nix/packages/continuwuity.nix @@ -2,9 +2,10 @@ lib, self, stdenv, - liburing, + rocksdb, craneLib, pkg-config, + liburing, rustPlatform, cargoExtraArgs ? "", rustflags ? "", @@ -36,12 +37,17 @@ let pkg-config rustPlatform.bindgenHook ]; + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ liburing ]; - doCheck = false; + env = { CARGO_PROFILE = profile; RUSTFLAGS = rustflags; } + // (lib.optionalAttrs (rocksdb != null) { + ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; + ROCKSDB_LIB_DIR = "${rocksdb}/lib"; + }) // (lib.optionalAttrs (target_cpu != null) { TARGET_CPU = target_cpu; }); @@ -52,6 +58,18 @@ craneLib.buildPackage ( inherit cargoExtraArgs; cargoArtifacts = craneLib.buildDepsOnly attrs; + # Needed to make continuwuity link to rocksdb + postFixup = lib.optionalString (stdenv.hostPlatform.isLinux && rocksdb != null) '' + old_rpath="$(patchelf --print-rpath $out/bin/conduwuit)" + extra_rpath="${ + lib.makeLibraryPath [ + rocksdb + ] + }" + + patchelf --set-rpath "$old_rpath:$extra_rpath" $out/bin/conduwuit + ''; + meta = { description = "A community-driven Matrix homeserver in Rust"; mainProgram = "conduwuit"; diff --git a/nix/packages/default.nix b/nix/packages/default.nix index d73b4b022..37915b079 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -36,7 +36,10 @@ default = pkgs.callPackage ./continuwuity.nix { inherit self craneLib; + liburing = (if isStatic then pkgs.pkgsStatic else pkgs).liburing; + rocksdb = if isStatic then null else pkgs.callPackage ./rocksdb.nix { }; + # extra features via `cargoExtraArgs` cargoExtraArgs = "-F http3"; # extra RUSTFLAGS via `rustflags` diff --git a/nix/packages/rocksdb.nix b/nix/packages/rocksdb.nix new file mode 100644 index 000000000..b4427dbc4 --- /dev/null +++ b/nix/packages/rocksdb.nix @@ -0,0 +1,36 @@ +{ + # stdenv, + # enableJemalloc ? stdenv.hostPlatform.isLinux, + enableJemalloc ? false, + rocksdb, + fetchFromGitea, + rust-jemalloc-sys-unprefixed, + ... +}: +(rocksdb.override { + # rocksdb fails to build with prefixed jemalloc, which is required on + # darwin due to [1]. In this case, fall back to building rocksdb with + # libc malloc. This should not cause conflicts, because all of the + # jemalloc symbols are prefixed. + # + # [1]: https://github.com/tikv/jemallocator/blob/ab0676d77e81268cd09b059260c75b38dbef2d51/jemalloc-sys/src/env.rs#L17 + jemalloc = rust-jemalloc-sys-unprefixed; + inherit enableJemalloc; +}).overrideAttrs + ({ + version = "continuwuity-v0.5.0-unstable-2026-05-19"; + src = fetchFromGitea { + domain = "forgejo.ellis.link"; + owner = "continuwuation"; + repo = "rocksdb"; + rev = "3756b2b905e13216d8b56bcc783d814e7b073aff"; + hash = "sha256-rSv4fr2bf9JJwdodgeuPCuceeh7k97KVxrAOC0wyPQY="; + }; + + # We have this already at https://forgejo.ellis.link/continuwuation/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155 + # Unsetting `patches` so we don't have to revert it and make this nix exclusive + patches = [ ]; + + # Unset postPatch, as our version override breaks version-specific sed calls in the original package + postPatch = ""; + }) diff --git a/nix/rocksdb-updater.nix b/nix/rocksdb-updater.nix new file mode 100644 index 000000000..38f900651 --- /dev/null +++ b/nix/rocksdb-updater.nix @@ -0,0 +1,14 @@ +{ + perSystem = + { pkgs, ... }: + { + apps.update-rocksdb = { + type = "app"; + program = pkgs.writeShellApplication { + name = "update-rocksdb"; + runtimeInputs = [ pkgs.nix-update ]; + text = "nix-update rocksdb -F --version branch"; + }; + }; + }; +}