From 5762f0893c776ef48812d59082eee46ca400f7d3 Mon Sep 17 00:00:00 2001
From: pablo
Date: Sat, 11 Apr 2026 12:22:20 +0300
Subject: [PATCH] feat: add flake
---
.gitignore | 3 ++
flake.lock | 48 ++++++++++++++++++++++++++++
flake.nix | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 142 insertions(+)
create mode 100644 flake.lock
create mode 100644 flake.nix
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/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..a405586
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,91 @@
+{
+ 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 = "0.1.0";
+ 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";
+ # Override panic=abort from workspace Cargo.toml — incompatible with buildRustPackage
+ CARGO_PROFILE_RELEASE_PANIC = "unwind";
+ # Tests run in CI; some require network access unavailable in the Nix sandbox
+ 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
+ ];
+ };
+ }
+ );
+ };
+}