What is Colmena
mainnix-instantiate and nix-copy-closure) and supports parallel deployment to multiple hosts. It is modeled after tools like NixOps and morph.repository·main·Indexed 25 days ago
https://github.com/nix-community/colmenaColmena is a stateless NixOS deployment tool written in Rust that acts as a thin wrapper over Nix commands to enable parallel deployment to multiple NixOS nodes. It supports traditional Nix configurations and Nix Flakes, offering features such as node tagging, local deployment via `colmena apply-local`, secrets management through `deployment.keys`, and ad hoc evaluation of configuration values. Version 0.5.0-pre.
nix-instantiate and nix-copy-closure) and supports parallel deployment to multiple hosts. It is modeled after tools like NixOps and morph.Colmena provides several key features for managing NixOS deployments:
deployment and allow you to manage deployment-specific logic within your standard NixOS module definitions.For every secret defined in deployment.keys.<name>, Colmena automatically creates a systemd service named ${name}-key.service.
This service is only active when the corresponding secret file is present on the node. You can use this to create service dependencies, ensuring that services requiring secrets only attempt to start once the secrets are successfully deployed.
A Colmena configuration (a "hive") is typically defined in a .nix file. It consists of three main parts:
meta: Global metadata. Use nixpkgs to pin the Nixpkgs version (accepts a path, a lambda like import <nixpkgs>, or an attribute set). You can also use nodeNixpkgs to provide different Nixpkgs versions per node. If your host allows remote builds, you can specify a machinesFile.defaults: A function that receives pkgs and returns a NixOS module applied to all hosts.nodes parameter (e.g., nodes.host-b.config.time.timeZone).Common deployment options within a host include:
deployment.targetHost: Override the default SSH connection target.deployment.targetPort: Override the SSH port.deployment.targetUser: Specify the SSH user.deployment.tags: A list of strings used for filtering deployments via the CLI.deployment.replaceUnknownProfiles: Boolean to control if unknown remote profiles are replaced during apply.{
meta = {
nixpkgs = <nixpkgs>;
nodeNixpkgs = {
node-b = ./another-nixos-checkout;
};
};
defaults = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ vim wget curl ];
};
host-a = { name, nodes, ... }: {
networking.hostName = name;
time.timeZone = nodes.host-b.config.time.timeZone;
};
host-b = {
deployment.targetHost = "host-b.mydomain.tld";
deployment.targetPort = 1234;
deployment.tags = [ "web" "infra-lax" ];
time.timeZone = "America/Los_Angeles";
};
}Instead of using Colmena-specific logic, you can use Nix's native distributed build feature. When enabled, Nix transparently forwards builds to configured builders and automatically copies the results back to the local machine once complete.
Configuration: Builders can be configured:
meta.machinesFile option.Colmena uses the NixOS test framework for its integration tests. You can execute the full suite of tests by running the nix-build command on the default.nix file in the repository root.
nix-build default.nixIf your expression evaluates to a derivation rather than a plain JSON value, you can use the --instantiate flag to obtain the resulting Nix store path.
$ colmena eval --instantiate -E '{ nodes, ... }: nodes.alpha.config.boot.kernelPackages.kernelThe Colmena manual is rendered using mdBook. You can build it locally using Nix.
To build the full manual:
nix build .#manual
To build a faster version that excludes the CLI usage reference:
nix build .#manualFast
nix build .#manualYou can extract values from your Colmena configuration (the nodes attribute set) to use in other programs by evaluating a .nix file containing a lambda. The lambda receives the standard Colmena arguments: nodes, pkgs, and lib. The result must be a JSON-serializable value.
To evaluate a file, use colmena eval <file.nix>. To evaluate an expression directly from the command line without a file, use the -E flag.
nix shell with the GitHub repository, install it to your user profile via nix-env, or add it as an input to your Flake. An unstable binary cache is available at https://colmena.cachix.org.