• Stars
    star
    593
  • Rank 72,647 (Top 2 %)
  • Language
    Nix
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bundle Nix derivations to run anywhere!

nix-bundle

nix-bundle is a way to package Nix attributes into single-file executables.

Benefits

  • Single-file output
  • Can be run by non-root users
  • No runtime
  • Distro agnostic
  • No installation

Getting started

Make sure you have installed Nix already. See http://nixos.org/nix/ for more details.

Once you have a working Nix install, you can run:

$ ./nix-bundle.sh hello /bin/hello

hello indicates the Nix derivation from NixPkgs that you want to use, while /bin/hello indicates the path of the executable relative to hello that you want to run. This will create the file "hello". Running it:

$ ./hello
Hello, world!

This is a standalone file that is completely portable! As long as you are running the same architecture Linux kernel and have a shell interpreter available it will run.

Some others to try:

./nix-bundle.sh nano /bin/nano
./nix-bundle.sh emacs /bin/emacs

Or if you want to try graphical applications:

# Simple X game. Very few dependencies. Quick to build and load. ~13MB
./nix-bundle.sh xskat /bin/xskat
./nix-bundle.sh firefox /bin/firefox
# SDL-based game. ~228MB
./nix-bundle.sh ivan /bin/ivan

Self-bundling (meta)

Starting with v0.1.3, you can bundle nix-bundle! To do this, just use nix-bundle normally:

NIX_PATH="nixpkgs=https://github.com/matthewbauer/nixpkgs/archive/nix-bundle.tar.gz" ./nix-bundle.sh nix-bundle /bin/nix-bundle

[Experimental] Create AppImage executables from Nix expressions

"nix-bundle.sh" tends to create fairly large outputs. This is largely because nix-bundle.sh "extracts" its payload up front. AppImage uses a different method where extraction only takes place when the file is accessed (through FUSE and SquashFS). You can now create a compliant "AppImage" using the "nix2appimage.sh" script:

./nix2appimage.sh emacs

This will create a file at Emacs-x86_64.AppImage which you can execute.

Notice that there is only one argument for nix2appimage.sh. This is because the target executable will be detected from the .desktop file in /share/applications/*.desktop. As a side-effect, AppImage requires your package to have a .desktop file, so packages like "hello", "coreutils", etc. will not work.

Some other examples to try:

./nix2appimage.sh firefox
./nix2appimage.sh vlc
./nix2appimage.sh 0ad
./nix2appimage.sh wireshark-gtk

These may take a while because of the large closure size.

Note that these do not currently work out of the box with NixOS. Other Linux distros should work.

Comparison with AppImage, FlatPak, Snappy

Name Distro-agnostic Runtime required Root required Storage
nix-bundle yes no no Arx tarball
AppImage yes no no Squashfs w/ lzma compression
FlatPak yes yes no ?
Snappy yes yes no squashFS

How it works

Nix-bundle glues together four different projects to work correctly:

  • Arx - an archive execution tool
  • Creates single-file archive executable that can unpack themselves and then run some command. nix-bundle calls nix-user-chroot to bootstrap the Nix environment. It outputs a "./nix" folder.
  • nix-user-chroot - a small bootstrap that uses Linux namespaces to call chroot
    • This will create sub namespace and bind mount the "./nix" to "/nix" so that the Nix references function properly.
  • Nix - a functional package manager
    • Used to build runtime closures that are self-contained.
  • nixpkgs
    • Provides lots of different packages to choose from.

Drawbacks

Nix-bundle has some drawbacks that need to be worked on:

  • Slow startup
  • Large files (Firefox 150MB)
  • Only compatible Linux
  • Outputs built on x86-64 will not run on i386
  • Requires Linux kernel with CAP_SYS_USER_NS on and permissions setup correctly

More Repositories

1

bauer

An Emacs+Nix IDE
Emacs Lisp
107
star
2

nixiosk

Declarative Kiosk systems built with NixOS
Nix
106
star
3

ghc-nix

Exploring the options for incremental Haskell builds using Nix
Haskell
105
star
4

gametime-player

A super simple JS-based libretro frontend
CoffeeScript
38
star
5

unipkg

Create a package for different distros using a single PKGBUILD file (unmaintained)
Shell
31
star
6

undmg

extract a dmg file
C
26
star
7

nix-haskell-mode

Automatic Haskell setup in Emacs, for Nix users
Emacs Lisp
25
star
8

rivulet

a simple, fast, open source RSS reader
Go
21
star
9

reddwall

Change your background to a random wallpaper on Reddit.
Python
20
star
10

resume

my rΓ©sumΓ©
TeX
19
star
11

retrojs

Libretro emulator cores compiled into modular JavaScript.
JavaScript
17
star
12

eu4-parser

some tools to parse files from the clausewitz engine
Haskell
14
star
13

static-nix

Statically built Nix binaries
Nix
14
star
14

nixos-kiosk

NixOS kiosk using Cage
Nix
10
star
15

caldav-to-gtasks

A caldav server that writes directly to Google Tasks
Python
9
star
16

uzbl-os

A Uzbl based distro, similar to Google Chrome OS
Python
8
star
17

libmii

Wii homebrew library for Miis
C
7
star
18

macNixOS

a set of useful things for running Nix on macOS
Shell
4
star
19

x-retro

<x-retro></x-retro>
CoffeeScript
4
star
20

uzbl-extension-manager

A simple extension manager for Uzbl
Shell
4
star
21

metapkgs

A set of package sets
Nix
4
star
22

gpemu2

libretro frontend written in Haskell and Reflex
Haskell
3
star
23

make-package

Nix
3
star
24

counter

Counter app for the Pebble watch
C
3
star
25

xilium.cefglue

GitHub mirror of xilium.cefglue
C#
3
star
26

matthewbauer.github.io

My personal site
Shell
2
star
27

unipkg-pacman

C
2
star
28

nur-packages

Nix
2
star
29

denali

Denali Linux - NixOS for humans
Nix
2
star
30

node-retro

THIS REPO IS DEPRECATED!!! Use retrojs instead.
C
2
star
31

auto-update-flake

GitHub Action to automatically update flake inputs if they pass CI
2
star
32

todo.txt-gtk

Graphical User Interface for todo.txt in Python
Python
2
star
33

65536

CSS
1
star
34

vector-algorithms

Haskell
1
star
35

skeleton

Haskell
1
star
36

exdongle

provides 'AutoRun' capabilities to Linux systems (based on a script by Gogodidi)
1
star
37

xib2nib

C++
1
star
38

hangman

Really hard hangman game in HTML and Javascript
JavaScript
1
star
39

snes-info

command line tool to get information on the header of SNES .SMC files
Go
1
star
40

hbb-medawiki

Homebrew Browser Mediawiki extensions to allow repository editing from a wiki
PHP
1
star
41

dot-emacs

Emacs Lisp
1
star
42

jaycal

Automagically generate a calendar using your university account.
JavaScript
1
star