infra/lib/deploy.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

75 lines
1.8 KiB
Nix
Raw Normal View History

2023-10-27 21:06:55 +00:00
/*
2024-05-08 20:57:07 +00:00
The contents of this file are adapted from digga
https://github.com/divnix/digga
Licensed under the MIT license
*/
2023-10-27 21:06:55 +00:00
{ lib, inputs }:
let
# https://github.com/serokell/deploy-rs#overall-usage
system = "x86_64-linux";
pkgs = import inputs.nixpkgs { inherit system; };
deployPkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.deploy-rs.overlay
2024-05-08 20:57:07 +00:00
(self: super: {
deploy-rs = {
inherit (pkgs) deploy-rs;
lib = super.deploy-rs.lib;
};
})
];
};
2024-05-08 20:57:07 +00:00
getFqdn =
c:
2023-10-27 21:06:55 +00:00
let
net = c.config.networking;
fqdn =
2024-05-08 20:57:07 +00:00
if (net ? domain) && (net.domain != null) then "${net.hostName}.${net.domain}" else net.hostName;
2023-10-27 21:06:55 +00:00
in
fqdn;
in
{
2024-05-08 20:57:07 +00:00
mkDeployNodes =
systemConfigurations: extraConfig:
2023-10-27 21:06:55 +00:00
/*
2024-05-08 20:57:07 +00:00
*
Synopsis: mkNodes _systemConfigurations_ _extraConfig_
2023-10-27 21:06:55 +00:00
2024-05-08 20:57:07 +00:00
Generate the `nodes` attribute expected by deploy-rs
where _systemConfigurations_ are `nodes`.
2023-10-27 21:06:55 +00:00
2024-05-08 20:57:07 +00:00
_systemConfigurations_ should take the form of a flake's
_nixosConfigurations_. Note that deploy-rs does not currently support
deploying to darwin hosts.
2023-10-27 21:06:55 +00:00
2024-05-08 20:57:07 +00:00
_extraConfig_, if specified, will be merged into each of the
nodes' configurations.
2023-10-27 21:06:55 +00:00
2024-05-08 20:57:07 +00:00
Example _systemConfigurations_ input:
2023-10-27 21:06:55 +00:00
2024-05-08 20:57:07 +00:00
```
{
hostname-1 = {
fastConnection = true;
sshOpts = [ "-p" "25" ];
};
hostname-2 = {
sshOpts = [ "-p" "19999" ];
sshUser = "root";
};
}
```
*
*/
lib.recursiveUpdate (lib.mapAttrs (_: c: {
hostname = getFqdn c;
profiles.system = {
user = "root";
path = deployPkgs.deploy-rs.lib.activate.nixos c;
};
}) systemConfigurations) extraConfig;
2023-10-27 21:06:55 +00:00
}