Home Explore Blog Models CI



nix

1st chunk of `src/libstore/local-store.md`
f428c3791c89bedf157ad0ca7a2f1f6915d4a87cc8e7319c0000000100000605
R"(

**Store URL format**: `local`, *root*

This store type accesses a Nix store in the local filesystem directly
(i.e. not via the Nix daemon). *root* is an absolute path that is
prefixed to other directories such as the Nix store directory. The
store pseudo-URL `local` denotes a store that uses `/` as its root
directory.

A store that uses a *root* other than `/` is called a *chroot
store*. With such stores, the store directory is "logically" still
`/nix/store`, so programs stored in them can only be built and
executed by `chroot`-ing into *root*. Chroot stores only support
building and running on Linux when [`mount namespaces`](https://man7.org/linux/man-pages/man7/mount_namespaces.7.html) and [`user namespaces`](https://man7.org/linux/man-pages/man7/user_namespaces.7.html) are
enabled.

For example, the following uses `/tmp/root` as the chroot environment
to build or download `nixpkgs#hello` and then execute it:

```console
# nix run --store /tmp/root nixpkgs#hello
Hello, world!
```

Here, the "physical" store location is `/tmp/root/nix/store`, and
Nix's store metadata is in `/tmp/root/nix/var/nix/db`.

It is also possible, but not recommended, to change the "logical"
location of the Nix store from its default of `/nix/store`. This makes
it impossible to use default substituters such as
`https://cache.nixos.org/`, and thus you may have to build everything
locally. Here is an example:

```console
# nix build --store 'local?store=/tmp/my-nix/store&state=/tmp/my-nix/state&log=/tmp/my-nix/log' nixpkgs#hello
```

)"

Title: Nix Store URL Format: Local and Chroot Stores
Summary
This document describes the `local` Nix store URL format, which allows direct access to a Nix store in the local filesystem without using the Nix daemon. The `local` format can take an optional `root` path; if no `root` is specified, it defaults to `/`. A store with a `root` other than `/` is called a 'chroot store.' These stores maintain `/nix/store` as their logical directory but require `chroot`-ing into the specified `root` for operations. On Linux, chroot stores need `mount` and `user` namespaces enabled. An example demonstrates using `/tmp/root` as a chroot environment. The text also notes that while it's possible to change the *logical* `/nix/store` path, it's not recommended as it disables default substituters and necessitates local builds.