89luca89 / distrobox

Use any linux distribution inside your terminal. Enable both backward and forward compatibility with software and freedom to use whatever distribution you’re more comfortable with. Mirror available at: https://gitlab.com/89luca89/distrobox
https://distrobox.it/
GNU General Public License v3.0
9.82k stars 398 forks source link

[Discussion]: Running distrobox on NixOS #958

Open I-Want-ToBelieve opened 1 year ago

I-Want-ToBelieve commented 1 year ago

The idea of ​​distrobox is to integrate the host's home directory into the container system, but the configuration files in the NixOS home directory have many paths to /nix/store/ and /etc/profiles/per-user/, and these paths are not included in the container. It does not exist. If these paths are mounted into the container, there will be bigger problems. Is there any solution to get rid of this dilemma?

❯ distrobox enter archlinux
/nix/store/5wspmqhgsfs7dza9gcyrj5yxbyd00q7y-coreutils-9.3/bin/dircolors: /var/lib/libvirt/distrobox/home/archlinux/.dir_colors: No such file or directory
Ducklett

    ▄▀▄▀▄       
    ▀▀▀▀▀▄      
  ▄▀▀▀▀▀▀▀▀     
  ▀▀▀▀▀▀▀▀▀▀ ▄  
▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀ 
 ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
   ▄▀▀▀▀▀▀▀▀▀▀▀▀
   ▀▀▀▀▀▀▀▀▀▀▀  
    ▀▀▀▀▀▀▀▀▀   
        ▀▀▀     

/etc/profiles/per-user/i.want.to.believe/bin/starship: command not found
/home/i.want.to.believe/.config/fish/config.fish (line 1): 
/etc/profiles/per-user/i.want.to.believe/bin/starship init fish
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in command substitution
    called on line 65 of file /home/i.want.to.believe/.config/fish/config.fish
from sourcing file /home/i.want.to.believe/.config/fish/config.fish
    called during startup
/home/i.want.to.believe/.config/fish/config.fish (line 65): Unknown command
        eval (/etc/profiles/per-user/i.want.to.believe/bin/starship init fish)
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
from sourcing file /home/i.want.to.believe/.config/fish/config.fish
    called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
[I] i.want.to.believe@archlinux /h/i.want.to.believe> 
I-Want-ToBelieve commented 1 year ago

Is it possible to mount these paths as read-only?

I-Want-ToBelieve commented 1 year ago

This seems to allow archlinux to read and execute programs in nixos-specific paths. Since archlinux does not have write permissions on these paths, it will not affect nixos.

I-Want-ToBelieve commented 1 year ago

Another option is to explore the possibility of home-manager being compatible with distrobox.

One form is that home-manager does not use distro-dependent paths, for example /etc/profiles/per-user/i.want.to.believe/bin/starship can be directly replaced by starship.

Another form is to install nix in archlinux and also use home-manager to manage the home directory. Put nixos' flake config into archlinux and build it to generate a path similar to nixos. This can be called isomorphism

I-Want-ToBelieve commented 1 year ago

The last way I can think of is for distrobox to provide an option whether to integrate nixos home into archlinux

89luca89 commented 1 year ago

I think it probably is easier to just source certain things in your ~/.profile or ~/.bashrc or ~/.zshrc only if NOT in the container

For example:

if [ ! -e /run/.toolboxenv ]; then
     do_my_awesome_stuff_on_host
else
     do_other_stuff_in_container
fi

This way you only source stuff when needed

tu-maurice commented 11 months ago

I mean the issue at hand is that the host's PATH and probably a few other environment variables are reused inside the container created by distrobox. I don't think you'd want that regardless of what distribution you're using distrobox on. Docker and podman don't reuse the environment by default, so why do these environment variables end up in the container?

I-Want-ToBelieve commented 11 months ago

This is more about the problem that the configuration files(dotfiles) in the home directory use hard-coded host paths and these paths do not exist in the container. It should not be related to the issue of environment variables.

I-Want-ToBelieve commented 11 months ago

NixOS is not fhs

Imagine if you use an ArchLinux container on a host running Ubuntu, then when the container is created, since the container reuses the host's home directory, and some software in the configuration files in the home directory does not exist in the container, command not found will be reported, but this is easy to solve. I only need to install these missing software in the ArchLinux container, but this does not work in NixOS. The path of NixOS is not /usr/bin but Special /nix/store and /etc/profiles/per-user

I-Want-ToBelieve commented 11 months ago

I thought of another way, what if the host's home directory is used as the lowerdir in overlayfs and the one to be used by the distrobox is used as the upperdir?

tu-maurice commented 11 months ago

This is more about the problem that the configuration files(dotfiles) in the home directory use hard-coded host paths

You're right. The ticket's description is different from my issue. Please disregard.

SadSock commented 2 months ago

I have encountered this problem as well. As an immutable distribution, NixOS greatly needs Distrobox. Immutable distributions are becoming increasingly popular.

This question currently have solution or not? Can through not mounting/home directory temporarily solve it?