Skip to content

Commit aa385c9

Browse files
committed
bonsai: refactor derivation
1. Remove `rec` keyword in favor of passing a function to `stdenv.mkDerivation`; 2. Reorder attributes; 3. Put build only dependencies --- Hare's third party libraries --- into `nativeBuildInputs`; 4. Remove `preConfigure` hook in favor of setting the `HARECACHE` make variable; 5. Use `stdenv.hostPlatform.uname.processor` for setting the architecture needed for cross-compilation; 6. Substitute in place the `HAREFLAGS` make variable instead of the `-a` flag directly, which is now set on the make variable (this should be submitted upstream, since the make variable, as of now, does absolutely nothing); 8. Pass the `-q` flag to `HAREFLAGS` to avoid polluting the logs when hare is either being called with `test` or `build`; 9. Remove deprecated `agpl3` license in favor of `agpl3Plus`; 10. Add `bonsaictl` as `meta.mainProgram`; and 11. Enable parallel building.
1 parent 2b5ceb2 commit aa385c9

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

pkgs/by-name/bo/bonsai/package.nix

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,49 @@
66
, hareThirdParty
77
}:
88

9-
stdenv.mkDerivation rec {
9+
stdenv.mkDerivation (finalAttrs: {
1010
pname = "bonsai";
1111
version = "1.0.2";
1212

1313
src = fetchFromSourcehut {
1414
owner = "~stacyharper";
1515
repo = "bonsai";
16-
rev = "v${version}";
16+
rev = "v${finalAttrs.version}";
1717
hash = "sha256-Yosf07KUOQv4O5111tLGgI270g0KVGwzdTPtPOsTcP8=";
1818
};
1919

20-
postPatch = ''
21-
substituteInPlace Makefile \
22-
--replace 'hare build' 'hare build $(HARE_TARGET_FLAGS)'
23-
'';
24-
2520
nativeBuildInputs = [
2621
hare
22+
hareThirdParty.hare-ev
23+
hareThirdParty.hare-json
2724
];
2825

29-
buildInputs = with hareThirdParty; [
30-
hare-ev
31-
hare-json
26+
makeFlags = [
27+
"PREFIX=${builtins.placeholder "out"}"
28+
"HARECACHE=.harecache"
29+
"HAREFLAGS=-qa${stdenv.hostPlatform.uname.processor}"
3230
];
3331

34-
env.HARE_TARGET_FLAGS =
35-
if stdenv.hostPlatform.isAarch64 then
36-
"-a aarch64"
37-
else if stdenv.hostPlatform.isRiscV64 then
38-
"-a riscv64"
39-
else if stdenv.hostPlatform.isx86_64 then
40-
"-a x86_64"
41-
else
42-
"";
43-
# TODO: hare setup-hook is supposed to do this for us.
44-
# It does it correctly for native compilation, but not cross compilation: wrong offset?
45-
env.HAREPATH = with hareThirdParty; "${hare-json}/src/hare/third-party:${hare-ev}/src/hare/third-party";
46-
47-
preConfigure = ''
48-
export HARECACHE=$(mktemp -d)
49-
'';
50-
51-
installFlags = [ "PREFIX=$(out)" ];
32+
enableParallelBuilding = true;
5233

5334
doCheck = true;
5435

36+
postPatch = ''
37+
substituteInPlace Makefile \
38+
--replace 'hare build' 'hare build $(HAREFLAGS)' \
39+
--replace 'hare test' 'hare test $(HAREFLAGS)'
40+
'';
41+
5542
passthru.updateScript = gitUpdater {
5643
rev-prefix = "v";
5744
};
5845

5946
meta = with lib; {
6047
description = "Finite State Machine structured as a tree";
6148
homepage = "https://git.sr.ht/~stacyharper/bonsai";
62-
license = licenses.agpl3;
49+
license = licenses.agpl3Plus;
6350
maintainers = with maintainers; [ colinsane ];
6451
platforms = platforms.linux;
52+
mainProgram = "bonsaictl";
6553
};
66-
}
54+
})

0 commit comments

Comments
 (0)