add nix package

This commit is contained in:
chayleaf 2024-08-12 05:41:21 +07:00
parent 0b6b49ddee
commit 3ff8bf71d5
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
2 changed files with 68 additions and 23 deletions

View file

@ -1,5 +1,25 @@
{ {
"nodes": { "nodes": {
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1722960479,
"narHash": "sha256-NhCkJJQhD5GUib8zN9JrmYGMwt4lCRp6ZVNzIiYCl0Y=",
"owner": "ipetkov",
"repo": "crane",
"rev": "4c6c77920b8d44cd6660c1621dea6b3fc4b4c4f4",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1723151029, "lastModified": 1723151029,
@ -18,6 +38,7 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"crane": "crane",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View file

@ -3,33 +3,57 @@
inputs = { inputs = {
nixpkgs.url = "github:chayleaf/nixpkgs/unbound"; nixpkgs.url = "github:chayleaf/nixpkgs/unbound";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
}; };
outputs = { self, nixpkgs }: { outputs = { self, nixpkgs, crane }: let
gen = func: nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] (system: func (import nixpkgs { inherit system; }));
in {
packages.x86_64-linux.bindings = let packages = gen (pkgs: rec {
pkgs = import nixpkgs { system = "x86_64-linux"; }; bindings = pkgs.unbound-full.overrideAttrs (old: {
in pkgs.unbound-full.overrideAttrs (old: { name = "unbound-dynmod-bindings.rs";
name = "unbound-dynmod-bindings.rs"; nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.rust-bindgen pkgs.rustfmt ];
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.rust-bindgen pkgs.rustfmt ]; phases = ["unpackPhase" "patchPhase" "configurePhase" "installPhase"];
phases = ["unpackPhase" "patchPhase" "configurePhase" "installPhase"]; outputs = [ "out" ];
outputs = [ "out" ]; installPhase = ''
installPhase = '' cp ${./dummy.h} ./dummy.h
cp ${./dummy.h} ./dummy.h bindgen ./dummy.h -- -I $PWD > $out
bindgen ./dummy.h -- -I $PWD > $out '';
''; });
unbound-mod = let
craneLib = crane.mkLib pkgs;
inherit (nixpkgs) lib;
in craneLib.buildPackage {
pname = "unbound-mod";
version = "0.1.0";
postPatch = ''
cp ${bindings} src/bindings.rs
'';
src = nixpkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type: lib.hasSuffix ".h" path || craneLib.filterCargoSources path type;
};
doCheck = false;
LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib";
LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib (pkgs.libnftnl.overrideAttrs (old: {
patches = (old.patches or []) ++ [ ./libnftnl-fix.patch ];
}))}/lib";
};
default = unbound-mod;
}); });
devShells.x86_64-linux.default = let devShells = gen (pkgs: {
pkgs = import nixpkgs { system = "x86_64-linux"; }; default = pkgs.mkShell rec {
in pkgs.mkShell rec { name = "unbound-rust-mod-shell";
name = "unbound-rust-mod-shell"; nativeBuildInputs = [ pkgs.rustc pkgs.cargo pkgs.nftables ];
nativeBuildInputs = [ pkgs.rustc pkgs.cargo pkgs.nftables ]; LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib";
LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib"; LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib (pkgs.libnftnl.overrideAttrs (old: {
LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib (pkgs.libnftnl.overrideAttrs (old: { patches = (old.patches or []) ++ [ ./libnftnl-fix.patch ];
patches = (old.patches or []) ++ [ ./libnftnl-fix.patch ]; }))}/lib";
}))}/lib"; LD_LIBRARY_PATH = "${LIBMNL_LIB_DIR}:${LIBNFTNL_LIB_DIR}";
LD_LIBRARY_PATH = "${LIBMNL_LIB_DIR}:${LIBNFTNL_LIB_DIR}"; };
}; });
}; };
} }