NixOps: Difference between revisions
imported>Nix m add Nix category |
m Alter formulation in warning slightly |
||
(10 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
'''NixOps''' is a tool for deploying NixOS systems in a reproducible and declarative manner. It allows users to manage and deploy entire NixOS-based infrastructures, whether to cloud platforms, virtual machines, or physical hardware. | |||
{{warning|'''at this time NixOps is not actively recommended for new projects or users'''. The tool is undergoing a significant transition between major versions, which has led to some instability and increased complexity in getting it up and running. As of August 2024, it requires extra effort to set up and maintain, and it might not offer a smooth experience. See [https://github.com/NixOS/nixops/issues/1574 nixops #1574] for updates and details or check out the [https://github.com/nixops4/nixops4 nixops4] project.}} | |||
NixOps allows users to declaratively specify the desired configuration of their systems and then automatically performs all necessary actions to realize that configuration. This includes tasks such as instantiating cloud machines, managing dependencies, and provisioning resources. NixOps is meant to be fully automated and to create reproducible deployments that leverage the Nix package manager’s purely functional model, creating consistency in the configuration and providing reliability across various environments. | |||
For further details, please refer to the [https://nixos.org/nixops/manual/ NixOps manual], which provides an overview of its functionality and features, as well as an up-to-date installation guide. | |||
== Example Configuration == | |||
This example demonstrates a basic NixOps configuration that sets up a staging environment with two machines: a reverse proxy and an application server running a git server (Forgejo). This example assumes that both machines already exist, that SSH in the operator's machine is well configured to reach them, and that both machines are running NixOS. The [[Overview of the Nix Language|nix language]] allows referencing the configuration of other machines using the <code>nodes</code> argument, making it easy to link services across the network. | |||
<syntaxhighlight lang="nix"> | |||
# network-staging.nix file | |||
let | |||
proxyHostname = "proxy.example.com"; | |||
gitHostname = "10.0.0.2"; | |||
in { | |||
network.description = "Staging environment for our git setup"; | |||
defaults.imports = [ ./common.nix ]; | |||
reverse-proxy = { nodes, ... }: { | |||
deployment.targetHost = proxyHostname; | |||
services.nginx = { | |||
enable = true; | |||
virtualHosts."example.com".locations."/" = { | |||
proxyPass = "http://${gitHostname}:${nodes.gitServer.config.services.forgejo.port}"; | |||
}; | |||
}; | |||
# the rest of reverse-proxy's configuration can be added here | |||
}; | |||
gitServer = _: { | |||
deployment.targetHost = gitHostname; | |||
services.forgejo.enable = true; | |||
# additional git server configuration can be added here | |||
}; | |||
} | |||
</syntaxhighlight> | |||
=== Invocation === | |||
To apply this configuration on both nodes, one must first create a deployment with the <code>nixops create</code> command, and then apply the new configuration with <code>nixops deploy</code>. | |||
<syntaxhighlight lang="bash"> | |||
nixops create network-staging.nix -d staging | |||
> created deployment ‘32b06868-d27c-11e2-a055-81d7beb7925e’ | |||
nixops deploy -d staging | |||
</syntaxhighlight> | |||
== External links == | |||
= | * [https://nixos.org/manual/nixops/stable/ The NixOps Manual] | ||
* [https://www.youtube.com/watch?v=SoHtccHNOJ8 A presentation on NixOps by Kim Lindberger (talyz) - Oslo NixOS MiniCon, March 2020] | |||
* [https://eno.space/blog/2021/08/nixos-on-underpowered-devices An example of cross-building for ARM and x86_64 using nixops] | |||
== | == See also == | ||
* [[krops]] | |||
* [[morph]] | |||
* [[nix-deploy]] | |||
* [[Colmena]] | |||
[[Category:Pedias]] | [[Category:Pedias]] | ||
[[Category:NixOps]] | [[Category:NixOps]] | ||
[[Category: | [[Category:Deployment]] | ||
[[Category:Server]] | [[Category:Server]] | ||
[[Category:Incomplete]] | [[Category:Incomplete]] |
Latest revision as of 20:05, 11 November 2024
NixOps is a tool for deploying NixOS systems in a reproducible and declarative manner. It allows users to manage and deploy entire NixOS-based infrastructures, whether to cloud platforms, virtual machines, or physical hardware.
NixOps allows users to declaratively specify the desired configuration of their systems and then automatically performs all necessary actions to realize that configuration. This includes tasks such as instantiating cloud machines, managing dependencies, and provisioning resources. NixOps is meant to be fully automated and to create reproducible deployments that leverage the Nix package manager’s purely functional model, creating consistency in the configuration and providing reliability across various environments.
For further details, please refer to the NixOps manual, which provides an overview of its functionality and features, as well as an up-to-date installation guide.
Example Configuration
This example demonstrates a basic NixOps configuration that sets up a staging environment with two machines: a reverse proxy and an application server running a git server (Forgejo). This example assumes that both machines already exist, that SSH in the operator's machine is well configured to reach them, and that both machines are running NixOS. The nix language allows referencing the configuration of other machines using the nodes
argument, making it easy to link services across the network.
# network-staging.nix file
let
proxyHostname = "proxy.example.com";
gitHostname = "10.0.0.2";
in {
network.description = "Staging environment for our git setup";
defaults.imports = [ ./common.nix ];
reverse-proxy = { nodes, ... }: {
deployment.targetHost = proxyHostname;
services.nginx = {
enable = true;
virtualHosts."example.com".locations."/" = {
proxyPass = "http://${gitHostname}:${nodes.gitServer.config.services.forgejo.port}";
};
};
# the rest of reverse-proxy's configuration can be added here
};
gitServer = _: {
deployment.targetHost = gitHostname;
services.forgejo.enable = true;
# additional git server configuration can be added here
};
}
Invocation
To apply this configuration on both nodes, one must first create a deployment with the nixops create
command, and then apply the new configuration with nixops deploy
.
nixops create network-staging.nix -d staging
> created deployment ‘32b06868-d27c-11e2-a055-81d7beb7925e’
nixops deploy -d staging
External links
- The NixOps Manual
- A presentation on NixOps by Kim Lindberger (talyz) - Oslo NixOS MiniCon, March 2020
- An example of cross-building for ARM and x86_64 using nixops