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; }; utils = import ../utils { inherit lib; };
hostDirNames = utils.dirNames ../hosts; hostDirNames = utils.dirNames ../hosts;
mkNode = hostname: tags: { mkNode = hostname: meta: {
imports = [ ../hosts/${hostname} ]; imports = [ ../hosts/${hostname} ];
deployment = { deployment = {
targetHost = self.nixosConfigurations.${hostname}.config.ssh.publicHostname; inherit (meta.deployment) targetHost targetUser tags;
targetUser = self.nixosConfigurations.${hostname}.config.host.username; buildOnTarget = builtins.any (t: t != "local" && t != "arm") meta.deployment.tags;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") tags;
inherit tags;
}; };
}; };
nodes = lib.genAttrs hostDirNames ( nodes = lib.genAttrs hostDirNames (hostname: mkNode hostname (utils.hostMeta ../hosts/${hostname}));
hostname: mkNode hostname (utils.hostMeta ../hosts/${hostname}).deployment.tags
);
in in
inputs.colmena.lib.makeHive ( inputs.colmena.lib.makeHive (
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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