Share and install Nix flakes in offline Nix environments
Files
README.md

Nix-Cart #

nix-cart is a tool for exporting a Nix flake from one system and installing it as a part of your Nix profile on another system where you may not be able to use nix copy.

The following are expectations in a scenario where nix-cart may be useful:

  1. Nix flakes are going to be used on both the build and target systems
  2. The build system will run nix-cart to produce an archive
  3. The target system has an existing Nix installation

This tool is intended to be useful in airgapped Nix environments.

Installation #

nix profile add "git+https://tangled.org/heywoodlh.io/nix-cart"

This will add nix-cart to your $PATH.

Alternatively, invoke nix-cart as a flake:

nix run "git+https://tangled.org/heywoodlh.io/nix-cart"

Exporting a flake #

Exporting a flake will produce a tar.gz file with a closure and corresponding path for the closure.

nix-cart export "github:nixos/nixpkgs#hello" /tmp/hello.tar.gz

Installing an archive #

After exporting an archive, it may be installed on another system like so:

nix-cart import /tmp/hello.tar.gz

Alternatively, it can be done with the bundled installer script like this:

tar xzvf hello.tar.gz

./install.sh

Troubleshooting #

The --verbose flag must be the last argument

Run nix-cart with the --verbose (-v) flag to see more information on each step:

# Export archive
nix-cart export "github:nixos/nixpkgs#hello" /tmp/hello.tar.gz --verbose

# Import archive into nix
nix-cart import /tmp/hello.tar.gz --verbose