From df84fc87cf3019f2f4621109719b9674565ce891 Mon Sep 17 00:00:00 2001 From: Pablo Lopez Date: Fri, 17 Apr 2026 16:27:15 +0300 Subject: [PATCH] feat: add flake (#85) * feat: add flake * fix: pr feedback * fix: removing dylib for libchat not used and it was causing the error with panic abort --- .github/workflows/ci.yml | 14 ++++++ .gitignore | 3 ++ core/conversations/Cargo.toml | 2 +- flake.lock | 48 +++++++++++++++++++ flake.nix | 88 +++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d44d88f..f1f19d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,3 +54,17 @@ jobs: - name: Run C FFI smoketest under valgrind run: make valgrind working-directory: crates/client-ffi/examples/message-exchange + + nix-build: + name: Nix Build + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v31 + with: + extra_nix_config: | + experimental-features = nix-command flakes + - run: nix build --print-build-logs diff --git a/.gitignore b/.gitignore index 9d00a2f..9ccb3e1 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,9 @@ target # Temporary data folder tmp +# Nix build output symlink +result + .DS_Store # Generated C headers (produced by `make` in examples/c-ffi; do not commit) diff --git a/core/conversations/Cargo.toml b/core/conversations/Cargo.toml index c109bff..b265823 100644 --- a/core/conversations/Cargo.toml +++ b/core/conversations/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [lib] -crate-type = ["rlib","staticlib","dylib"] +crate-type = ["rlib","staticlib"] [dependencies] base64 = "0.22" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1d78474 --- /dev/null +++ b/flake.lock @@ -0,0 +1,48 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1775710090, + "narHash": "sha256-ar3rofg+awPB8QXDaFJhJ2jJhu+KqN/PRCXeyuXR76E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4c1018dae018162ec878d42fec712642d214fdfa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1775877051, + "narHash": "sha256-wpSQm2PD/w4uRo2wb8utk0b5hOBkkg/CZ1xICY+qB7M=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "08b4f3633471874c8894632ade1b78d75dbda002", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9f5de6c --- /dev/null +++ b/flake.nix @@ -0,0 +1,88 @@ +{ + description = "libchat - Logos Chat cryptographic library"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, rust-overlay }: + let + systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f { + pkgs = import nixpkgs { + inherit system; + overlays = [ rust-overlay.overlays.default ]; + }; + }); + in + { + packages = forAllSystems ({ pkgs }: + let + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust_toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + in + { + default = rustPlatform.buildRustPackage { + pname = "libchat"; + version = (builtins.fromTOML (builtins.readFile ./crates/client-ffi/Cargo.toml)).package.version; + src = pkgs.lib.cleanSourceWith { + src = ./.; + filter = path: type: + let base = builtins.baseNameOf path; + in !(builtins.elem base [ "target" "nim-bindings" ".git" ".github" "tmp" ]); + }; + + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "chat-proto-0.1.0" = "sha256-aCl80VOIkd/GK3gnmRuFoSAvPBfeE/FKCaNlLt5AbUU="; + }; + }; + + nativeBuildInputs = [ pkgs.perl pkgs.pkg-config pkgs.cmake ]; + buildType = "release"; + doCheck = false; + + postBuild = '' + cargo run --frozen --release --bin generate-headers --features headers -p client-ffi -- crates/client-ffi/client_ffi.h + ''; + + installPhase = '' + runHook preInstall + mkdir -p $out/lib $out/include + cp target/${pkgs.stdenv.hostPlatform.rust.rustcTarget}/release/libclient_ffi.a $out/lib/ + cp crates/client-ffi/client_ffi.h $out/include/ + runHook postInstall + ''; + + meta = with pkgs.lib; { + description = "Logos Chat library (C FFI)"; + platforms = platforms.unix; + }; + }; + } + ); + + devShells = forAllSystems ({ pkgs }: + let + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust_toolchain.toml; + in + { + default = pkgs.mkShell { + nativeBuildInputs = [ + rustToolchain + pkgs.pkg-config + pkgs.cmake + ]; + }; + } + ); + }; +}