linuxkit-nix icon indicating copy to clipboard operation
linuxkit-nix copied to clipboard

Any plans to integrate back to Nix proper?

Open copumpkin opened this issue 7 years ago • 11 comments

Curious if you've thought through what would be required to make this an integral part of Nix on macOS. Would be super cool if it could be seamless!

copumpkin avatar Aug 29 '18 17:08 copumpkin

That would be cool!

I wonder if we should have a fancy gui installer separate from the Nix release, to include more monolithically tools like this.

grahamc avatar Sep 06 '18 19:09 grahamc

@grahamc Apologies for asking it here, but it is semi related, and the issue in nixpkgs (https://github.com/NixOS/nixpkgs/issues/16696) about docker on a mac was closed.

Is there a reason why we need to run a VM to create a docker image on OS X? I understand that docker requires linux-x86_64 binaries to run, but looks like nix is capable of cross compiling and generating linux binaries on mac, and here https://github.com/NixOS/nixpkgs/issues/16696#issuecomment-423398121 appears like charles-dyfis-net got close to get it working.

takeda avatar Dec 18 '18 07:12 takeda

@takeda I think it used to be possible to build a Docker image on macOS. People were building images with macOS binaries, accidentally. If you use macOS to cross-build Linux dependencies then do a buildImage, you don't need a VM.

puffnfresh avatar Dec 18 '18 08:12 puffnfresh

What I'm trying to say is, that it theoretically building docker container under OS X should be as simple as passing "x86_64-linux" as target architecture to nixpkgs. From the comment looks like it almost works, but it fails when it tries to start linux bash under OS X, implying that perhaps bash is listed as buildInputs when an OS X version should be built instead and passed to nativeBuildInputs.

I like to believe that we are really close to do that and that VM is not needed at all, but perhaps I'm missing something.

takeda avatar Dec 18 '18 16:12 takeda

@takeda the comment is passing "system" "x86_64-linux" to nixpkgs. Don't do that and you should be able to build Docker images using Darwin.

puffnfresh avatar Dec 18 '18 16:12 puffnfresh

Some places that I think we can pretty easily integrate back in:

  • Add nix-script-store-plugin, hyperkit, linuxkit, virtsock, vpnkit, go-vpnkit to Nixpkgs as ordinary packages.
  • Put parts of linuxkit-builder into a NixOS module. We could also add a release job so that it appears in the cache for every NixOS version.

That would still leave linuxkit-builder and nix-linuxkit-runner as well as some of the glue code. Not sure how to handle these...

matthewbauer avatar Dec 31 '18 02:12 matthewbauer

@matthewbauer yeah I really think we should do at least those two things.

puffnfresh avatar Dec 31 '18 05:12 puffnfresh

@puffnfresh sorry, for refreshing an old thread, but what's the recommend way to build a docker image on OS X? If I don't specify system=x86_64-linux (and use docker image or linuxkit to build it) the binaries that will be used will be built for darwin and won't run in docker. Is there a better place where to specify the architecture?

Also is cross compiling any use? Seems like one would be the intended way of doing it, but I tried to use crossSystem instead, and looks like that needs to recompile everything from scratch.

takeda avatar Feb 16 '21 06:02 takeda

@takeda I switched from linuxkit-nix to nix-docker recently (since it seemed unmaintained at this point), and set it up as a remote builder according to[0] and have compiled Docker images in this way on macOS.

[0] https://github.com/LnL7/nix-docker#running-as-a-remote-builder

siraben avatar Feb 25 '21 12:02 siraben

Example with an overlay:

$ nix build .#pkgs.x86_64-linux.nix-hello
$ docker load -i ./result                 
f284825dce54: Loading layer [==================================================>]  1.649MB/1.649MB
486e72206d1d: Loading layer [==================================================>]    256kB/256kB
8afb3985975d: Loading layer [==================================================>]   31.6MB/31.6MB
694032bc7c41: Loading layer [==================================================>]  266.2kB/266.2kB
77bbb7945d50: Loading layer [==================================================>]  71.68kB/71.68kB
The image nix-hello:latest already exists, renaming the old one with ID sha256:952ba607e8b714d40d6a83e007e9f4736aba28d1f3171012c772307820e9fe7f to empty string
Loaded image: nix-hello:latest
$ docker run -ti nix-hello:latest hello
Hello, world!

siraben avatar Feb 25 '21 12:02 siraben

@siraben thanks for the suggestion, that works, but it's (same as with linuxkit-nix) it is an extra step that need to be done, and it makes it harder to get other coworkers get sold on nix if they have to do bunch of other stuff to get up to speed (I think it's amazing for setting up developer environment).

What I would love nix to do is to cross compile packages so no extra build machines would be needed.

takeda avatar Mar 03 '21 02:03 takeda