unbound-rust-mod/flake.nix

69 lines
2.2 KiB
Nix
Raw Normal View History

2024-08-09 15:27:40 +07:00
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:chayleaf/nixpkgs/unbound";
2024-08-12 05:41:21 +07:00
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
2024-08-09 15:27:40 +07:00
};
2024-08-12 05:41:21 +07:00
outputs = { self, nixpkgs, crane }: let
gen = func: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] (system: func (import nixpkgs { inherit system; }));
in {
2024-08-09 15:27:40 +07:00
2024-08-12 05:41:21 +07:00
packages = gen (pkgs: rec {
bindings = pkgs.unbound-full.overrideAttrs (old: {
name = "unbound-dynmod-bindings.rs";
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.rust-bindgen pkgs.rustfmt ];
phases = ["unpackPhase" "patchPhase" "configurePhase" "installPhase"];
outputs = [ "out" ];
installPhase = ''
cp ${./dummy.h} ./dummy.h
2024-08-13 15:39:14 +07:00
opts=()
for file in **/*.h; do
opts+=(--allowlist-file "$PWD/$file")
done
bindgen --no-layout-tests "''${opts[@]}" dummy.h -- -I "$PWD" > "$out"
2024-08-12 05:41:21 +07:00
'';
});
unbound-mod = let
craneLib = crane.mkLib pkgs;
inherit (nixpkgs) lib;
in craneLib.buildPackage {
pname = "unbound-mod";
version = "0.1.0";
2024-08-13 15:39:14 +07:00
cargoExtraArgs = "--package example";
2024-08-12 05:41:21 +07:00
postPatch = ''
2024-08-13 15:39:14 +07:00
ls -la
cp ${bindings} unbound-mod/src/bindings.rs
2024-08-12 05:41:21 +07:00
'';
src = nixpkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type: lib.hasSuffix ".h" path || craneLib.filterCargoSources path type;
};
2024-08-13 15:39:14 +07:00
postInstall = ''
mv $out/lib/libexample.so $out/lib/libunbound_mod.so
'';
2024-08-12 05:41:21 +07:00
doCheck = false;
LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib";
2024-08-13 11:05:28 +07:00
LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libnftnl}/lib";
2024-08-12 05:41:21 +07:00
};
default = unbound-mod;
2024-08-09 15:27:40 +07:00
});
2024-08-12 05:41:21 +07:00
devShells = gen (pkgs: {
default = pkgs.mkShell rec {
name = "unbound-rust-mod-shell";
2024-08-12 11:24:01 +07:00
nativeBuildInputs = [
# pkgs.rustc pkgs.cargo
pkgs.nftables
];
2024-08-12 05:41:21 +07:00
LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib";
2024-08-13 11:05:28 +07:00
LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libnftnl}/lib";
2024-08-12 05:41:21 +07:00
LD_LIBRARY_PATH = "${LIBMNL_LIB_DIR}:${LIBNFTNL_LIB_DIR}";
};
});
2024-08-09 15:27:40 +07:00
};
}