fix: add public hostname to ssh config and refactor

This commit is contained in:
2026-02-02 18:34:39 +01:00
parent 4236aa1def
commit c538c5ad08
4 changed files with 35 additions and 34 deletions

View File

@@ -3,6 +3,16 @@
inputs, inputs,
}: }:
let
mkNode = hostname: tags: {
imports = [ ../hosts/${hostname} ];
deployment = {
targetHost = self.nixosConfigurations.${hostname}.config.ssh.publicHostname;
targetUser = self.nixosConfigurations.${hostname}.config.ssh.username;
inherit tags;
};
};
in
inputs.colmena.lib.makeHive { inputs.colmena.lib.makeHive {
meta = { meta = {
nixpkgs = import inputs.nixpkgs { nixpkgs = import inputs.nixpkgs {
@@ -13,35 +23,9 @@ inputs.colmena.lib.makeHive {
nodeSpecialArgs = builtins.mapAttrs (_: v: v._module.specialArgs or { }) self.nixosConfigurations; nodeSpecialArgs = builtins.mapAttrs (_: v: v._module.specialArgs or { }) self.nixosConfigurations;
}; };
astyanax = { astyanax = mkNode "astyanax" [ "local" ];
imports = [ ../hosts/astyanax ]; andromache = mkNode "andromache" [ "local" ];
deployment.tags = [ "local" ]; vm = mkNode "vm" [ "local" ];
}; hecuba = mkNode "hecuba" [ "cloud" ];
eetion = mkNode "eetion" [ "arm" ];
andromache = {
imports = [ ../hosts/andromache ];
deployment.tags = [ "local" ];
};
vm = {
imports = [ ../hosts/vm ];
deployment.tags = [ "local" ];
};
hecuba = {
imports = [ ../hosts/hecuba ];
deployment = {
targetHost = "server.hektormisplon.xyz";
targetUser = "username";
tags = [ "cloud" ];
};
};
eetion = {
imports = [ ../hosts/eetion ];
deployment = {
targetUser = "h";
tags = [ "arm" ];
};
};
} }

View File

@@ -18,8 +18,20 @@ in
enable = true; enable = true;
enableDefaultConfig = false; enableDefaultConfig = false;
matchBlocks = lib.genAttrs hostsWithKeys (hostname: { matchBlocks = lib.genAttrs hostsWithKeys (
host = hostname; hostname:
}); let
hostConfig = outputs.nixosConfigurations.${hostname}.config;
publicHostname = hostConfig.ssh.publicHostname;
targetUser = hostConfig.ssh.username;
in
{
host = hostname;
user = targetUser;
}
// lib.optionalAttrs (publicHostname != "") {
hostname = publicHostname;
}
);
}; };
} }

View File

@@ -24,6 +24,7 @@ in
networking.hostName = hostName; networking.hostName = hostName;
ssh.username = username; ssh.username = username;
ssh.publicHostname = "server.hektormisplon.xyz";
ssh.authorizedHosts = [ ssh.authorizedHosts = [
"andromache" "andromache"
"astyanax" "astyanax"

View File

@@ -9,6 +9,10 @@
type = lib.types.str; type = lib.types.str;
default = "h"; default = "h";
}; };
publicHostname = lib.mkOption {
type = lib.types.str;
default = "";
};
}; };
# auto generate authorized_keys from `authorizedHosts` # auto generate authorized_keys from `authorizedHosts`