nixcfg/lib/deploy/default.nix

58 lines
1.4 KiB
Nix
Raw Normal View History

2024-03-21 15:00:36 +01:00
{ lib, inputs }:
let
inherit (inputs) deploy-rs;
in
rec {
## Create deployment configuration for use with deploy-rs.
##
## ```nix
## mkDeploy {
## inherit self;
## overrides = {
## my-host.system.sudo = "doas -u";
## };
## }
## ```
##
#@ { self: Flake, overrides: Attrs ? {} } -> Attrs
mkDeploy =
{
self,
overrides ? { },
}:
2024-03-21 15:00:36 +01:00
let
hosts = self.nixosConfigurations or { };
names = builtins.attrNames hosts;
nodes = lib.foldl (
result: name:
let
host = hosts.${name};
user = host.config.metacfg.user.name or null;
inherit (host.pkgs) system;
in
result
// {
${name} = (overrides.${name} or { }) // {
hostname = overrides.${name}.hostname or "${name}";
profiles = (overrides.${name}.profiles or { }) // {
system =
(overrides.${name}.profiles.system or { })
// {
2024-03-21 15:00:36 +01:00
path = deploy-rs.lib.${system}.activate.nixos host;
}
// lib.optionalAttrs (user != null) {
2024-03-21 15:00:36 +01:00
user = "root";
sshUser = user;
}
// lib.optionalAttrs (host.config.metacfg.security.doas.enable or false) { sudo = "doas -u"; };
2024-03-21 15:00:36 +01:00
};
};
}
) { } names;
2024-03-21 15:00:36 +01:00
in
{
inherit nodes;
};
2024-03-21 15:00:36 +01:00
}