2022-02-20 20:16:49 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
2022-02-19 22:55:53 +00:00
|
|
|
let
|
|
|
|
inherit (builtins) head;
|
2022-02-20 20:16:49 +00:00
|
|
|
inherit (lib) mkMerge mkIf mkDefault;
|
2022-02-19 22:55:53 +00:00
|
|
|
inherit (lib.my) mkOpt' mkBoolOpt';
|
|
|
|
|
|
|
|
cfg = config.my.deploy;
|
|
|
|
in
|
|
|
|
{
|
2022-02-20 20:16:49 +00:00
|
|
|
options.my.deploy = with lib.types; {
|
2022-02-19 22:55:53 +00:00
|
|
|
authorizedKeys = {
|
|
|
|
keys = mkOpt' (listOf singleLineStr) [ ] "SSH public keys to add to the default deployment user.";
|
2022-02-22 00:59:57 +00:00
|
|
|
keyFiles = mkOpt' (listOf path) [ lib.my.sshKeyFiles.deploy ] "SSH public key files to add to the default deployment user.";
|
2022-02-19 22:55:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enable = mkBoolOpt' true "Whether to expose deploy-rs configuration for this system.";
|
2022-02-20 20:16:49 +00:00
|
|
|
inherit (lib.my.deploy-rs) node;
|
2022-02-19 22:55:53 +00:00
|
|
|
|
|
|
|
generate = {
|
|
|
|
system.enable = mkBoolOpt' true "Whether to generate a deploy-rs profile for this system's config.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
{
|
2022-02-20 20:16:49 +00:00
|
|
|
my.deploy.enable = mkIf config.my.build.isDevVM false;
|
|
|
|
}
|
|
|
|
(mkIf cfg.enable {
|
|
|
|
my.deploy.node = {
|
|
|
|
hostname = mkDefault config.networking.fqdn;
|
|
|
|
profiles = {
|
|
|
|
system = mkIf cfg.generate.system.enable {
|
|
|
|
path = pkgs.deploy-rs.lib.activate.nixos { inherit config; };
|
2022-02-19 22:55:53 +00:00
|
|
|
|
2022-02-20 20:16:49 +00:00
|
|
|
user = "root";
|
2022-02-19 22:55:53 +00:00
|
|
|
};
|
|
|
|
};
|
2022-02-20 20:16:49 +00:00
|
|
|
|
|
|
|
sshUser = "deploy";
|
|
|
|
user = mkDefault "root";
|
|
|
|
sudo = mkDefault (if config.security.doas.enable then "doas -u" else "sudo -u");
|
|
|
|
sshOpts = mkDefault [ "-p" (toString (head config.services.openssh.ports)) ];
|
2022-02-19 22:55:53 +00:00
|
|
|
};
|
2022-02-20 20:16:49 +00:00
|
|
|
|
2022-02-19 22:55:53 +00:00
|
|
|
users = {
|
|
|
|
users."${cfg.node.sshUser}" = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.node.sshUser;
|
|
|
|
extraGroups = mkDefault [ "wheel" ];
|
|
|
|
shell = pkgs.bash;
|
|
|
|
openssh.authorizedKeys = cfg.authorizedKeys;
|
|
|
|
};
|
|
|
|
groups."${cfg.node.sshUser}" = {};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
}
|