Recreate the VM if its image changes b8922951 parent b32bd2c1

Fix changing configuration options that require changes to the VM image (like changing `onDemand`). Previously the VM would always keep the image it generated the first time it was run. If this got out of sync with the current settings then it would often fail to start and builds would fail as they wouldn't be able to reach the VM over SSH. Since this deletes (and recreates) any existing VM when there's a new image, the cached contents of the previous VM's Nix store wlil be lost.

authored by Chris Pick

πŸ‘€
.gitignore
Switch to qcow2 image
πŸ‘€
1 year ago
πŸ‘€
LICENSE
Add LICENSE and features to README 1 year ago
πŸ‘€
README.md
Document bootstrapping with `linux-builder`
πŸ‘€
1 year ago
πŸ‘€
constants.nix
Add `darwinModules.on-demand`
πŸ‘€
1 year ago
πŸ‘€
flake.lock
`nix flake update` 1 year ago
πŸ‘€
flake.nix
Add `config.rosetta-builder.onDemand`
πŸ‘€
1 year ago
πŸ‘€
module.nix
Recreate the VM if its image changes
πŸ‘€
1 year ago
πŸ‘€
package.nix
Add `config.rosetta-builder.onDemand`
πŸ‘€
1 year ago

README.md

nix-rosetta-builder

A Rosetta 2-enabled, Apple silicon (macOS/Darwin)-hosted Linux Nix builder.

Runs on aarch64-darwin and builds aarch64-linux (natively) and x86_64-linux (quickly using Rosetta 2).

Features

Advantages over nix-darwin’s built in nix.linux-builder (which is based on pkgs.darwin.linux-builder):

  • x86_64-linux support enabled by default and much faster (using Rosetta 2)
  • Multi-core by default
  • More secure:
    • VM runs with minimum permissions (runs as a non-root/admin/wheel user/service account)
    • VM doesn’t accept remote connections (it binds to the loopback interface (127.0.0.1))
    • VM cannot be impersonated (its private SSH host key is not publicly-known)

nix-darwin flake setup

flake.nix:

{
description = "Configure macOS using nix-darwin with rosetta-builder";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nix-darwin = {
url = "github:lnl7/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-rosetta-builder = {
url = "github:cpick/nix-rosetta-builder";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ self, nix-darwin, nix-rosetta-builder, nixpkgs }: {
darwinConfigurations."${hostname}" = nix-darwin.lib.darwinSystem {
modules = [
# An existing Linux builder is needed to initially bootstrap `nix-rosetta-builder`.
# If one isn't already available: comment out the `nix-rosetta-builder` module below,
# uncomment this `linux-builder` module, and run `darwin-rebuild switch`:
# { nix.linux-builder.enable = true; }
# Then: uncomment `nix-rosetta-builder`, remove `linux-builder`, and `darwin-rebuild switch`
# a second time. Subsequently, `nix-rosetta-builder` can rebuild itself.
nix-rosetta-builder.darwinModules.default
];
};
};
}

Uninstall

Remove nix-rosetta-builder from nix-darwin’s flake.nix, darwin-rebuild switch, and then:

sudo rm -r /var/lib/rosetta-builder
sudo dscl . -delete /Users/_rosettabuilder
sudo dscl . -delete /Groups/rosettabuilder

Contributing

Feature requests, bug reports, and pull requests are all welcome.