diff --git a/.forgejo/workflows/update-flake-hashes.yml b/.forgejo/workflows/update-flake-hashes.yml index baf9b4b0a..57b0bd601 100644 --- a/.forgejo/workflows/update-flake-hashes.yml +++ b/.forgejo/workflows/update-flake-hashes.yml @@ -45,9 +45,6 @@ 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/crane.nix b/nix/crane.nix deleted file mode 100644 index 1d4c1b8fb..000000000 --- a/nix/crane.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ inputs, ... }: -{ - perSystem = - { - pkgs, - self', - ... - }: - { - _module.args.craneLib = (inputs.crane.mkLib pkgs).overrideToolchain ( - pkgs: self'.packages.stable-toolchain - ); - }; -} diff --git a/nix/default.nix b/nix/default.nix index b4ba59162..742e34d5a 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,10 +1,8 @@ { imports = [ ./rust.nix - ./crane.nix ./packages ./devshell.nix ./fmt.nix - ./rocksdb-updater.nix ]; } diff --git a/nix/devshell.nix b/nix/devshell.nix index 24441e64c..d7b91c9f9 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -1,7 +1,6 @@ -{ +{ inputs, ... }: { perSystem = { - craneLib, self', lib, pkgs, @@ -9,34 +8,36 @@ }: { # basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux) - devShells.default = craneLib.devShell { - packages = [ - self'.packages.rocksdb - pkgs.nodejs - pkgs.pkg-config - ] - ++ lib.optionals pkgs.stdenv.isLinux [ - pkgs.liburing - pkgs.rust-jemalloc-sys-unprefixed - ]; - - env = { - LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ]; - LD_LIBRARY_PATH = lib.makeLibraryPath ( - [ - pkgs.stdenv.cc.cc.lib + devShells.default = + (inputs.crane.mkLib pkgs).overrideToolchain (pkgs: self'.packages.stable-toolchain).devShell + { + packages = [ + self'.packages.rocksdb + pkgs.nodejs + pkgs.pkg-config ] ++ lib.optionals pkgs.stdenv.isLinux [ pkgs.liburing - pkgs.jemalloc - ] - ); - } - // lib.optionalAttrs pkgs.stdenv.isLinux { - PKG_CONFIG_PATH = lib.makeSearchPath "lib/pkgconfig" [ - pkgs.liburing.dev - ]; - }; - }; + pkgs.rust-jemalloc-sys-unprefixed + ]; + + env = { + LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ]; + LD_LIBRARY_PATH = lib.makeLibraryPath ( + [ + pkgs.stdenv.cc.cc.lib + ] + ++ lib.optionals pkgs.stdenv.isLinux [ + pkgs.liburing + pkgs.jemalloc + ] + ); + } + // lib.optionalAttrs pkgs.stdenv.isLinux { + PKG_CONFIG_PATH = lib.makeSearchPath "lib/pkgconfig" [ + pkgs.liburing.dev + ]; + }; + }; }; } diff --git a/nix/packages/continuwuity.nix b/nix/packages/continuwuity.nix index ec34b0b92..30eb18973 100644 --- a/nix/packages/continuwuity.nix +++ b/nix/packages/continuwuity.nix @@ -9,7 +9,6 @@ cargoExtraArgs ? "", rustflags ? "", target_cpu ? null, - rocksdb, profile ? "release", }: let @@ -29,17 +28,20 @@ let attrs = { inherit src; + strictDeps = true; nativeBuildInputs = [ pkg-config rustPlatform.bindgenHook ]; buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ liburing ]; env = { - ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; - ROCKSDB_LIB_DIR = "${rocksdb}/lib"; CARGO_PROFILE = profile; RUSTFLAGS = rustflags; } + // (lib.optionalAttrs stdenv.hostPlatform.isStatic { + CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl"; + CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static"; + }) // (lib.optionalAttrs (target_cpu != null) { TARGET_CPU = target_cpu; }); @@ -50,18 +52,6 @@ craneLib.buildPackage ( inherit cargoExtraArgs; cargoArtifacts = craneLib.buildDepsOnly attrs; - # Needed to make continuwuity link to rocksdb - postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' - 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 2f2422ffc..2cb692d40 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -1,4 +1,5 @@ { + inputs, self, ... }: @@ -6,32 +7,71 @@ perSystem = { self', + lib, pkgs, + system, craneLib, ... }: { - packages = { - rocksdb = pkgs.callPackage ./rocksdb.nix { }; - default = pkgs.callPackage ./continuwuity.nix { - inherit self craneLib; - inherit (self'.packages) rocksdb; - # extra features via `cargoExtraArgs` - cargoExtraArgs = "-F http3"; - # extra RUSTFLAGS via `rustflags` - # the stuff below is required for http3 - rustflags = "--cfg reqwest_unstable"; - }; - # users may also override this with other cargo profiles to build for other feature sets - # for features configuration see `default` package which enables http3 by default + packages = + let + mkPackages = + pkgs: + let + fnx = inputs.fenix.packages.${system}; - # example: different compilation profile and different target_cpu - max-perf-haswell = self'.packages.default.override { - # compiles explicitly for haswell arch cpus - target_cpu = "haswell"; - # compiles slower but with more thorough optimizations - profile = "release-max-perf"; - }; - }; + isStatic = pkgs.stdenv.hostPlatform.isMusl; + + craneLib = (inputs.crane.mkLib pkgs).overrideToolchain ( + _: + if isStatic then + fnx.combine [ + self'.packages.stable-toolchain + (fnx.targets.${pkgs.stdenv.hostPlatform.config}.stable).rust-std + ] + else + self'.packages.stable-toolchain + ); + in + { + default = pkgs.callPackage ./continuwuity.nix { + inherit self craneLib; + liburing = (if isStatic then pkgs.pkgsStatic else pkgs).liburing; + # extra features via `cargoExtraArgs` + cargoExtraArgs = "-F http3"; + # extra RUSTFLAGS via `rustflags` + # the stuff below is required for http3 + rustflags = "--cfg reqwest_unstable"; + }; + # users may also override this with other cargo profiles to build for other feature sets + # for features configuration see `default` package which enables http3 by default + + # example: different compilation profile and different target_cpu + max-perf-haswell = self'.packages.default.override { + # compiles explicitly for haswell arch cpus + target_cpu = "haswell"; + # compiles slower but with more thorough optimizations + profile = "release-max-perf"; + }; + }; + in + (mkPackages pkgs) + // (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-static-x86_64" value) ( + mkPackages ( + import inputs.nixpkgs { + localSystem = system; + crossSystem = "x86_64-unknown-linux-musl"; + } + ) + )) + // (lib.mapAttrs' (name: value: lib.nameValuePair "${name}-static-aarch64" value) ( + mkPackages ( + import inputs.nixpkgs { + localSystem = system; + crossSystem = "aarch64-unknown-linux-musl"; + } + ) + )); }; } diff --git a/nix/packages/rocksdb.nix b/nix/packages/rocksdb.nix deleted file mode 100644 index b4427dbc4..000000000 --- a/nix/packages/rocksdb.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - # 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 deleted file mode 100644 index 38f900651..000000000 --- a/nix/rocksdb-updater.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - perSystem = - { pkgs, ... }: - { - apps.update-rocksdb = { - type = "app"; - program = pkgs.writeShellApplication { - name = "update-rocksdb"; - runtimeInputs = [ pkgs.nix-update ]; - text = "nix-update rocksdb -F --version branch"; - }; - }; - }; -} diff --git a/nix/rust.nix b/nix/rust.nix index ab62ad197..f56823839 100644 --- a/nix/rust.nix +++ b/nix/rust.nix @@ -13,7 +13,7 @@ fnx = inputs.fenix.packages.${system}; stable-toolchain = fnx.fromToolchainFile { - file = inputs.self + "/rust-toolchain.toml"; + dir = inputs.self; # See also `rust-toolchain.toml` sha256 = "sha256-mvUGEOHYJpn3ikC5hckneuGixaC+yGrkMM/liDIDgoU=";