Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Multi-platform

Sometimes, you need to run your composition(s) in multiple (or specific) platforms.

For example, if your setup requires an exotic kind of cluster, it may only be available in ARM (aarch64) CPU instruction-set.

NixOS-Compose supports multi-platform by default. You just need to enable it.

Here is a basic flake example for various platforms (here: x86-64, aarch64 & powerpc64le):

{
  ...

  outputs = { self, nixpkgs, nxc }:
    let
      systems = [
        "x86_64-linux"
        "powerpc64le-linux"
        "aarch64-linux"
      ];
      forAllSystems = nixpkgs.lib.genAttrs systems;
    in
    {
      packages = forAllSystems (system:
        nxc.lib.compose {
          inherit nixpkgs system;
          composition = ./composition.nix;
        }
      );

      defaultPackage = forAllSystems (system:
        self.packages.${system}."composition::vm"
      );

      devShell = forAllSystems (system:
        nxc.devShells.${system}.nxcShell
      );
    };
}

You can adapt this to your need by the systems array; This provides the necessary definitions for building your flake with these 3 systems.

Tip

You can find a list of platforms that are currently supported by nixpkgs over in the nixpkgs manual.

Using NixOS-Compose with different platforms

Once defined in your flake, you can use a specific platform by specifying the namespace in which you want NixOS-Compose to build against.

Note

In the following example, we are running a build with the VM flavour, with aarch64 as our system.

This will only succeed if the host running the command can actually compile aarch64.

nxc build -f vm --namespace .#packages.aarch64-linux

You can also use a remote-builder if you have one available:

nxc build -f vm --namespace .#packages.aarch64-linux --mounted-store-url builder@remote-builder

That is; If your builder supports the target platform.

Tip

If you wish to compile another platform (let’s say you want aarch64), but your system is not compatible (let’s say you run x86-64), you can use tools such as binfmt.

Compiling with this tool is quite slow, but it gets the job done.