diff --git a/nix/checks.nix b/nix/checks.nix deleted file mode 100644 index 4533f20a2..000000000 --- a/nix/checks.nix +++ /dev/null @@ -1,105 +0,0 @@ -{ inputs, ... }: -{ - perSystem = - { - self', - lib, - pkgs, - ... - }: - let - uwulib = inputs.self.uwulib.init pkgs; - - rocksdb = self'.packages.rocksdb; - - commonAttrs = (uwulib.build.commonAttrs { }) // { - buildInputs = [ - pkgs.liburing - pkgs.rust-jemalloc-sys-unprefixed - rocksdb - ]; - nativeBuildInputs = [ - pkgs.pkg-config - # bindgen needs the build platform's libclang. Apparently due to "splicing - # weirdness", pkgs.rustPlatform.bindgenHook on its own doesn't quite do the - # right thing here. - pkgs.rustPlatform.bindgenHook - ]; - env = { - LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ]; - LD_LIBRARY_PATH = lib.makeLibraryPath [ - pkgs.liburing - pkgs.rust-jemalloc-sys-unprefixed - rocksdb - ]; - } - // uwulib.environment.buildPackageEnv - // { - ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; - ROCKSDB_LIB_DIR = "${rocksdb}/lib"; - }; - }; - cargoArtifacts = self'.packages.continuwuity-all-features-deps; - in - { - # taken from - # - # https://crane.dev/examples/quick-start.html - checks = { - continuwuity-all-features-build = self'.packages.continuwuity-all-features-bin; - - continuwuity-all-features-clippy = uwulib.build.craneLibForChecks.cargoClippy ( - commonAttrs - // { - inherit cargoArtifacts; - cargoClippyExtraArgs = "-- --deny warnings"; - } - ); - - continuwuity-all-features-docs = uwulib.build.craneLibForChecks.cargoDoc ( - commonAttrs - // { - inherit cargoArtifacts; - # This can be commented out or tweaked as necessary, e.g. set to - # `--deny rustdoc::broken-intra-doc-links` to only enforce that lint - env.RUSTDOCFLAGS = "--deny warnings"; - } - ); - - # Check formatting - continuwuity-all-features-fmt = uwulib.build.craneLibForChecks.cargoFmt { - src = uwulib.build.src; - }; - - continuwuity-all-features-toml-fmt = uwulib.build.craneLibForChecks.taploFmt { - src = pkgs.lib.sources.sourceFilesBySuffices uwulib.build.src [ ".toml" ]; - # taplo arguments can be further customized below as needed - taploExtraArgs = "--config ${inputs.self}/taplo.toml"; - }; - - # Audit dependencies - continuwuity-all-features-audit = uwulib.build.craneLibForChecks.cargoAudit { - inherit (inputs) advisory-db; - src = uwulib.build.src; - }; - - # Audit licenses - continuwuity-all-features-deny = uwulib.build.craneLibForChecks.cargoDeny { - src = uwulib.build.src; - }; - - # Run tests with cargo-nextest - # Consider setting `doCheck = false` on `continuwuity-all-features` if you do not want - # the tests to run twice - continuwuity-all-features-nextest = uwulib.build.craneLibForChecks.cargoNextest ( - commonAttrs - // { - inherit cargoArtifacts; - partitions = 1; - partitionType = "count"; - cargoNextestPartitionsExtraArgs = "--no-tests=pass"; - } - ); - }; - }; -} diff --git a/nix/crane.nix b/nix/crane.nix new file mode 100644 index 000000000..1d4c1b8fb --- /dev/null +++ b/nix/crane.nix @@ -0,0 +1,14 @@ +{ 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 718af6210..79d9baecd 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,10 +1,9 @@ { imports = [ - ./packages - ./checks.nix - ./devshell.nix - ./tests.nix - ./fmt.nix ./rust.nix + ./crane.nix + ./packages + ./devshell.nix + ./fmt.nix ]; } diff --git a/nix/devshell.nix b/nix/devshell.nix index 59a68f05c..8ae9fb170 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -1,27 +1,21 @@ -{ inputs, ... }: { perSystem = { + craneLib, self', lib, pkgs, ... }: - let - uwulib = inputs.self.uwulib.init pkgs; - rocksdbAllFeatures = self'.packages.rocksdb.override { - enableJemalloc = true; - }; - in { # basic nix shell containing all things necessary to build continuwuity in all flavors manually (on x86_64-linux) - devShells.default = uwulib.build.craneLib.devShell { + devShells.default = craneLib.devShell { packages = [ pkgs.nodejs pkgs.pkg-config pkgs.liburing pkgs.rust-jemalloc-sys-unprefixed - rocksdbAllFeatures + self'.packages.rocksdb ]; env.LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ]; }; diff --git a/nix/packages/default.nix b/nix/packages/default.nix index f38d0ba4a..0c8cdf33f 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -36,18 +36,22 @@ cargoArtifacts = crane.buildDepsOnly common; + rocksdb = pkgs.callPackage ./rocksdb.nix { }; + continuwuity = crane.buildPackage ( common // { inherit cargoArtifacts; - doCheck = false; - env.LIBCLANG_PATH = lib.makeLibraryPath [ pkgs.llvmPackages.libclang.lib ]; + env = { + ROCKSDB_INCLUDE_DIR = "${rocksdb}/include"; + ROCKSDB_LIB_DIR = "${rocksdb}/lib"; + }; } ); in { default = continuwuity; - rocksdb = pkgs.callPackage ./rocksdb.nix { }; + inherit rocksdb; }; }; } diff --git a/nix/packages/rocksdb.nix b/nix/packages/rocksdb.nix index cd255407f..9ca20ae4b 100644 --- a/nix/packages/rocksdb.nix +++ b/nix/packages/rocksdb.nix @@ -25,7 +25,7 @@ owner = "continuwuation"; repo = "rocksdb"; rev = version; - sha256 = ""; + sha256 = "sha256-X4ApGLkHF9ceBtBg77dimEpu720I79ffLoyPa8JMHaU="; }; # We have this already at https://forgejo.ellis.link/continuwuation/rocksdb/commit/a935c0273e1ba44eacf88ce3685a9b9831486155 diff --git a/nix/rust.nix b/nix/rust.nix index cf867ed2d..304d0c637 100644 --- a/nix/rust.nix +++ b/nix/rust.nix @@ -4,6 +4,7 @@ { system, lib, + pkgs, ... }: { @@ -11,7 +12,7 @@ let fnx = inputs.fenix.packages.${system}; - stable = fnx.fromToolchainFile { + stable-toolchain = fnx.fromToolchainFile { file = inputs.self + "/rust-toolchain.toml"; # See also `rust-toolchain.toml` @@ -19,11 +20,10 @@ }; in { - # used for building nix stuff (doesn't include rustfmt overhead) - build-toolchain = stable; - # used for dev shells + inherit stable-toolchain; + dev-toolchain = fnx.combine [ - stable + stable-toolchain # use the nightly rustfmt because we use nightly features fnx.complete.rustfmt ]; diff --git a/nix/tests.nix b/nix/tests.nix deleted file mode 100644 index 0aa34e087..000000000 --- a/nix/tests.nix +++ /dev/null @@ -1,150 +0,0 @@ -{ - perSystem = - { - self', - lib, - pkgs, - ... - }: - let - baseTestScript = - pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } - '' - import asyncio - import nio - - - async def main() -> None: - # Connect to continuwuity - client = nio.AsyncClient("http://continuwuity:6167", "alice") - - # Register as user alice - response = await client.register("alice", "my-secret-password") - - # Log in as user alice - response = await client.login("my-secret-password") - - # Create a new room - response = await client.room_create(federate=False) - print("Matrix room create response:", response) - assert isinstance(response, nio.RoomCreateResponse) - room_id = response.room_id - - # Join the room - response = await client.join(room_id) - print("Matrix join response:", response) - assert isinstance(response, nio.JoinResponse) - - # Send a message to the room - response = await client.room_send( - room_id=room_id, - message_type="m.room.message", - content={ - "msgtype": "m.text", - "body": "Hello continuwuity!" - } - ) - print("Matrix room send response:", response) - assert isinstance(response, nio.RoomSendResponse) - - # Sync responses - response = await client.sync(timeout=30000) - print("Matrix sync response:", response) - assert isinstance(response, nio.SyncResponse) - - # Check the message was received by continuwuity - last_message = response.rooms.join[room_id].timeline.events[-1].body - assert last_message == "Hello continuwuity!" - - # Leave the room - response = await client.room_leave(room_id) - print("Matrix room leave response:", response) - assert isinstance(response, nio.RoomLeaveResponse) - - # Close the client - await client.close() - - - if __name__ == "__main__": - asyncio.run(main()) - ''; - in - { - # run some nixos tests as checks - checks = lib.pipe self'.packages [ - # we take all packages (names) - builtins.attrNames - # we filter out all packages that end with `-bin` (which we are interested in for testing) - (builtins.filter (lib.hasSuffix "-bin")) - # for each of these binaries we built the basic nixos test - # - # this test was initially yoinked from - # - # https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix - (builtins.concatMap ( - name: - builtins.map - ( - { config, suffix }: - { - name = "test-${name}-${suffix}"; - value = pkgs.testers.runNixOSTest { - inherit name; - - nodes = { - continuwuity = { - services.matrix-continuwuity = { - enable = true; - package = self'.packages.${name}; - settings = config; - extraEnvironment.RUST_BACKTRACE = "yes"; - }; - networking.firewall.allowedTCPPorts = [ 6167 ]; - }; - client.environment.systemPackages = [ baseTestScript ]; - }; - - testScript = '' - start_all() - - with subtest("start continuwuity"): - continuwuity.wait_for_unit("continuwuity.service") - continuwuity.wait_for_open_port(6167) - - with subtest("ensure messages can be exchanged"): - client.succeed("${lib.getExe baseTestScript} >&2") - ''; - - }; - } - ) - [ - { - suffix = "base"; - config = { - global = { - server_name = name; - address = [ "0.0.0.0" ]; - allow_registration = true; - yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true; - }; - }; - } - { - suffix = "with-room-version"; - config = { - global = { - server_name = name; - address = [ "0.0.0.0" ]; - allow_registration = true; - yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true; - default_room_version = "12"; - }; - }; - } - ] - )) - builtins.listToAttrs - ]; - }; -}