Nix Alien
You are running nix/NixOS and have ever encountered the following problem?
$ ./myapp
bash: ./myapp: No such file or directory
Fear not, now there is nix-alien which will download necessary dependencies for you.
$ nix-alien myapp # Run the binary inside a FHS shell with all needed shared dependencies to execute the binary
$ nix-alien-ld myapp # Spawns you inside a shell with NIX_LD_LIBRARY_PATH set to the needed dependencies, to be used with nix-ld
$ nix-alien-find-libs myapp # Lists all libs needed for the binaryUsage
Once nix-alien is installed in your system, all you need to do is run:
$ nix-alien ~/myappThis will run nix-alien on ~/myapp binary with a FHSUserEnv including all shared library dependencies. The resulting default.nix file will be saved to $XDG_CACHE_HOME/nix-alien/<path-uuid>/fhs-env/default.nix, making the next evaluation faster. The cache is based on the binary absolute path. You can also pass --recreate flag to force the recreation of default.nix file, and --destination to change where default.nix file will be saved.
To pass arguments to the app:
$ nix-alien ~/myapp -- --foo barIn case you’re using nix-ld, there is also nix-alien-ld:
$ nix-alien-ld -- ~/myappThis will spawn a wrapped binary with NIX_LD_LIBRARY_PATH and NIX_LD setup. The resulting default.nix file will be saved to $XDG_CACHE_HOME/nix-alien/<path-uuid>/nix-ld/default.nix, making the next evaluation faster. The cache is based on the binary absolute path. You can also pass --recreate flag to force the recreation of default.nix file, and --destination to change where default.nix file will be saved.
To pass arguments to the app:
$ nix-alien-ld ~/myapp -- --foo barIf you want to use the fzf based menu to find the libraries for scripting purposes, you can run:
$ nix-alien-find-libs ~/myappThis will print the found libraries on the stdout. The informational messages are printed to stderr, so you can easily redirect them to /dev/null if needed. You can also use --json flag to print the result as a JSON instead.
There are also some other options, check them using --help flag on each program. Example for nix-alien:
usage: nix-alien [-h] [--version] [-l LIBRARY] [-p PACKAGE] [-c CANDIDATE] [-r] [-d PATH] [-P] [-E] [-s] [-f] program ...
positional arguments:
program Program to run
ellipsis Arguments to be passed to the program
options:
-h, --help show this help message and exit
--version show program's version number and exit
-l LIBRARY, --additional-libs LIBRARY
Additional library to search. May be passed multiple times
-p PACKAGE, --additional-packages PACKAGE
Additional package to add. May be passed multiple times
-c CANDIDATE, --select-candidates CANDIDATE
Library candidates that will be auto-selected if found via regex. Useful for automation.
-r, --recreate Recreate 'default.nix' file if exists
-d PATH, --destination PATH
Path where 'default.nix' file will be created
-P, --print-destination
Print where 'default.nix' file is located and exit
-E, --edit Edit 'default.nix' using $EDITOR (or 'nano' if unset)
-s, --silent Silence informational messages
-f, --flake Create and use 'flake.nix' file instead (experimental)