-
Notifications
You must be signed in to change notification settings - Fork 18
treewide: add support for building on aarch64-darwin #2260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ed0c65b
3912a50
51280f5
9c85402
28db045
5cebed1
b2ed01c
3d1e292
a0adb80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Development setup for macOS (experimental) | ||
|
|
||
| Contrast uses `just` and Nix as its build system. Several packages Contrast needs to build, such as container images (`nix build .#base.containers.*`), need to be built for `x86_64-linux` so when building from a different architecture such as `aarch64-darwin`, those builds need to be delegated to a builder that can build for `x86_64-linux`. | ||
|
|
||
| ## Canonical setup | ||
|
|
||
| 1. Install Nix. You have several options such the [Lix installer](https://lix.systems/install/) (recommended), the [Determinate Nix installer](https://docs.determinate.systems/) or by following the [official instructions](https://nixos.org/download/). It's recommended to use one of the automated installers as they also make the uninstall on macOS easy. | ||
|
|
||
| 2. Setup a `x86_64-linux` builder. There are 2 options: | ||
|
|
||
| - setup a remote builder by following Nix's [distributed builds tutorial](https://nix.dev/tutorials/nixos/distributed-builds-setup.html). If you are working for Edgeless Systems, you can use one of our office machines by following the instructions in https://github.com/edgelesssys/nix-remote-builders. | ||
| - setup a local VM-based builder that emulates x86, by installing [nix-rosetta-builder](https://github.com/cpick/nix-rosetta-builder). Not that the performance of this option might not be great but it's helpful if you need to work offline. | ||
|
|
||
| It's recommended to setup both. Nix will automatically offload packages that need to be built for `x86_64-linux` to any builder available for that architecture. So if one of the remote machines isn't available, builds will use the VM-based builder. | ||
|
|
||
| ## Alternative setup using a Linux VM | ||
|
|
||
| Alternatively you can setup a VM with Nix which you can use to build contrast. Since this option will be also using emulation, the performance might not be great. | ||
|
|
||
| 1. Follow the instructions on [nixos-lima](https://github.com/nixos-lima/nixos-lima) and [nixos-lima-config-sample](https://github.com/nixos-lima/nixos-lima-config-sample) to create a `x86_64-linux` VM. | ||
|
|
||
| 2. To avoid having to authenticate twice either with your container registry or kubectl, you can forward the local credentials to the VM by adding the following in the VM configuration: | ||
|
|
||
| ```yaml | ||
| - location: "~/.docker" | ||
| mountPoint: "/home/lima.linux/.docker" | ||
| writable: true | ||
| 9p: | ||
| cache: "mmap" | ||
| - location: "~/.kube" | ||
| mountPoint: "/home/lima.linux/.kube" | ||
| writable: true | ||
| ``` | ||
|
|
||
| 3. Forward contrast project path as well: | ||
|
|
||
| ```yaml | ||
| - location: "~/contrast" | ||
| writable: true | ||
| 9p: | ||
| cache: "mmap" | ||
| ``` | ||
|
|
||
| 4. Add the lima user to trusted-users by adding the following in the VM's NixOS configuration (`configuration.nix`): | ||
|
|
||
| ```nix | ||
| nix.settings.trusted-users = [ "root" "@wheel" ]; | ||
| ``` | ||
|
|
||
sespiros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 5. (Optional) You might have to add the hosts you are deploying to in the VM's NixOS configuration: | ||
|
|
||
| ```nix | ||
| networking.hosts = { | ||
| "XXX.YYY.ZZZ.XXX" = [ "<SOME HOSTNAME>" ]; | ||
| }; | ||
| ``` | ||
|
|
||
| 6. Start a `x86_64` VM with: | ||
|
|
||
| ```bash | ||
| limactl start --yes --set '.user.name = "lima"' nixos.yaml --arch=x86_64 | ||
| ``` | ||
|
|
||
| 7. Connect to the VM with: | ||
|
|
||
| ``` | ||
| cd ~/contrast | ||
| limactl shell nixos | ||
| nix develop .# | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Copyright 2026 Edgeless Systems GmbH | ||
| # SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| final: prev: | ||
|
|
||
| if prev.stdenv.hostPlatform.system == "x86_64-linux" then | ||
| { } | ||
| else | ||
| { | ||
| contrastPkgs = prev.contrastPkgs.overrideScope ( | ||
| _cFinal: cPrev: { | ||
| kata = cPrev.kata.overrideScope ( | ||
| _: _: { | ||
| inherit (final.runtimePkgs.kata) | ||
| contrast-node-installer-image | ||
| agent | ||
| image | ||
| kernel-uvm | ||
| calculateSnpLaunchDigest | ||
| calculateTdxLaunchDigests | ||
| ; | ||
| } | ||
| ); | ||
|
|
||
| contrast = cPrev.contrast.overrideScope ( | ||
| _: _: { | ||
| inherit (final.runtimePkgs.contrast) | ||
| coordinator | ||
| initializer | ||
| node-installer-image | ||
| nodeinstaller | ||
| ; | ||
| } | ||
| ); | ||
|
|
||
| inherit (final.runtimePkgs) | ||
| debugshell | ||
| service-mesh | ||
| k8s-log-collector | ||
| boot-image | ||
| boot-microvm | ||
| qemu-cc | ||
| pause-bundle | ||
| OVMF-TDX | ||
| calculateSnpIDBlock | ||
| ; | ||
|
|
||
| scripts = cPrev.scripts.overrideScope ( | ||
| _: _: { | ||
| inherit (final.runtimePkgs.scripts) | ||
| cleanup-bare-metal | ||
| cleanup-images | ||
| cleanup-containerd | ||
| nix-gc | ||
| ; | ||
| } | ||
| ); | ||
|
|
||
| inherit (final.runtimePkgs) containers; | ||
| } | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
|
|
||
| { | ||
| lib, | ||
| stdenv, | ||
| buildGoModule, | ||
| contrast, | ||
| kata, | ||
|
|
@@ -54,7 +55,14 @@ buildGoModule (finalAttrs: { | |
| nativeBuildInputs = [ installShellFiles ]; | ||
|
|
||
| prePatch = '' | ||
| install -D ${lib.getExe contrastPkgsStatic.kata.genpolicy} cli/genpolicy/assets/genpolicy-kata | ||
| # On linux, use the statically linked genpolicy (portable across distros). | ||
| # On darwin, use the native build (macOS doesn't support static binaries | ||
| # and system libraries are always present). | ||
| install -D ${ | ||
| lib.getExe ( | ||
| if stdenv.hostPlatform.isDarwin then kata.genpolicy else contrastPkgsStatic.kata.genpolicy | ||
| ) | ||
| } cli/genpolicy/assets/genpolicy-kata | ||
|
Comment on lines
+58
to
+65
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhhh I get now what you meant in the other comment. Did the "old" version, i.e. overriding |
||
| install -D ${kata.genpolicy.rules}/genpolicy-rules.rego cli/genpolicy/assets/genpolicy-rules-kata.rego | ||
| install -D ${reference-values} internal/manifest/assets/reference-values.json | ||
| install -D ${snp-id-blocks} cli/cmd/assets/snp-id-blocks.json | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than a new scope, could we nest this in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright 2026 Edgeless Systems GmbH | ||
| # SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| { | ||
| lib, | ||
| pkgs, | ||
| contrastPkgs, | ||
| writeShellApplication, | ||
| }: | ||
|
|
||
| let | ||
| pushOCIDir = | ||
| name: dir: tag: | ||
| writeShellApplication { | ||
| name = "push-${name}"; | ||
| runtimeInputs = with pkgs; [ crane ]; | ||
| text = '' | ||
| imageName="$1" | ||
| containerlookup="''${2:-/dev/null}" | ||
| layersCache="''${3:-$(mktemp)}" | ||
| hash=$(crane push "${dir}" "$imageName:${tag}") | ||
| printf "ghcr.io/edgelesssys/contrast/%s:latest=%s\n" "${name}" "$hash" >> "$containerlookup" | ||
| if [ ! -f "$layersCache" ]; then | ||
| echo -n "[]" > "$layersCache" | ||
| fi | ||
| jq -s 'add' "$layersCache" "${dir}/layers-cache.json" > tmp.json && mv tmp.json "$layersCache" | ||
| echo "$hash" | ||
| ''; | ||
| }; | ||
| in | ||
| { | ||
| push-node-installer-kata = | ||
| pushOCIDir "node-installer-kata" contrastPkgs.contrast.node-installer-image | ||
| "v${contrastPkgs.contrast.nodeinstaller.version}"; | ||
| push-node-installer-kata-gpu = | ||
| pushOCIDir "node-installer-kata-gpu" contrastPkgs.contrast.node-installer-image.gpu | ||
| "v${contrastPkgs.contrast.nodeinstaller.version}"; | ||
| } | ||
| // (lib.concatMapAttrs (name: container: { | ||
| "push-${name}" = pushOCIDir name container.outPath container.meta.tag; | ||
| }) contrastPkgs.containers) |
Uh oh!
There was an error while loading. Please reload this page.