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
This commit is contained in:
Pablo Lopez 2026-04-17 16:27:15 +03:00 committed by GitHub
parent 6c7b3a4252
commit df84fc87cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 154 additions and 1 deletions

View File

@ -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

3
.gitignore vendored
View File

@ -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)

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2024"
[lib]
crate-type = ["rlib","staticlib","dylib"]
crate-type = ["rlib","staticlib"]
[dependencies]
base64 = "0.22"

48
flake.lock generated Normal file
View File

@ -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
}

88
flake.nix Normal file
View File

@ -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
];
};
}
);
};
}