refactor(deploy): move deployment config into '<host>/meta.nix'

This commit is contained in:
2026-04-21 16:43:36 +02:00
parent 6a30a431f8
commit 583b9ea5f3
12 changed files with 43 additions and 34 deletions

View File

@@ -8,19 +8,15 @@ let
utils = import ../utils { inherit lib; };
hostDirNames = utils.dirNames ../hosts;
mkNode = hostname: tags: {
mkNode = hostname: meta: {
imports = [ ../hosts/${hostname} ];
deployment = {
targetHost = self.nixosConfigurations.${hostname}.config.ssh.publicHostname;
targetUser = self.nixosConfigurations.${hostname}.config.host.username;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") tags;
inherit tags;
inherit (meta.deployment) targetHost targetUser tags;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") meta.deployment.tags;
};
};
nodes = lib.genAttrs hostDirNames (
hostname: mkNode hostname (utils.hostMeta ../hosts/${hostname}).deployment.tags
);
nodes = lib.genAttrs hostDirNames (hostname: mkNode hostname (utils.hostMeta ../hosts/${hostname}));
in
inputs.colmena.lib.makeHive (
{

View File

@@ -1,18 +1,15 @@
{
outputs,
myUtils,
lib,
pkgs,
...
}:
let
nixosConfigs = builtins.attrNames outputs.nixosConfigurations;
homeConfigs = map (n: lib.last (lib.splitString "@" n)) (
builtins.attrNames outputs.homeConfigurations
);
allHosts = lib.unique (homeConfigs ++ nixosConfigs);
hostDir = ../../hosts;
hostNames = myUtils.dirNames hostDir;
hostsWithKeys = lib.filter (
hostname: builtins.pathExists ../../hosts/${hostname}/ssh_host.pub
) allHosts;
hostname: builtins.pathExists (hostDir + "/${hostname}/ssh_host.pub")
) hostNames;
in
{
home.packages = with pkgs; [ sshfs ];
@@ -25,15 +22,14 @@ in
lib.genAttrs hostsWithKeys (
hostname:
let
hostConfig = outputs.nixosConfigurations.${hostname}.config;
inherit (hostConfig.ssh) publicHostname username;
meta = myUtils.hostMeta (hostDir + "/${hostname}");
in
{
host = hostname;
user = username;
user = meta.deployment.targetUser;
}
// lib.optionalAttrs (publicHostname != "") {
hostname = publicHostname;
// lib.optionalAttrs (meta.deployment.targetHost != "") {
hostname = meta.deployment.targetHost;
}
)
// {

View File

@@ -1,5 +1,9 @@
{
system = "x86_64-linux";
deployment.tags = [ "local" ];
deployment = {
tags = [ "local" ];
targetHost = "";
targetUser = "h";
};
role = "desktop";
}

View File

@@ -1,5 +1,9 @@
{
system = "x86_64-linux";
deployment.tags = [ "local" ];
deployment = {
tags = [ "local" ];
targetHost = "";
targetUser = "h";
};
role = "laptop";
}

View File

@@ -12,7 +12,6 @@
];
ssh = {
publicHostname = config.host.name;
authorizedHosts = [
"andromache"
"astyanax"

View File

@@ -1,5 +1,9 @@
{
system = "aarch64-linux";
deployment.tags = [ "arm" ];
deployment = {
tags = [ "arm" ];
targetHost = "eetion-02";
targetUser = "h";
};
role = "embedded";
}

View File

@@ -13,7 +13,6 @@
];
ssh = {
publicHostname = config.host.name;
authorizedHosts = [
"andromache"
"astyanax"

View File

@@ -1,5 +1,9 @@
{
system = "aarch64-linux";
deployment.tags = [ "arm" ];
deployment = {
tags = [ "arm" ];
targetHost = "eetion";
targetUser = "h";
};
role = "embedded";
}

View File

@@ -19,7 +19,6 @@
networking.hostName = config.host.name;
ssh = {
publicHostname = "server.hektormisplon.xyz";
authorizedHosts = [
"andromache"
"astyanax"

View File

@@ -1,5 +1,9 @@
{
system = "x86_64-linux";
deployment.tags = [ "cloud" ];
deployment = {
tags = [ "cloud" ];
targetHost = "server.hektormisplon.xyz";
targetUser = "username";
};
role = "server";
}

View File

@@ -1,5 +1,9 @@
{
system = "x86_64-linux";
deployment.tags = [ "local" ];
deployment = {
tags = [ "local" ];
targetHost = "";
targetUser = "h";
};
role = "vm";
}

View File

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