Run unpatched binaries on Nix/NixOS

Overview

nix-alien

ci

Introduction

You are running nix/NixOS and have ever encountered the following problem?

$ ./bb
bash: ./bb: No such file or directory

Fear not, now there is nix-alien which will download necessary dependencies for you.

$ ./nix-alien bb            --> Run the binary inside a FHS shell with all needed shared dependencies to execute the binary
$ ./nix-alien-ld bb         --> 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 bb  --> Lists all libs needed for the binary

Usage (Flakes)

Assuming you have nix already installed:

$ nix-shell -p nixUnstable nix-index
$ nix-index # this will take a long time
$ nix run --experimental-features 'nix-command flakes' "github:thiagokokada/nix-alien" -- ~/myapp

This 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/ /default.nix , making the next evaluation faster. You can also pass --recreate flag to force the recreation of default.nix file

You can edit your /etc/nix/nix.conf or ~/.config/nix/nix.conf file and add the following line to avoid having to pass --experimental-features flag every time:

experimental-features = nix-command flakes

From here on this guide will assume the above configuration is done for brevity.

In case you're using nix-ld, there is also nix-alien-ld:

$ nix run "github:thiagokokada/nix-alien#nix-alien-ld" -- ~/myapp 

This will spawn a mkShell instead with NIX_LD_LIBRARY_PATH and NIX_LD setup. The resulting shell.nix file will be saved to $XDG_CACHE_HOME/nix-alien/ /shell.nix , making the next evaluation faster. You can also pass --recreate flag to force the recreation of shell.nix file

If you want to use the fzf based menu to find the libraries for scripting purposes, you can run:

$ nix run "github:thiagokokada/nix-alien#nix-alien-find-libs" -- ~/myapp 

This 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.

To avoid the slow startup of nix-index, you can also download a pre-computed index from nix-index-database:

$ nix run "github:thiagokokada/nix-alien#nix-index-update"

Usage (non-Flakes)

$ $(nix-build default.nix --no-out-link)/bin/nix-alien
$ $(nix-build default.nix --no-out-link)/bin/nix-alien-ld
$ $(nix-build default.nix --no-out-link)/bin/nix-alien-find-libs
$ $(nix-build nix-index-update.nix --no-out-link)/bin/nix-index-update

Limitations

Binaries loading shared libraries dynamically (e.g.: with dlopen) will probably not work with this script. However, this script can still be useful to create an initial default.nix or shell.nix, that can be populated later with the runtime dependencies of the program.

Technical Description

This Python program allows you to download ELF binaries and use them right away! This is achieved by enumerating the shared library dependencies from the ELF header and then searching for the equivalent library in nixpkgs. This is done by querying nix-locate locally.

To be able to use nix-locate, first, the index has to be build. This is done by running nix-index and waiting 10-15 minutes. To speed-up this process, this repo also includes nix-index-update script, that downloads the index from nix-index-database.

Credits

Owner
Thiago Kenji Okada
Software Engineer at @nubank, Linux enthusiast, Anime fan and geek.
Thiago Kenji Okada
Demo repository for Saltconf21 talk - Testing strategies for Salt states

Saltconf21 testing strategies Demonstration repository for my Saltconf21 talk "Strategies for testing Salt states" Talk recording Slides and demos Get

Barney Sowood 3 Mar 31, 2022
A male and female dog names python package

A male and female dog names python package

Fayas Noushad 3 Dec 12, 2021
A quick experiment to demonstrate Metamath formula parsing, where the grammar is embedded in a few additional 'syntax axioms'.

Warning: Hacked-up code ahead. (But it seems to work...) What it does This demonstrates an idea which I posted about several times on the Metamath mai

Marnix Klooster 1 Oct 21, 2021
Write Streamlit apps using Notion! (Prototype)

Streamlit + Notion test app Write Streamlit apps using Notion! ☠️ IMPORTANT: This is just a little prototype I made to play with some ideas. Not meant

Thiago Teixeira 22 Sep 08, 2022
Sequence clustering and database creation using mmseqs, from local fasta files

Sequence clustering and database creation using mmseqs, from local fasta files

Ana Julia Velez Rueda 3 Oct 27, 2022
Meliodas Official 1.4 BombSquad Server Scripts

Noxious-Official-1.4-BombSquad-Server-Scripts Scripts Are Provided By Sparxtn Somewhat Edited By Me Scripts are Working Fine Just Download & Use It Be

Meliodas♡ 2 Oct 16, 2022
A reproduction repo for a Scheduling bug in AirFlow 2.2.3

A reproduction repo for a Scheduling bug in AirFlow 2.2.3

Ilya Strelnikov 1 Feb 09, 2022
script to analyze EQ decay using python

pyq_decay script to analyze EQ decay using python PyQ Decay ver 1.0 A pythonic script to analyze EQ aftershock decay using method of Omori (1894), Mog

1 Nov 04, 2021
Code for Crowd counting via unsupervised cross-domain feature adaptation.

CDFA-pytorch Code for Unsupervised crowd counting via cross-domain feature adaptation. Pre-trained models Google Drive Baidu Cloud : t4qc Environment

Guanchen Ding 6 Dec 11, 2022
A script to generate NFT art living on the Solana blockchain.

NFT Generator This script generates NFT art based on its desired traits with their specific rarities. It has been used to generate the full collection

Rude Golems 24 Oct 08, 2022
A lightweight solution for local Particle development.

neopo A lightweight solution for local Particle development. Features Builds Particle projects locally without any overhead. Compatible with Particle

Nathan Robinson 19 Jan 01, 2023
CEI Natural Disaster Tracking Portal

CEI Natural Disaster Tracking Portal (cc) Climatic Eye of ISCI We are an initiative that conducts studies in the field of Space Science, publishes pro

Baris Dincer 7 Dec 24, 2022
A python script to get your activity

activities A python script to get your activity Not complete Requirements Python (=3.7) Pip (for python = 3.7) Git Pip packages psutil asyncio aioht

StarNumber 3 Nov 07, 2021
Swubcase - The shitty programming language

What is Swubcase? Swubcase is easy-to-use programming language that can fuck you

5 Jun 19, 2022
A web application (with multiple API project options) that uses MariaDB HTAP!

Bookings Bookings is a web application that, backed by the power of the MariaDB Connectors and the MariaDB X4 Platform, unleashes the power of smart t

MariaDB Corporation 4 Dec 28, 2022
Cloud-native SIEM for intelligent security analytics for your entire enterprise.

Microsoft Sentinel Welcome to the Microsoft Sentinel repository! This repository contains out of the box detections, exploration queries, hunting quer

Microsoft Azure 2.9k Jan 02, 2023
A ULauncher/Albert extension that supports currency, units and date time conversion, as well as a calculator that supports complex numbers and functions.

Ulauncher/Albert Calculate Anything Ulauncher/Albert Calculate Anything is an extension for Ulauncher and Albert to calculate things like currency, ti

tchar 67 Jan 01, 2023
Pomodoro timer by the Algodrip team!

PomoDrip 🍅 Pomodoro timer by the Algo Drip team! To-do: Create the script for the pomodoro timer Design the front-end of the program (Flask or Javasc

Algodrip 3 Sep 12, 2021
An easy python calculator for those who want's to know how if statements, loops, and imports works give it a try!

A usefull calculator for any student or anyone who want's to know how to build a simple 2 mode python based calculator.

Antonio Sánchez 1 Jan 06, 2022
An alternative app for core Armoury Crate functions.

NoROG DISCLAIMER: Use at your own risk. This is alpha-quality software. It has not been extensively tested, though I personally run it daily on my lap

12 Nov 29, 2022