All Projects â†’ matthewbauer â†’ Nix Bundle

matthewbauer / Nix Bundle

Licence: mit
Bundle Nix derivations to run anywhere!

Labels

Projects that are alternatives of or similar to Nix Bundle

dotfiles
My NixOS dotfiles
Stars: ✭ 21 (-93.05%)
Mutual labels:  nix
dconf2nix
🐾 Convert Dconf files (e.g. Gnome Shell) to Nix, as expected by Home Manager
Stars: ✭ 51 (-83.11%)
Mutual labels:  nix
Not Os
An operating system generator, based on NixOS, that, given a config, outputs a small (47 MB), read-only squashfs for a runit-based operating system, with support for iPXE and signed boot.
Stars: ✭ 280 (-7.28%)
Mutual labels:  nix
dotnix
Shackled within an elaborate prison of my own design.
Stars: ✭ 35 (-88.41%)
Mutual labels:  nix
bigdata-fun
A complete (distributed) BigData stack, running in containers
Stars: ✭ 14 (-95.36%)
Mutual labels:  nix
nixcfg
NixOS and Home-Manager configurations for all of my devices (desktop, Pinebook Pro, RPi4, cloud servers, etc). Like dotfiles, but way better. (nÊe 'nixos-config')
Stars: ✭ 119 (-60.6%)
Mutual labels:  nix
microvm.nix
NixOS MicroVMs
Stars: ✭ 136 (-54.97%)
Mutual labels:  nix
Mobile Nixos
Questions? #nixos-aarch64 (or #nixos) on Freenode!
Stars: ✭ 291 (-3.64%)
Mutual labels:  nix
nixpkgs
My Nix system configs!
Stars: ✭ 143 (-52.65%)
Mutual labels:  nix
Nix Docker
Provision Docker images using Nix
Stars: ✭ 274 (-9.27%)
Mutual labels:  nix
system
Declarative NixOS system configuration for all my machines
Stars: ✭ 14 (-95.36%)
Mutual labels:  nix
nix-cookbook
A cookbook of snippets that show you how you can accomplish common tasks using the Nix expression language
Stars: ✭ 73 (-75.83%)
Mutual labels:  nix
go2nix
Reproducible builds and development environment for Go
Stars: ✭ 88 (-70.86%)
Mutual labels:  nix
elinter
Nix-based CI and local testing framework for Emacs Lisp projects
Stars: ✭ 19 (-93.71%)
Mutual labels:  nix
Haskell.nix
Alternative Haskell Infrastructure for Nixpkgs
Stars: ✭ 283 (-6.29%)
Mutual labels:  nix
nixexprs
nix stuff
Stars: ✭ 13 (-95.7%)
Mutual labels:  nix
tix
[WIP] A type system for nix
Stars: ✭ 59 (-80.46%)
Mutual labels:  nix
Nix.dev
An opinionated guide for developers wanting to get things done with Nix.
Stars: ✭ 300 (-0.66%)
Mutual labels:  nix
Nixpkgs Mozilla
mozilla related nixpkgs (extends nixos/nixpkgs repo)
Stars: ✭ 288 (-4.64%)
Mutual labels:  nix
Node2nix
Generate Nix expressions to build NPM packages
Stars: ✭ 258 (-14.57%)
Mutual labels:  nix

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].