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
27 changes: 27 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build (Nix)

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix flake check
build-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- run: nix build .#
79 changes: 29 additions & 50 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,7 @@
config.allowUnfree = true;
};

inherit (pkgs) mkShell rust-bin writeShellApplication;

rust = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

scripts.muchat-watch = writeShellApplication {
name = "muchat-watch";
runtimeInputs = with pkgs; [
cargo-nextest
cargo-watch
rust
];
text = ''
exec cargo watch -s 'cargo fmt && cargo clippy --all && cargo nextest run'
'';
};
muchat = import ./lib.nix pkgs;

checks.pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
Expand All @@ -56,48 +42,41 @@

rustfmt = {
enable = true;
packageOverrides.cargo = rust;
packageOverrides.cargo = muchat.packages.rust;
};

prettier.enable = true;
prettier = {
enable = true;

excludes = [ "pnpm-lock.yaml" ];
};
};
};

packages.simplex-chat = pkgs.callPackage ./nix/simplex-chat.nix { };
in
{
inherit checks packages;

devShells.default = mkShell {
inherit (checks.pre-commit-check) shellHook;

name = "muchat";

buildInputs = with pkgs; [
(attrValues scripts)
(attrValues packages)

rust

cargo-edit
cargo-tauri
cargo-watch
nodePackages.pnpm
nodejs
openssl
pkg-config

webkitgtk
gtk3
cairo
gdk-pixbuf
glib
dbus
openssl
librsvg
webkitgtk_4_1
];
};
inherit checks;
inherit (muchat) packages;

devShells.default =
with pkgs;
mkShell {
inherit (checks.pre-commit-check) shellHook;

name = "muchat-shell";
inputsFrom = attrValues muchat.packages;

buildInputs = with pkgs; [
muchat.packages.simplex-chat
muchat.packages.rust

cargo-edit
cargo-tauri
cargo-watch
nodePackages.pnpm
nodejs
];
};
}
);
}
53 changes: 53 additions & 0 deletions lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
callPackage,
makeRustPlatform,
makeWrapper,
rust-bin,
stdenv,
...
}:
let
inherit (builtins) readFile;

lib = {
src = ./.;

rustPlatform = makeRustPlatform {
rustc = rust;
cargo = rust;
};

baseName = name: baseNameOf (toString name);
loadTOML = path: fromTOML (readFile path);
};

rust = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

packages = {
inherit rust;

default = stdenv.mkDerivation {
name = "muchat";

nativeBuildInputs = [ makeWrapper ];

dontBuild = true;
dontUnpack = true;

installPhase = with packages; ''
mkdir -p $out/{share/muchat/bin,bin}

install -m 0755 ${ui}/bin/muchat-ui $out/bin/.muchat-unwrapped
makeWrapper $out/bin/.muchat-unwrapped $out/bin/muchat \
--prefix PATH : ${simplex-chat}/bin
'';
};

frontend = callPackage ./ui { muchat = { inherit lib; }; };
simplex-chat = callPackage ./nix/simplex-chat.nix { };
ui = callPackage ./ui/src-tauri { muchat = { inherit lib packages; }; };
};
in
{
inherit lib packages;
}
8 changes: 4 additions & 4 deletions providers/src/chat/client.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use std::{

Check warning on line 1 in providers/src/chat/client.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/muchat/muchat/providers/src/chat/client.rs
sync::{
atomic::{AtomicU16, Ordering},
Arc,
atomic::{AtomicU16, Ordering},
},
time::Duration,
};

Check warning on line 8 in providers/src/chat/client.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/muchat/muchat/providers/src/chat/client.rs
use async_stream::try_stream;
use futures::{
stream::{SplitSink, SplitStream},
Future,
SinkExt,
Stream,
StreamExt,

Check warning on line 14 in providers/src/chat/client.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/muchat/muchat/providers/src/chat/client.rs
stream::{SplitSink, SplitStream},
};
use tokio::{
net::TcpStream,
sync::{

Check warning on line 19 in providers/src/chat/client.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/muchat/muchat/providers/src/chat/client.rs
mpsc::{self, Receiver, Sender},
Mutex,
mpsc::{self, Receiver, Sender},
},
};
use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};
use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, connect_async, tungstenite::Message};

use super::{
commands::{CommandData, CommandPayload, ComposedMessage},
Expand Down
2 changes: 1 addition & 1 deletion providers/src/chat/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use client::{ChatClient, StreamMessage};

Check warning on line 3 in providers/src/chat/mod.rs

View workflow job for this annotation

GitHub Actions / check

Diff in /home/runner/work/muchat/muchat/providers/src/chat/mod.rs
use commands::ChatCommand;
use error::TransportError;
use futures::{pin_mut, Stream, StreamExt};
use futures::{Stream, StreamExt, pin_mut};
use response::{ChatInfo, ChatInfoType, ChatResponse, DirectionType};
use tokio::{
self,
Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
edition = "2024"

reorder_imports = true
imports_granularity = "Crate"
imports_layout = "HorizontalVertical"
Expand Down
42 changes: 42 additions & 0 deletions ui/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
nodejs,
pnpm,
stdenv,
muchat,
}:
let
inherit (builtins) filterSource fromJSON readFile;
inherit (muchat.lib) baseName;
inherit (stdenv) mkDerivation;

package-json = fromJSON (readFile ./package.json);
in
mkDerivation (final: {
inherit (package-json) version;
pname = package-json.name;

src = filterSource (name: _: !(baseName name == "src-tauri")) ./.;

nativeBuildInputs = [
nodejs
pnpm.configHook
];

buildPhase = ''
runHook preBuild

pnpm build

runHook postBuild
'';

installPhase = ''
mkdir -p $out
cp -r dist/* $out/
'';

pnpmDeps = pnpm.fetchDeps {
inherit (final) pname version src;
hash = "sha256-YIy2dICdyQj+v0lqOZGS95oPKdGmNHUSY4e4WzK/xSw=";
};
})
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "muchat-ui",
"name": "muchat-ui-frontend",
"private": true,
"version": "0.0.0",
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions ui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ tauri-build = { version = "2.0.3", features = [] }

[dependencies]
log = "0.4.22"
serde = { workspace = true }
serde_json = { workspace = true }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
tauri = "2.1.1"
tauri-plugin-fs = "2.2.0"
tauri-plugin-log = "2.2.0"
tauri-plugin-shell = "2.2.0"
tauri-plugin-websocket = "2.2.0"
tokio = { workspace = true }
tokio = { version = "1.42.0", features = ["full"] }
79 changes: 79 additions & 0 deletions ui/src-tauri/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
cairo,
dbus,
gdk-pixbuf,
glib,
gnused,
gtk3,
lib,
librsvg,
muchat,
openssl,
pkg-config,
pnpm,
stdenv,
webkitgtk,
webkitgtk_4_1,
}:
let
inherit (lib) optionals splitString;
inherit (muchat.lib) loadTOML rustPlatform src;
inherit (stdenv) isDarwin isLinux;

cargoTOML = loadTOML ./Cargo.toml;

toPatch =
with builtins;
path: target:
let
content = readFile path;
lines = splitString "\n" content;
additions = map (line: "+" + line) lines;
diffBody = concatStringsSep "\n" additions;
lineCount = length lines;
in
toFile "${target}.patch" ''
diff --git a/${target} b/${target}
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/${target}
@@ -0,0 +1,${toString lineCount} @@
${diffBody}
'';

in
rustPlatform.buildRustPackage {
inherit (cargoTOML.package) name version;

src = "${src}/ui/src-tauri";
cargoLock.lockFile = "${src}/Cargo.lock";

buildInputs =
[ ]
++ optionals isLinux [
openssl
webkitgtk
gtk3
cairo
gdk-pixbuf
glib
dbus
librsvg
webkitgtk_4_1
]
++ optionals isDarwin [ ];

nativeBuildInputs = [
gnused
pkg-config
];

useNextest = true;

patches = [ (toPatch "${src}/Cargo.lock" "Cargo.lock") ];

patchPhase = ''
sed -i -e "s;../dist;${muchat.packages.frontend};g" tauri.conf.json
'';
}
2 changes: 1 addition & 1 deletion ui/src/components/features/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const Chat = () => {
<div key={index}>
{msg.content.type === "rcvMsgContent" && (
<MessageBubble
heading={contact?.localDisplayName ?? "No Display Name"}
heading={contact?.localDisplayName ?? "No Display Name"}
side="right"
key={index}
>
Expand Down
Loading