Distrobox: Difference between revisions

Add instructions for fixing Distrobox's host font integration functionality under NixOS
m Refer to the new Fixes for non-Nix applications page
 
(One intermediate revision by the same user not shown)
Line 29: Line 29:
== Tips and tricks ==
== Tips and tricks ==


=== Using host fonts inside Distrobox containers ===
=== Using host fonts/icons/themes inside Distrobox containers ===
By default, Distrobox tries to bind mount the host's <code>/run/host/usr/share/fonts</code> directory inside the container as <code>/usr/local/share/fonts</code>[https://github.com/89luca89/distrobox/blob/d925c3f10315b72ec38a0405e57fe06c87edc754/distrobox-init#L997-L1000]. However, on NixOS, the directory is non-existent due to NixOS not following the [https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html FHS Standard].
By default, Distrobox tries to bind mount the host's <code>/run/host/usr/share/{fonts, icons, themes}</code> directory inside the container as <code>/usr/local/share/{fonts, icons, themes}</code>[https://github.com/89luca89/distrobox/blob/d925c3f10315b72ec38a0405e57fe06c87edc754/distrobox-init#L997-L1000]. However, on NixOS, the directory is non-existent due to NixOS not following the [https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html FHS Standard].


If you have already installed fonts on your NixOS system and want them to be accessible inside Distrobox containers by default, you can set <code>fonts.fontDir.enable = true;</code> and bind mount the <code>/run/current-system/sw/share/X11/fonts</code> directory to <code>/run/host/usr/share/fonts</code>.
If you have already installed fonts/icons/themes on your NixOS system and want them to be accessible inside Distrobox containers by default, follow the instructions provided in this page: [[Fixes for non-Nix applications#Flatpak, Distrobox, Appimage and other non-Nix applications can't find system fonts/icons/themes]] .
 
(Note that this will only work for newly created or cloned Distrobox containers, this won't affect older containers.)<syntaxhighlight lang="nixos" line="1">
# distrobox-font-fix.nix
{ pkgs, ... }:
 
{
  # Bind mount fonts.fontDir path to FHS path
  # to fix distrobox font issues
 
  # Makes all the fonts declared in your NixOS
  # config accessible under /run/current-system/sw/share/X11/fonts
  fonts.fontDir.enable = true;
 
  # Distrobox: Bind mounts /run/host/usr/share/fonts
  system.fsPackages = [ pkgs.bindfs ];
  fileSystems."/run/host/usr/share/fonts" = {
    device = "/run/current-system/sw/share/X11/fonts";
    fsType = "fuse.bindfs";
    options = [
      "ro" # Mounts read-only
      "resolve-symlinks" # Makes the files seem as if they are real files and not symlinks
      "x-gvfs-hide" # Hides it from GUI file managers
    ];
  };
}
 
</syntaxhighlight>


Note that although the aforementioned solution only bindmounts paths to <code>/usr/share/</code>, the container manager being used with Distrobox (<code>podman</code>, <code>docker</code>, <code>lilypod</code> etc) will automatically make the host's root filesystem (<code>/</code>) accessible inside the container as <code>/run/host/</code>, making the paths needed by Distrobox accessible as usual, thus the aforementioned fix is sufficient.
=== 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.
The following example will run an Ubuntu container with a different architecture than the host, in this case arm64.