Distrobox: Difference between revisions
Use with different architecture |
Add known issue: Distrobox is not location independent. I have personally encountered this. |
||
| (15 intermediate revisions by 6 users not shown) | |||
| Line 16: | Line 16: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
distrobox create --root --name archlinux --init --image archlinux:latest | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 22: | Line 22: | ||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
distrobox enter --root archlinux | |||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 30: | Line 30: | ||
=== Using different architecture === | === Using different architecture === | ||
The following example will run an Ubuntu container with a different architecture than the host, in this case arm64. | |||
Add following line to your system configuration, apply it and then reboot the system.<syntaxhighlight lang="nix"> | |||
boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; | |||
</syntaxhighlight>Run a Debian container with arm64 architecture<syntaxhighlight lang="nix"> | |||
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes | sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes | ||
distrobox create -n | distrobox create -n debian --image arm64v8/debian | ||
distrobox enter | distrobox enter debian | ||
</syntaxhighlight> | |||
=== "potentially insufficient UIDs and GUIDs" error === | |||
When setting up containers that do not run as root, as <code>podman</code> does by default, you may see an error along the following lines: (this example uses podman, lilipod has a different error) | |||
<syntaxhighlight lang="console"> | |||
# distrobox create container | |||
... | |||
Error: copying system image from manifest list: writing blob: adding layer with blob ...: | |||
unpacking failed (error: exit status 1; | |||
output: potentially insufficient UIDs or GIDs available in user namespace (requested 1000:1000 for /home/container): Check /etc/subuid and /etc/subgid if configured locally and run "podman system migrate": lchown /home/container: invalid argument) | |||
</syntaxhighlight> | |||
To fix it, adding the following to your config might help: | |||
<syntaxhighlight lang="nix"> | |||
users.users.YOURUSERNAME = { | |||
extraGroups = [ "podman" ]; | |||
subGidRanges = [ | |||
{ | |||
count = 65536; | |||
startGid = 1000; | |||
} | |||
]; | |||
subUidRanges = [ | |||
{ | |||
count = 65536; | |||
startUid = 1000; | |||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Rebuild your system, run <code>podman system migrate</code>, and try creating the distrobox container again. | |||
=== Exposing your profile === | |||
If you get errors like <code>/home/user/.zshenv:.:2: no such file or directory: /etc/profiles/per-user/user/etc/profile.d/hm-session-vars.sh</code> or <code>_atuin_preexec: command not found: atuin</code> that is because your shell init is referencing paths that are not accessible to Distrobox. By default, Distrobox only gets access to your home directory. You can mount additional volumes with <code>distrobox create --volume /your/custom/volume/path</code>, but it is more convenient to define defaults in <code>distrobox.conf</code>: <syntaxhighlight lang="nix">environment.etc."distrobox/distrobox.conf".text = '' | |||
container_additional_volumes="/nix/store:/nix/store:ro /etc/profiles/per-user:/etc/profiles/per-user:ro /etc/static/profiles/per-user:/etc/static/profiles/per-user:ro" | |||
''; </syntaxhighlight> | |||
[[Category:Applications]] | [[Category:Applications]] | ||
[[Category:Container]] | [[Category:Container]] | ||
== Known Issues == | |||
=== Distrobox Fails With Arch Linux and init === | |||
This is a cross-distro (not NixOS-specific) issue resulting from a [https://github.com/util-linux/util-linux/ util-linux] runuser regression.<ref name="debian-report">https://github.com/89luca89/distrobox/issues/2069</ref><ref name="nixos-report">https://github.com/89luca89/distrobox/issues/2065</ref> A fix has recently been merged, and the issue should be resolved in the next release (v2.43).<ref name="util-linux-pull">https://github.com/util-linux/util-linux/pull/4185</ref>. | |||
=== Distrobox is not location independent === | |||
The symptom is that a distrobox container created in the past can not run, because it references a non-existing "distrobox-init" script as a necessary bind mount. | |||
Historically, this was a known issue<ref>https://github.com/89luca89/distrobox/issues/315</ref> affecting users who have created a container with a different version of distrobox than the one that is currently running. It can surface after running GC. The root cause is that the container is created with bind mounts for essential scripts, one of which is the entrypoint itself, the source of which is often an absolute path, such as: <code>/nix/store/XXXXX-distrobox/bin/distrobox-init</code>. The problem is that once a container was created with a bind mount, its source has to be available every time the container is re-executed. | |||
This issue was solved 2 times upstream, both in 2022: | |||
The first solution<ref>https://github.com/89luca89/distrobox/commit/52a34fbd52e1f0f035657b167ebe997d41db0993</ref> replaces the bind-mount with copying the scripts into the container during distrobox-enter. | |||
The second solution<ref>https://github.com/89luca89/distrobox/commit/1ad3204ee78dfb8ee772cdd81788f3cbb3f4bd1b</ref> reverts the first solution, due to problems the former had introduced with btrfs. In order to avoid regressions for Nix users, it introduces a weaker solution for mounting the scripts: instead of <code>realpath</code>, it makes use of: <code>cd "$(dirname "${0}")" && pwd</code>. That works, but only as long as: | |||
# The "$0" argument is preserved. There was an [https://github.com/NixOS/nixpkgs/issues/478154 issue in nixpkgs], fixed in 2026<ref>https://github.com/NixOS/nixpkgs/commit/2f87ef8fdbabc6df0fbaf59ad14598864711ed4c</ref>, with non-preservation of "$0" in the "distrobox" command wrapper. Direct calls to <code>distrobox-create</code> were unaffected. | |||
# In every future execution of the container, the distrobox utilities will remain in the same path. This is workable when the installation is fixed on a path like <code>/run/current-system/sw/bin/distrobox-init</code>. | |||
Notably, if you were affected by the first issue, then your container will not work even after the fixes that have since come out. The second issue is not resolved due to decisions upstream. | |||
== References == | |||
<references/> | |||
Latest revision as of 15:16, 22 May 2026
Distrobox offers you to use any linux distribution inside your terminal as a simple wrapper for Podman, Docker or Lilipod.
Setup
Distrobox uses Docker internally to fetch and run system images. Easily get started by enabling Podman with Docker-compatibility mode.
virtualisation.podman = {
enable = true;
dockerCompat = true;
};
environment.systemPackages = [ pkgs.distrobox ];
Usage
Setup container with latest Arch Linux image
distrobox create --root --name archlinux --init --image archlinux:latest
Enter Arch Linux container
distrobox enter --root archlinux
For further usage, please refer to the Distrobox documentation.
Tips and tricks
Using different architecture
The following example will run an Ubuntu container with a different architecture than the host, in this case arm64.
Add following line to your system configuration, apply it and then reboot the system.
boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
Run a Debian container with arm64 architecture
sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes
distrobox create -n debian --image arm64v8/debian
distrobox enter debian
"potentially insufficient UIDs and GUIDs" error
When setting up containers that do not run as root, as podman does by default, you may see an error along the following lines: (this example uses podman, lilipod has a different error)
# distrobox create container
...
Error: copying system image from manifest list: writing blob: adding layer with blob ...:
unpacking failed (error: exit status 1;
output: potentially insufficient UIDs or GIDs available in user namespace (requested 1000:1000 for /home/container): Check /etc/subuid and /etc/subgid if configured locally and run "podman system migrate": lchown /home/container: invalid argument)
To fix it, adding the following to your config might help:
users.users.YOURUSERNAME = {
extraGroups = [ "podman" ];
subGidRanges = [
{
count = 65536;
startGid = 1000;
}
];
subUidRanges = [
{
count = 65536;
startUid = 1000;
}
];
};
Rebuild your system, run podman system migrate, and try creating the distrobox container again.
Exposing your profile
If you get errors like /home/user/.zshenv:.:2: no such file or directory: /etc/profiles/per-user/user/etc/profile.d/hm-session-vars.sh or _atuin_preexec: command not found: atuin that is because your shell init is referencing paths that are not accessible to Distrobox. By default, Distrobox only gets access to your home directory. You can mount additional volumes with distrobox create --volume /your/custom/volume/path, but it is more convenient to define defaults in distrobox.conf:
environment.etc."distrobox/distrobox.conf".text = ''
container_additional_volumes="/nix/store:/nix/store:ro /etc/profiles/per-user:/etc/profiles/per-user:ro /etc/static/profiles/per-user:/etc/static/profiles/per-user:ro"
'';
Known Issues
Distrobox Fails With Arch Linux and init
This is a cross-distro (not NixOS-specific) issue resulting from a util-linux runuser regression.[1][2] A fix has recently been merged, and the issue should be resolved in the next release (v2.43).[3].
Distrobox is not location independent
The symptom is that a distrobox container created in the past can not run, because it references a non-existing "distrobox-init" script as a necessary bind mount.
Historically, this was a known issue[4] affecting users who have created a container with a different version of distrobox than the one that is currently running. It can surface after running GC. The root cause is that the container is created with bind mounts for essential scripts, one of which is the entrypoint itself, the source of which is often an absolute path, such as: /nix/store/XXXXX-distrobox/bin/distrobox-init. The problem is that once a container was created with a bind mount, its source has to be available every time the container is re-executed.
This issue was solved 2 times upstream, both in 2022:
The first solution[5] replaces the bind-mount with copying the scripts into the container during distrobox-enter.
The second solution[6] reverts the first solution, due to problems the former had introduced with btrfs. In order to avoid regressions for Nix users, it introduces a weaker solution for mounting the scripts: instead of realpath, it makes use of: cd "$(dirname "${0}")" && pwd. That works, but only as long as:
- The "$0" argument is preserved. There was an issue in nixpkgs, fixed in 2026[7], with non-preservation of "$0" in the "distrobox" command wrapper. Direct calls to
distrobox-createwere unaffected. - In every future execution of the container, the distrobox utilities will remain in the same path. This is workable when the installation is fixed on a path like
/run/current-system/sw/bin/distrobox-init.
Notably, if you were affected by the first issue, then your container will not work even after the fixes that have since come out. The second issue is not resolved due to decisions upstream.
References
- ↑ https://github.com/89luca89/distrobox/issues/2069
- ↑ https://github.com/89luca89/distrobox/issues/2065
- ↑ https://github.com/util-linux/util-linux/pull/4185
- ↑ https://github.com/89luca89/distrobox/issues/315
- ↑ https://github.com/89luca89/distrobox/commit/52a34fbd52e1f0f035657b167ebe997d41db0993
- ↑ https://github.com/89luca89/distrobox/commit/1ad3204ee78dfb8ee772cdd81788f3cbb3f4bd1b
- ↑ https://github.com/NixOS/nixpkgs/commit/2f87ef8fdbabc6df0fbaf59ad14598864711ed4c