From 0fdb1be9387dd4964ac18bffd8e6b8b6fe9d98d5 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Fri, 3 Apr 2026 10:56:45 -0400 Subject: [PATCH] feat: add customizable cargoExtraArgs --- nix/packages/continuwuity.nix | 68 +++++++++++++++++++++++++++++++ nix/packages/default.nix | 76 +++++------------------------------ 2 files changed, 77 insertions(+), 67 deletions(-) create mode 100644 nix/packages/continuwuity.nix diff --git a/nix/packages/continuwuity.nix b/nix/packages/continuwuity.nix new file mode 100644 index 000000000..e5fc92b30 --- /dev/null +++ b/nix/packages/continuwuity.nix @@ -0,0 +1,68 @@ +{ + lib, + self, + craneLib, + callPackage, + pkg-config, + rustPlatform, + liburing, + stdenv, + cargoExtraArgs ? [ ], +}: +let + # see https://crane.dev/API.html#cranelibfiltercargosources + # we need to keep the `web` directory which would be filtered out by the regular source filtering function + # https://crane.dev/API.html#cranelibcleancargosource + isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null; + isRust = craneLib.filterCargoSources; + isNix = path: _type: builtins.match ".+/nix.*" path != null; + webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t); + + src = lib.cleanSourceWith { + src = self; + filter = webOrRustNotNix; + name = "source"; + }; + + rocksdb = callPackage ./rocksdb.nix { }; + + attrs = { + inherit src; + nativeBuildInputs = [ + pkg-config + rustPlatform.bindgenHook + ]; + buildInputs = lib.optional stdenv.hostPlatform.isLinux liburing; + env = { + ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; + ROCKSDB_LIB_DIR = "${rocksdb}/lib"; + }; + }; + + cargoArtifacts = craneLib.buildDepsOnly attrs; + +in +craneLib.buildPackage ( + lib.recursiveUpdate attrs { + inherit cargoArtifacts cargoExtraArgs; + + # Needed to make continuwuity link to rocksdb + postFixup = '' + 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"; + platforms = lib.platforms.linux; + maintainers = with lib.maintainers; [ quadradical ]; + }; + } +) diff --git a/nix/packages/default.nix b/nix/packages/default.nix index 19a017402..245e25807 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -1,77 +1,19 @@ -{ inputs, ... }: +{ + self, + ... +}: { perSystem = { - craneLib, - self', pkgs, - lib, + craneLib, ... }: { - packages = - let - src = - let - # see https://crane.dev/API.html#cranelibfiltercargosources - # we need to keep the `web` directory which would be filtered out by the regular source filtering function - # https://crane.dev/API.html#cranelibcleancargosource - isWebTemplate = path: _type: builtins.match ".*(src/(web|service)|docs).*" path != null; - isRust = craneLib.filterCargoSources; - isNix = path: _type: builtins.match ".+/nix.*" path != null; - webOrRustNotNix = p: t: !(isNix p t) && (isWebTemplate p t || isRust p t); - in - lib.cleanSourceWith { - src = inputs.self; - filter = webOrRustNotNix; - name = "source"; - }; - rocksdb = pkgs.callPackage ./rocksdb.nix { }; - - attrs = { - inherit src; - nativeBuildInputs = with pkgs; [ - pkg-config - rustPlatform.bindgenHook - ]; - buildInputs = [ - pkgs.liburing - ]; - env = { - ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; - ROCKSDB_LIB_DIR = "${rocksdb}/lib"; - }; - }; - - cargoArtifacts = craneLib.buildDepsOnly attrs; - in - { - default = craneLib.buildPackage ( - lib.recursiveUpdate attrs { - inherit cargoArtifacts; - - # Needed to make continuwuity link to rocksdb - postFixup = '' - old_rpath="$(patchelf --print-rpath $out/bin/conduwuit)" - extra_rpath="${ - pkgs.lib.makeLibraryPath [ - pkgs.rocksdb - ] - }" - - patchelf --set-rpath "$old_rpath:$extra_rpath" $out/bin/conduwuit - ''; - - meta = { - description = "A community-driven Matrix homeserver in Rust"; - mainProgram = "conduwuit"; - platforms = lib.platforms.linux; - maintainers = with lib.maintainers; [ quadradical ]; - }; - } - ); - inherit rocksdb; - }; + packages = { + rocksdb = pkgs.callPackage ./rocksdb.nix { }; + default = pkgs.callPackage ./continuwuity.nix { inherit self craneLib; }; + }; }; }