2023-07-08 14:27:43 +00:00
---
title: Declarative host management
---
= Declarative host management
This project uses a custom setup for declarative host management.
2024-01-16 12:07:58 +00:00
It is a custom github:hercules-ci/flake-parts[opts=repo] module that allows you to easily initialize NixOS systems of multiple platforms (with multiple images output) while making it purely-built as much as possible.
2023-07-08 14:27:43 +00:00
2024-01-16 12:07:58 +00:00
This custom flake-parts modules integrates the following projects:
2024-01-20 09:24:26 +00:00
* It automatically adds github:serokell/deploy-rs[opts=repo] nodes ready to be deployed with `deploy` CLI tool when given the right parameters.
2024-01-16 12:07:58 +00:00
* Mandatory inclusion of github:nix-community/home-manager[opts=repo].
* Image output generation made easy with github:nix-community/nixos-generators[opts=repo].
Each of the declared hosts are then exported either as part of the `images` or `nixosConfigurations` (or both) flake output attribute.
The `images` flake output attribute contains a per-system set of packages of the NixOS systems as the indicated package format.
2023-07-26 10:05:22 +00:00
For example, you can build my personalized NixOS installer ISO with the following command.
[source, shell, subs=attributes]
----
2024-01-20 09:24:26 +00:00
nix build {canonical-flake-url}#images.x86_64-linux.bootstrap-install-iso
2023-07-26 10:05:22 +00:00
----
2024-01-20 09:24:26 +00:00
The following code listing is an example of a declarative NixOS setup.
It should have the following effects in the flake output:
2024-01-16 12:07:58 +00:00
* Two additional NixOS configurations to be deployed at `nixosConfigurations.plover-{x86_64-linux,aarch64-linux}`.
By default, declarative NixOS setups are not added automatically to `nixosConfigurations` output unless we have `configs.<config>.formats = null;` but we did configure `configs.<config>.deploy` so that makes it even.
2023-12-26 01:59:34 +00:00
2024-01-16 12:07:58 +00:00
* Four additional derivations added in `images` flake output (since there's 2 formats and 2 platforms) at `images.{x86_64-linux,aarch64-linux}.plover-{do,gce}`.
2023-07-08 14:27:43 +00:00
[#lst:images-metadata-example]
2023-12-23 12:32:08 +00:00
[source, nix]
2023-07-08 14:27:43 +00:00
----
2023-12-23 12:32:08 +00:00
{
2024-01-16 12:07:58 +00:00
setups.nixos.configs.plover = {
2023-12-23 12:32:08 +00:00
systems = [ "x86_64-linux" "aarch64-linux" ];
2024-01-16 12:07:58 +00:00
formats = [ "do" "gce" ];
2023-12-23 12:32:08 +00:00
domain = "foodogsquared.one";
2024-01-20 09:24:26 +00:00
nixpkgsBranch = "nixos-unstable-small";
homeManagerBranch = "home-manager-unstable";
2023-12-23 12:32:08 +00:00
modules = [
({ config, lib, ... }: {
services.foo.enable = true;
})
];
2024-01-16 12:07:58 +00:00
overlays = [
inputs.neovim-nightly-overlay.overlays.default
];
2023-12-23 12:32:08 +00:00
deploy = {
2024-01-16 12:07:58 +00:00
fastConnection = true;
autoRollback = true;
magicRollback = true;
remoteBuild = true;
profiles = os: {
system = {
sshUser = "root";
user = "admin";
path = inputs.deploy.lib.${os.system}.activate.nixos os.config;
};
};
2023-12-23 12:32:08 +00:00
};
};
}
2023-07-08 14:27:43 +00:00
----