runNixOps2 :: AttrSet → Effect

Provision interrelated machine configurations and other cloud resources.

NixOps 2 is pre-release software, so this function is also subject to change.



Optional flake (outputs) containing nixopsConfigurations.default.

If you do not use a flake to specify the deployment, set src instead.

If nix is older than 2.4, set nix to a nix package with flake support.


Optional NixOps deployment name.

If your NixOps state file contains a single deployment and you want to select it automatically, you should leave this unset or null.


Use when flake is not set.

This should contain the NixOps network expressions and other files required for the deployment. Unlike some other deployment methods, NixOps needs access to the actual expression files, because it needs to evaluate with non-static arguments like secrets and IP adresses.

Confidential information should not be committed and included here, but inserted via secrets.json and userSetupScript.


Use when flake is not set.

A list of relative file path strings in src that are used as network expressions.

Default: null

Example: ["nixops.nix"]


Default: true

Whether to build the network during the Hercules CI build phase. This ensures that all packages are in the cache and avoids attempting a deployment when some packages can’t be built.


Default: []

Prebuild runs outside of NixOps, which means that some info may be missing. Specify extra network expressions here to fill in or override the missing definitions.


Default: []

Prebuild runs outside of NixOps, which means that some info may be missing.

This lets you fill in arguments like those set witih nixops set-args.


Default: "nixpkgs=${pkgs.path}", where pkgs is the Nixpkgs invocation that included the effects overlay.

Necessary for looking up <nixpkgs> or potentially other locations using angle bracket syntax.


Default: "switch"; performing a full deployment, analogous to nixos-rebuild switch but on all nodes and including resources.

Other valid values besides "switch" are "dry-run", "plan", "build"*, "create", "copy", "dry-activate", "test", "boot".

Note that your agent will not automatically push to the cache for build. prebuild (enabled by default) does take care of this. See also the NixOps deployment guide on prebuilding.


Default: true.

Set to false to make the deploy command fail when a reboot is necessary.


Default: true.

Whether to create cloud resources when they appear to have gone missing.


Default: []

A list of strings that will be passed as extra arguments to nixops deploy.


Default: pkgs.nix

The Nix package to use.


Default: pkgs.nixopsUnstable

The NixOps package to use.


Default: false

Whether it’s ok to delete the state. Only use this on stateless deployments; not on deployments that need the state file to remember IP addresses, cloud resource ids, etc.

This disables an assertion intended to prevent mistakes with cloud deployments.

…​ — remaining arguments

Other attributes are passed to mkEffect, which passes its remaining arguments to mkDerivation.

Return value

An effect that performs the specified action on the NixOps deployment.

The effect has the following attributes in addition to the attributes returned by mkEffect.


A derivation representing the built system configuration.


An attribute set containing the NixOS configurations of the prebuilt nodes.

This is primarily useful for inspection with nix repl.


An attribute set with various attributes, including resources.

This is primarily useful for inspection with nix repl.

See also

  • runNixOps — similar function for NixOps 1.x

  • runNixOS — a simpler solution for single pre-existing machines

  • runArion — deploy services to Docker using NixOS, Nix or Docker-based images