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-composition

Sometimes you have two or more compositions that have a lot in common. For example, you want to test a tool with different integration, or run performance tests on multiple similar tools, etc…

To do so, NixOSCompose provides a simple mechanism that allows you to create a multi-composition.

Example

Here is a simple example of a composition.nix file:

{
  oar = import ./oar.nix;
  slurm = import ./slurm.nix;
}

Each *.nix file being a composition file itself. For example, the oar.nix might look like:

{ pkgs, ... }: {
  roles =
    let
      commonConfig = import ./common_config.nix { inherit pkgs; };
    in
    {
      server = { ... }: {
        imports = [ commonConfig oarConfig ];
        services.oar.server.enable = true;
        services.oar.dbserver.enable = true;
      };

      node = { ... }: {
        imports = [ commonConfig oarConfig ];
        services.oar.node.enable = true;
      };
    };

  rolesDistribution = { node = 2; };
}

This compositions can be built and started with the VM flavour using the -C or --composition-flavour option:

nxc build -C oar::vm
nxc start -C oar::vm

Tip

NixOSCompose will build all compositions when -C parameter is not provided in the build phase. Although, the -C parameter is still required for starting.

Step-by-step how-to create your first multi-composition

First, initialize the template wherever you feel like it belongs:

cd somewhere
nxc init -t multi-compositions

You can then edit your compositions (you can learn more over here).

Build everything:

nxc build

Then finally run it:

nxc start -C foo::vm