nix-community / NixOS-WSL

NixOS on WSL(2) [maintainer=@nzbr]
Apache License 2.0
1.6k stars 108 forks source link

Rancher desktop support #440

Open x-0D opened 4 months ago

x-0D commented 4 months ago

Problem

Rancher desktop integration don't work with nixos distro

Solution

Add support for rancher-desktop integration optional feature flag

jDmacD commented 3 months ago

I tried this after seeing you post. If you have Rancher Desktop installed the docker cli is available at /mnt/c/Program Files/Rancher Desktop/resources/resources/linux/bin/ and the docker socket is at /mnt/wsl/rancher-desktop/run/docker.sock.

You can connect by

Everytime rancher restart the permissions on /mnt/wsl/rancher-desktop/run/docker.sock will reset.

I am using home-manager so I put this in my configuration

  home.sessionVariables = {
    DOCKER_HOST = "unix:///mnt/wsl/rancher-desktop/run/docker.sock";
  };
  home.sessionPath = [
    "/mnt/c/Program Files/Rancher Desktop/resources/resources/linux/bin/"
  ];

 home.packages = [
    (pkgs.writeShellScriptBin "rancher-desktop" ''
      echo "starting rancher.."
      /mnt/c/Program\ Files/Rancher\ Desktop/Rancher\ Desktop.exe&
      echo "setting permissions.."
      sudo chown nixos:users /mnt/wsl/rancher-desktop/run/docker.sock
      echo "done!"
    '') 
]

It's a little clunky, but it seems to work. I haven't tested it thoroughly.

phma4 commented 1 month ago

Another workaround is to add PATH=$PATH:/run/current-system/sw/bin/

at the beginning of:

C:\Program Files\Rancher Desktop\resources\resources\setup-spin

The write protection needs to be removed before the file can be edited. Afterwards enabling the integration should work the same as with other distros. This should probably be reported to the Rancher Desktop repo and fixed there.

Credit: https://github.com/sonowz/vscode-remote-wsl-nixos/blob/master/server-env-setup