{ pkgs, lib, fenix, selfPkgs, ... }: let version = "0.15.0"; mkServicepoint = { rustPlatform, buildType, }: rustPlatform.buildRustPackage (finalAttrs: { inherit buildType version; pname = "servicepoint-binding-c"; src = lib.filter { root = ./.; include = [ ./Cargo.lock ./Cargo.toml ./src ./build.rs ./LICENSE ./cbindgen.toml ]; }; cargoLock.lockFile = ./Cargo.lock; meta = { description = "C bindings for the servicepoint crate."; homepage = "https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c"; license = lib.licenses.gpl3Plus; pkgConfigModules = [ "servicepoint" ]; }; nativeBuildInputs = with pkgs; [ pkg-config ]; buildInputs = with pkgs; [ xz ]; preBuild = '' mkdir -p include export SERVICEPOINT_HEADER_OUT=$(realpath "include") echo "Rust version: $(rustc --version)" echo "preBuild hook: set SERVICEPOINT_HEADER_OUT to $SERVICEPOINT_HEADER_OUT" ''; postInstall = '' cp -r include $out mkdir -p $out/lib/pkgconfig sed "s:\$out:$out:g" ${./servicepoint.pc.in} | sed "s:\$version:$version:g" > $out/lib/pkgconfig/servicepoint.pc ''; }); mkExample = { name, servicepointBinding }: pkgs.stdenv.mkDerivation { inherit version; pname = "servicepoint-c-example-${name}"; nativeBuildInputs = with pkgs; [ pkg-config ]; buildInputs = [ servicepointBinding ]; src = ./example/src; #dontUnpack = true; buildPhase = '' mkdir -p $out/bin gcc ${name}.c $(pkg-config --libs servicepoint --cflags) -o $out/bin/${name} ''; }; rustPlatform-stable = pkgs.rustPlatform; rustPlatform-unstable = pkgs.makeRustPlatform { cargo = fenix.minimal.cargo; rustc = fenix.minimal.rustc; }; examples = [ "announce" "brightness_tester" "header_logger" "moving_line" "random_stuff" "wiping_clear" ]; in rec { servicepoint-binding-c-release = mkServicepoint { buildType = "release"; rustPlatform = rustPlatform-stable; }; servicepoint-binding-c-size-optimized = mkServicepoint { buildType = "size_optimized"; rustPlatform = rustPlatform-unstable; }; servicepoint-binding-c = servicepoint-binding-c-release; all-examples = pkgs.symlinkJoin { name = "servicepoint-all-examples"; paths = builtins.map (e: selfPkgs.${e}) examples; }; } // (lib.genAttrs examples ( name: mkExample { inherit name; servicepointBinding = selfPkgs.servicepoint-binding-c; } ))