How to manually install runtime dependencies?

Current I am trying build snap for yazi, a terminal file manager.

Some of its features rely on fd-find, ripgrep, zoxide, fzf, and the packages in the official repository of core22 is too old.

So I need to manually install these runtime dependencies:

cargo install fd-find
cargo install ripgrep
cargo install zoxide
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install --bin

But I don’t know which step should I place these commands and how to organize all these files properly.

If your snap is strict confined, then you’d need to include these additional tools within your own snap. You could either install them via stage-packages if they’re in the Ubuntu archive, or build them as extra parts in your snap.

If you’re building a classic snap, you could still bundle the tools, or rely on the user installing the tools themselves. There’s not really an option to trigger installing other packages here.

As I said the packages in current Ubuntu archive is too old to function properly. So I can’t use stage-packages or rely on the user installing.

Also I don’t really want to build all these packages.

Is it possible manually install these packages to the stage or prime folder, so that they can be bundled in the the final snap?

yes, you can always just use override-* statements to run any script or code during build to achieve this …

i.e. I would put your above code into an override-build: block in the part where you build the application like:

    build-packages:
      - cargo
      - ... whatever else you need as build packages ...
    override-build: |
      cargo install fd-find
      cargo install ripgrep
      cargo install zoxide
      git clone --depth 1 https://github.com/junegunn/fzf.git fzf
      fzf/install --bin
      craftctl default

note that this last command seems to call some script that will likely try to install stuff to /bin, you might want to take a deeper look at this script to make sure things end up in $CRAFT_PART_INSTALL/bin instead … perhaps you need to patch it

1 Like

@ogra Thanks a lot! I don’t know craftctl default before.

I managed bundle all dependencies with the following code:

apps:
  yazi:
    command: yazi
    environment:
      PATH: $SNAP/bin:$PATH

parts:
  yazi:
    plugin: rust
    source: .
    override-build: |
      craftctl default
      cargo install fd-find --root $CRAFT_PART_INSTALL
      cargo install ripgrep --root $CRAFT_PART_INSTALL
      cargo install zoxide --root $CRAFT_PART_INSTALL
      git clone --depth 1 https://github.com/junegunn/fzf.git fzf
      fzf/install --bin && mv fzf/bin/fzf $CRAFT_PART_INSTALL/bin/

Since all things go to $CRAFT_PART_INSTALL after build (and install), so I just install all the packages to this folder.

One thing to be care with is the PATH value has to be changed in classic confinement mode to include all these dependencies.