haampie / libtree

ldd as a tree
MIT License
2.67k stars 60 forks source link

Add the ability to build with Nix #47

Closed fzakaria closed 2 years ago

fzakaria commented 2 years ago

Introduce a way to build libtree with Nix.

I see that the tool already has support for Spack, so Nix in theory is similar albeit more strict. I've included a default derivation that is pinned explicitly to all the required dependencies and commits.

strip and chrpath are also included and set to be runtime dependencies by wrapping the executable and prefixing the PATH environment variable.

❯ cat ./result/bin/libtree
#! /nix/store/l0wlqpbsvh1pgvhcdhw7qkka3d31si7k-bash-5.1-p8/bin/bash -e
export PATH=$PATH${PATH:+':'}'/nix/store/7z5ai3qarfa3xvw0rfpy9dnqqilwjppf-binutils-wrapper-2.35.2/bin:/nix/store/ycf9vgcgiin75cw9am4fz7qnp0iv1r1p-chrpath-0.16/bin'
exec -a "$0" "/nix/store/18qnx47mlcnjxf16w65sjj4vy47l89p8-libtree-2.0.0/bin/.libtree-wrapped"  "$@"

❯ ./result/bin/libtree /nix/store/2r14xjbp68pvsw44hj9xjy39vmid6vq4-ruby-2.7.4/bin/ruby
ruby
├── libruby-2.7.4.so.2.7 [runpath]
│   └── libcrypt.so.1 [runpath]
└── libcrypt.so.1 (collapsed) [runpath]

If you have Nix installed you can easily run it with:

nix run -f https://github.com/fzakaria/libtree/archive/faridzakaria/add-nix-build.tar.gz --command libtree
[1 built, 0.2 MiB DL]
Show the dependency tree of binaries and optionally bundle them into a single folder.
Usage:
  libtree [OPTION...] binary [more binaries...]

  -h, --help     Print usage
      --version  Print version info

We can also upstream this derivation to nixpkgs as well.

fzakaria commented 2 years ago

Rationale: if you visit https://repology.org/repositories/graphs you can see that nixpkgs is the largest and freshest package repository. It's goal is similar to Spack to provide reproducible hermetic builds and also provides a Linux distribution (NixOS) on the same concepts.

haampie commented 2 years ago

Thanks! I'll merge this, and then backport it to the release/2.0 branch