linuxkit-nix/README.md

134 lines
4.3 KiB
Markdown
Raw Permalink Normal View History

2023-01-27 07:50:20 +03:00
*__You should look at the
[darwin.builder](https://nixos.org/manual/nixpkgs/unstable/#sec-darwin-builder),
2023-01-27 07:50:20 +03:00
which is now part of nixpkgs.__*
linuxkit-nix was started in 2017 when QEMU did not support macOS'
Hypervisor.framework API. This meant that QEMU had to use full
emulation with no hardware acceleration. Not ideal for building large
software.
QEMU also had some issues on macOS with userspace networking.
At the time, LinuxKit was the easiest way to spin up a VM for builds,
because it spun up HyperKit for hardware accelerated virtualisation
and VPNKit for userspace networking - both used in Docker for Mac.
Theoretically the underlying technology was stable but it was bit
tricky to get everything working well together. There were
bootstrapping issues. For example, we had to be careful when
referencing `linux-x86_64` packages because we were on `darwin-x86_64`
and it could only fetch from Hydra - it couldn't even build a custom
shell script for the Linux VM until we got that initial VM running.
This project also had issues with daemons, permissions and race
conditions.
In 2018, QEMU got experimental support for Hypervisor.framework and
that got promoted to stable in 2019. QEMU is now fast and since
nixpkgs has great support for building and running QEMU virtual
machines, there's little need for this project.
---
2018-11-08 00:16:37 +03:00
# LinuxKit Nix - Linux on Mac Nix builder
2019-07-30 21:57:15 +03:00
[hydra jobset](https://hydra.nixos.org/jobset/linux-on-mac-builder/master)
LinuxKit Nix makes it easy to build Linux binaries from a macOS machine using
Nix. It's installing a VM using the native virtualization
(Hypervisor.Framework) so it's quite liteweight compared to installing
VirtualBox. The project also comes with an installation script that configures
Nix to use the VM as a remote builder automatically.
2018-04-02 17:34:28 +03:00
## Requirements
This project depends on Nix and a nixpkgs channel >= 18.03.
## Installation
2018-04-11 15:48:41 +03:00
Fetch it from the NixOS binary cache:
2018-04-11 15:48:41 +03:00
2018-11-07 21:40:21 +03:00
nix-env -i /nix/store/jgq3savsyyrpsxvjlrz41nx09z7r0lch-linuxkit-builder
nix-linuxkit-configure
It'll write to:
2018-04-11 15:48:41 +03:00
- ~/.cache/nix-linuxkit-builder/, in particular
~/.cache/nix-linuxkit-builder/nix-state/console-ring is interesting
- ~root/.ssh/ for the SSH config
- /etc/nix/machines
- ~/Library/LaunchAgents/org.nix-community.linuxkit-builder.plist
2018-04-11 15:48:41 +03:00
2018-11-08 00:14:50 +03:00
Once installed the daemon should automatically start and stay running.
2018-04-11 15:48:41 +03:00
2018-11-08 00:14:50 +03:00
## Debugging
2018-04-11 15:48:41 +03:00
2018-11-08 00:14:50 +03:00
To see if the daemon is running execute the following command and look at the
first column. If it has a number (PID) it's running, if it's `-` then it's
stopped:
launchctl list | grep linuxkit
2018-04-11 15:48:41 +03:00
You can force start it with:
2018-04-11 15:48:41 +03:00
launchctl start org.nix-community.linuxkit-builder
2018-04-11 15:48:41 +03:00
You can force stop it with:
2018-04-11 15:48:41 +03:00
launchctl stop org.nix-community.linuxkit-builder
2018-04-11 15:48:41 +03:00
If after you stop it you may want to check for processes, like:
2018-04-02 17:34:28 +03:00
pgrep vpnkit
pgrep linuxkit
pgrep hyperkit
2018-04-02 17:34:28 +03:00
2018-08-11 13:49:19 +03:00
If something goes wrong and it didn't stop properly, you can try:
2018-04-02 17:34:28 +03:00
pkill -F ~/.cache/nix-linuxkit-builder/nix-state/hyperkit.pid hyperkit
2018-11-08 00:14:50 +03:00
2020-01-14 21:07:39 +03:00
## Troubleshooting
### `cannot build on 'ssh://nix-linuxkit': cannot connect to 'nix-linuxkit' ...`
When runninng `nix-linuxkit-configure`, an SSH config is created at
`/var/root/.ssh/nix-linuxkit-ssh-config`. Copy the contents of that SSH config
into your regular SSH config located at `~/.ssh/config`.
2018-11-08 00:14:50 +03:00
### `error: 'x86_64-linux' is require to build ...`
Check the `/etc/nix/nix.conf` file for a `builders` option. It should either
be set to `@/etc/nix/machines` or not set at all for LinuxKit Nix to work
properly.
2019-08-24 12:22:22 +03:00
Another solution is to set `export NIX_REMOTE_SYSTEMS=/etc/nix/machines`
before running the nix or nixops command.
2018-11-08 00:14:50 +03:00
### `cannot build on 'ssh://nix-linuxkit': cannot connect ...: Operation timed out`
Something is wrong with LinuxKit. See the debugging section to try things out.
Leave an issue at https://github.com/nix-community/linuxkit-nix/issues
2020-01-14 21:08:08 +03:00
## Uninstalling
```sh
# Remove configuration
rm -rf ~/.cache/nix-linuxkit-builder/
# Remove build machine
# (edit manually if you have other configuration here)
sudo rm -f /etc/nix/machines
# Remove LaunchAgent
launchctl stop org.nix-community.linuxkit-builder
rm -f ~/Library/LaunchAgents/org.nix-community.linuxkit-builder.plist
# Remove SSH config
# (edit manually if you have other configuration here)
sudo rm -rf /var/root/.ssh
# Uninstall Nix package
nix-env -e linuxkit-builder
```