Skip to content

Commit e32fdb3

Browse files
authored
Support embedded nix builds (#2736)
This adds support for building bpftrace as an appimage. See the documentation update in nix.md in the commit for usage. This is intended to replace the current semi-static embedded build. This approach has both pros and cons over the semi-static embedded build. For one, the appimage is actually fully static (as it bundles the necesssary libc). So it's more likely to work on more systems. The downside is that the appimage is a ~10x larger binary than the semi-static binary. The appimage also requires fuse to work (which most systems should support). It's takes ~1s longer to start up which I don't think is a huge deal. This closes #2721.
1 parent f7ae0c3 commit e32fdb3

File tree

3 files changed

+109
-7
lines changed

3 files changed

+109
-7
lines changed

docs/nix.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ $ sudo ./result/bin/bpftrace --info 2>&1 | grep LLVM
4646
LLVM: 13.0.1
4747
```
4848

49+
### Build bpftrace as a statically linked binary
50+
51+
```
52+
$ nix build .#appimage
53+
$ ldd ./result
54+
not a dynamic executable
55+
$ sudo ./result -e 'BEGIN { print("static!"); exit() }'
56+
Attaching 1 probe...
57+
static!
58+
```
59+
4960
### Don't use Nix to build, but rather only manage dependencies
5061

5162
```

flake.lock

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

flake.nix

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,16 @@
44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
66
flake-utils.url = "github:numtide/flake-utils";
7+
nix-appimage = {
8+
# Use fork until https://github.com/ralismark/nix-appimage/pull/8 is in
9+
url = "github:danobi/nix-appimage/5d5093111a1ec4f116c1c57b7a807d41404bfa5e";
10+
# Avoid multiple copies of the same dependency
11+
inputs.nixpkgs.follows = "nixpkgs";
12+
inputs.flake-utils.follows = "flake-utils";
13+
};
714
};
815

9-
outputs = { self, nixpkgs, flake-utils, ... }:
16+
outputs = { self, nixpkgs, flake-utils, nix-appimage, ... }:
1017
# This flake only supports 64-bit linux systems.
1118
# Note bpftrace support aarch32 but for simplicity we'll omit it for now.
1219
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ]
@@ -127,6 +134,14 @@
127134
bpftrace-llvm12 = mkBpftrace pkgs.llvmPackages_12;
128135
bpftrace-llvm11 = mkBpftrace pkgs.llvmPackages_11;
129136
bpftrace-llvm10 = mkBpftrace pkgs.llvmPackages_10;
137+
138+
# Self-contained static binary with all dependencies
139+
appimage = nix-appimage.mkappimage.${system} {
140+
drv = default;
141+
entrypoint = pkgs.lib.getExe default;
142+
name = default.name;
143+
};
144+
130145
};
131146

132147
# Define apps that can be run with `nix run`

0 commit comments

Comments
 (0)