Nix equivalent of guix pack --relocatable

Is there a Nix version of

guix pack --relocatable

as shown in this blog post about tarballs as containers?

In the end I would like to be able to have an app (or collection of apps) in a directory with all of its dependencies—a trimmed down store, just for that app, I guess—that is relocatable; that I can copy to an arbitrary location on another system where I do not have admin, no Docker, no Singularity, no Nix, … and I can still run the app out of the directory that I’ve copied over. Also, the target system is probably very out-of-date with respect to its kernel, …

I’m currently building my project, for work, using nix-shell --pure, and it is working very well. I hope to transition to actually making a Nix package and being able to distribute it as described above.

3 Likes

I don’t know what guix pack --relocatable does, but, sounds a bit like GitHub - matthewbauer/nix-bundle: Bundle Nix derivations to run anywhere!

3 Likes

That looks really good! I’ll see if I can figure it out.

The only thing missing from my wishlist is the ability to pack up multiple apps. For example, pack up emacs, julia, git, …, and be able to use them out of the same package. Hopefully, they would share enough dependencies that packaging them together would save tons of space.

Looks like you could create a simple shell script with writeShellScriptBin that has the packages that you want to bundle as dependencies and runs them based on the command line arguments. The derivation would look something like

{ writeShellScriptBin, emacs, julia, git }:

writeShellScriptBin "run" { } ''
  case "$1" in
  emacs) prog="${emacs}/bin/emacs"; shift 1;;
  julia) prog="${julia}/bin/julia"; shift 1;;
  # etc.
  esac

  exec "$prog" "$@"
''

Then you could bundle it by running nix-bundle.sh run /bin/run.

PS I haven’t tested any of this…

1 Like

Pretty cool!

Now I just have to learn Nix; I’m only as far as basic package management and nix-shell/shell.nix. I really need to learn how to write derivations generally, and for my projects in particular. Off to read Nix Pills and nix.dev …

nix-bundle requires the target system to have user namespace support, so it wouldn’t work with older kernels, but it would appear that guix pack --relocatable has the same limitation… I’m guessing it’s even implemented the same way.

3 Likes

So… I was able to use nix-bundle to bundle up emacs and take it to another system without Nix. It ran great, BUT the process does not see any files on the host system—not to mention not finding my ~/.emacs.d/init.el—which is kinda the point of an editor, making emacs useless.

My other use case for nix-bundle would be to bundle science/math code to run on HPC systems. Like an editor, it would require read/write access to host filesystems, nix-bundle would not help much.

It seems like there must be a way to get bundled apps to “see” the host filesystem transparently. When I tried out the Guix bundle system, the app, emacs, found my init.el and could read/write any files on the host.

Am I missing something with nix-bundle? Is there a way to get the apps to have access to the host filesystems?