Skip to content

Commit addf0d6

Browse files
committed
feat: inline Rizin Nix packages
1 parent 5510b68 commit addf0d6

11 files changed

Lines changed: 399 additions & 234 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,28 @@ rustPlatform.buildRustPackage {
3838
}
3939
```
4040

41+
## Nix packages
42+
43+
The flake provides both the Rust bindings and the pinned Rizin build:
44+
45+
```bash
46+
nix build .#rizin-rs
47+
nix build .#rizin
48+
```
49+
50+
Rizin is pinned to a specific commit from its `dev` branch. Update it to the
51+
latest `dev` revision, including the source and Meson dependency hashes, with:
52+
53+
```bash
54+
./nix/rizin/update.sh
55+
```
56+
57+
Pass a full 40-character commit SHA to pin a specific revision instead:
58+
59+
```bash
60+
./nix/rizin/update.sh <commit>
61+
```
62+
4163
## Usage
4264

4365
TODO

flake.lock

Lines changed: 4 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,42 @@
44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
66
flake-utils.url = "github:numtide/flake-utils";
7-
b = {
8-
url = "github:b1llow/nix";
9-
inputs.nixpkgs.follows = "nixpkgs";
10-
};
117
};
128

139
outputs =
1410
{
1511
self,
1612
nixpkgs,
1713
flake-utils,
18-
b,
1914
...
2015
}:
2116
flake-utils.lib.eachDefaultSystem (
2217
system:
2318
let
2419
pkgs = import nixpkgs { inherit system; };
2520
inherit (pkgs)
26-
lib
2721
nixfmt-tree
2822
rustPlatform
29-
pkg-config
3023
llvmPackages_18
3124
mkShell
3225
rust-analyzer
26+
rustfmt
3327
cargo-watch
3428
;
35-
bpkgs = b.packages.${system};
36-
inherit (bpkgs) rizin;
29+
30+
rizin = pkgs.callPackage ./nix/rizin { };
31+
rizin-rs = pkgs.callPackage ./nix/rizin-rs { inherit rizin; };
3732

3833
env = {
3934
LIBCLANG_PATH = "${llvmPackages_18.libclang.lib}/lib";
4035
};
41-
42-
rizin-rs = rustPlatform.buildRustPackage (
43-
env
44-
// rec {
45-
pname = "rizin-rs";
46-
version = "0.9.1";
47-
src = ./.;
48-
cargoLock.lockFile = ./Cargo.lock;
49-
50-
nativeBuildInputs = [
51-
rustPlatform.bindgenHook
52-
pkg-config
53-
];
54-
buildInputs = [
55-
rizin
56-
llvmPackages_18.libclang
57-
];
58-
59-
doCheck = true;
60-
61-
preConfigure = ''
62-
63-
'';
64-
}
65-
);
6636
in
6737
{
6838
formatter = nixfmt-tree;
6939

7040
packages = {
7141
default = rizin-rs;
72-
inherit rizin-rs;
42+
inherit rizin rizin-rs;
7343
};
7444

7545
devShells = {
@@ -92,6 +62,7 @@
9262
fmt = mkShell {
9363
packages = [
9464
rustPlatform.rust.cargo
65+
rustfmt
9566
];
9667
};
9768
};

nix/rizin-rs/default.nix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
llvmPackages_18,
3+
pkg-config,
4+
rizin,
5+
rustPlatform,
6+
}:
7+
8+
rustPlatform.buildRustPackage {
9+
pname = "rizin-rs";
10+
inherit (rizin) version;
11+
12+
src = ../..;
13+
cargoLock.lockFile = ../../Cargo.lock;
14+
15+
LIBCLANG_PATH = "${llvmPackages_18.libclang.lib}/lib";
16+
17+
nativeBuildInputs = [
18+
rustPlatform.bindgenHook
19+
pkg-config
20+
];
21+
buildInputs = [
22+
rizin
23+
llvmPackages_18.libclang
24+
];
25+
26+
doCheck = true;
27+
}

nix/rizin/checksum.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rev": "26362e8c1888d4fec5d87068c08f313251cc64e1",
3+
"srcHash": "sha256-CFDvgM4Ct5ZNsi/CnWxq9aOaAhklvkwZd8aupTLay2E=",
4+
"mesonDepsHash": "sha256-MYRYrrhWbQRkHaYfSAxPMnhqxFFSb5xAHirqP8Zy2AY="
5+
}

nix/rizin/default.nix

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
cacert,
3+
fetchFromGitHub,
4+
git,
5+
lib,
6+
makeSetupHook,
7+
meson,
8+
rizin,
9+
stdenvNoCC,
10+
}:
11+
12+
let
13+
checksums = builtins.fromJSON (builtins.readFile ./checksum.json);
14+
15+
src = fetchFromGitHub {
16+
owner = "rizinorg";
17+
repo = "rizin";
18+
rev = checksums.rev;
19+
hash = checksums.srcHash;
20+
};
21+
22+
mesonDeps = stdenvNoCC.mkDerivation {
23+
pname = "rizin-meson-deps";
24+
version = builtins.substring 0 12 checksums.rev;
25+
inherit src;
26+
27+
postUnpack = ''
28+
rm "$sourceRoot/subprojects/sigdb.wrap"
29+
'';
30+
31+
nativeBuildInputs = [
32+
cacert
33+
git
34+
meson
35+
];
36+
37+
buildPhase = ''
38+
runHook preBuild
39+
40+
meson subprojects download
41+
find subprojects -type d -name .git -prune -exec rm -rf {} +
42+
cp -r subprojects "$out"
43+
44+
runHook postBuild
45+
'';
46+
47+
phases = [
48+
"unpackPhase"
49+
"buildPhase"
50+
];
51+
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
52+
outputHashMode = "recursive";
53+
outputHashAlgo = "sha256";
54+
outputHash = checksums.mesonDepsHash;
55+
};
56+
57+
mesonDepsConfigHook = makeSetupHook {
58+
name = "rizin-meson-deps-config-hook";
59+
} ./meson-deps-config-hook.sh;
60+
in
61+
rizin.overrideAttrs (prevAttrs: {
62+
version = "unstable-${builtins.substring 0 12 checksums.rev}";
63+
inherit src mesonDeps;
64+
patches = builtins.filter (
65+
patch: builtins.baseNameOf patch != "0001-fix-compilation-with-clang.patch"
66+
) (prevAttrs.patches or [ ]);
67+
68+
mesonFlags = [
69+
"-Dportable=true"
70+
"-Dinstall_sigdb=false"
71+
];
72+
73+
nativeBuildInputs = (prevAttrs.nativeBuildInputs or [ ]) ++ [ mesonDepsConfigHook ];
74+
buildInputs = [ ];
75+
76+
# nixpkgs-update: no auto update
77+
passthru = {
78+
inherit mesonDeps;
79+
updateScript = ./update.sh;
80+
skipBulkUpdate = true;
81+
};
82+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# shellcheck shell=bash
2+
3+
mesonDepsConfigHook() {
4+
if [[ -z ${mesonDeps-} ]]; then
5+
echo "mesonDepsConfigHook: mesonDeps is not set" >&2
6+
return 1
7+
fi
8+
9+
rm -rf subprojects
10+
cp -r "$mesonDeps" subprojects
11+
chmod -R u+w subprojects
12+
}
13+
14+
preConfigureHooks+=(mesonDepsConfigHook)

0 commit comments

Comments
 (0)