refactor: merge 'host.nix' into 'meta.nix'

This commit is contained in:
2026-06-12 20:30:08 +02:00
parent c7567330b8
commit 1995c04b1d
21 changed files with 78 additions and 84 deletions

View File

@@ -8,16 +8,24 @@ let
utils = import ../utils { inherit lib; }; utils = import ../utils { inherit lib; };
hostnames = utils.dirNames ../hosts; hostnames = utils.dirNames ../hosts;
mkNode = hostname: meta: { mkNode =
hostname:
let
meta = utils.hostMeta ../hosts/${hostname};
isLocal = builtins.elem "local" meta.tags;
in
{
imports = [ ../hosts/${hostname} ]; imports = [ ../hosts/${hostname} ];
host.name = hostname; host.name = hostname;
deployment = { deployment = {
inherit (meta.deployment) targetHost targetUser tags; inherit (meta) tags;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") meta.deployment.tags; targetUser = meta.host.username;
targetHost = if isLocal then "" else hostname;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") meta.tags;
}; };
}; };
nodes = lib.genAttrs hostnames (hostname: mkNode hostname (utils.hostMeta ../hosts/${hostname})); nodes = lib.genAttrs hostnames mkNode;
in in
inputs.colmena.lib.makeHive ( inputs.colmena.lib.makeHive (
{ {

View File

@@ -29,12 +29,13 @@ in
hostname: hostname:
let let
meta = myUtils.hostMeta (hostDir + "/${hostname}"); meta = myUtils.hostMeta (hostDir + "/${hostname}");
isLocal = builtins.elem "local" meta.tags;
in in
{ {
User = meta.deployment.targetUser; User = meta.host.username;
} }
// lib.optionalAttrs (meta.deployment.targetHost != "") { // lib.optionalAttrs (!isLocal) {
HostName = meta.deployment.targetHost; HostName = hostname;
} }
) )
// { // {

View File

@@ -7,13 +7,13 @@
}: }:
let let
meta = import ./meta.nix;
wolInterfaces = import ./wol-interfaces.nix; wolInterfaces = import ./wol-interfaces.nix;
in in
{ {
imports = [ imports = [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
./hard.nix ./hard.nix
./host.nix
inputs.nixos-hardware.nixosModules.common-cpu-intel inputs.nixos-hardware.nixosModules.common-cpu-intel
inputs.nixos-hardware.nixosModules.common-pc inputs.nixos-hardware.nixosModules.common-pc
inputs.nixos-hardware.nixosModules.common-pc-ssd inputs.nixos-hardware.nixosModules.common-pc-ssd
@@ -24,6 +24,8 @@ in
}) })
]; ];
inherit (meta) host;
home-manager.users.${config.host.username} = import ../../home/hosts/${config.host.name}; home-manager.users.${config.host.username} = import ../../home/hosts/${config.host.name};
"ai-tools".enable = true; "ai-tools".enable = true;

View File

@@ -1,7 +0,0 @@
{
host = {
username = "h";
highRam = true;
admin = true;
};
}

View File

@@ -1,9 +1,10 @@
{ {
system = "x86_64-linux"; system = "x86_64-linux";
deployment = {
tags = [ "local" ];
targetHost = "";
targetUser = "h";
};
role = "desktop"; role = "desktop";
tags = [ "local" ];
host = {
username = "h";
highRam = true;
admin = true;
};
} }

View File

@@ -6,11 +6,13 @@
... ...
}: }:
let
meta = import ./meta.nix;
in
{ {
imports = [ imports = [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
./hard.nix ./hard.nix
./host.nix
inputs.nixos-hardware.nixosModules.common-pc inputs.nixos-hardware.nixosModules.common-pc
inputs.nixos-hardware.nixosModules.common-pc-ssd inputs.nixos-hardware.nixosModules.common-pc-ssd
# inputs.nixos-hardware.nixosModules.lenovo-thinkpad-e14-intel-gen7 (not available yet?) # inputs.nixos-hardware.nixosModules.lenovo-thinkpad-e14-intel-gen7 (not available yet?)
@@ -21,6 +23,8 @@
}) })
]; ];
inherit (meta) host;
home-manager.users.${config.host.username} = import ../../home/hosts/${config.host.name}; home-manager.users.${config.host.username} = import ../../home/hosts/${config.host.name};
"ai-tools".enable = true; "ai-tools".enable = true;

View File

@@ -1,7 +0,0 @@
{
host = {
username = "h";
highRam = true;
admin = true;
};
}

View File

@@ -1,9 +1,10 @@
{ {
system = "x86_64-linux"; system = "x86_64-linux";
deployment = {
tags = [ "local" ];
targetHost = "";
targetUser = "h";
};
role = "laptop"; role = "laptop";
tags = [ "local" ];
host = {
username = "h";
highRam = true;
admin = true;
};
} }

View File

@@ -3,13 +3,17 @@
# Raspberry Pi 3 # Raspberry Pi 3
# See <https://nixos.wiki/wiki/NixOS_on_ARM/Raspberry_Pi_3> # See <https://nixos.wiki/wiki/NixOS_on_ARM/Raspberry_Pi_3>
let
meta = import ./meta.nix;
in
{ {
imports = [ imports = [
./hard.nix ./hard.nix
./host.nix
../../modules ../../modules
]; ];
inherit (meta) host;
ssh.enable = true; ssh.enable = true;
boot = { boot = {

View File

@@ -1,5 +0,0 @@
{
host = {
username = "h";
};
}

View File

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

View File

@@ -3,13 +3,17 @@
# Orange Pi Zero2 H616 # Orange Pi Zero2 H616
# See <https://nixos.wiki/wiki/NixOS_on_ARM/Orange_Pi_Zero2_H616> # See <https://nixos.wiki/wiki/NixOS_on_ARM/Orange_Pi_Zero2_H616>
let
meta = import ./meta.nix;
in
{ {
imports = [ imports = [
./hard.nix ./hard.nix
./host.nix
../../modules ../../modules
]; ];
inherit (meta) host;
ssh.enable = true; ssh.enable = true;
tailscale.enable = true; tailscale.enable = true;

View File

@@ -1,5 +0,0 @@
{
host = {
username = "h";
};
}

View File

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

View File

@@ -7,16 +7,19 @@
# also see <https://wiki.nixos.org/wiki/Install_NixOS_on_Hetzner_Cloud> # also see <https://wiki.nixos.org/wiki/Install_NixOS_on_Hetzner_Cloud>
let
meta = import ./meta.nix;
in
{ {
imports = [ imports = [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
./hard.nix ./hard.nix
inputs.comin.nixosModules.comin inputs.comin.nixosModules.comin
./host.nix
../../modules ../../modules
]; ];
docker.enable = true; inherit (meta) host;
ssh.enable = true; ssh.enable = true;
tailscale.enable = true; tailscale.enable = true;

View File

@@ -1,5 +0,0 @@
{
host = {
username = "username";
};
}

View File

@@ -1,9 +1,8 @@
{ {
system = "x86_64-linux"; system = "x86_64-linux";
deployment = {
tags = [ "cloud" ];
targetHost = "hecuba";
targetUser = "username";
};
role = "server"; role = "server";
tags = [ "cloud" ];
host = {
username = "username";
};
} }

View File

@@ -3,15 +3,19 @@
config, config,
... ...
}: }:
let
meta = import ./meta.nix;
in
{ {
imports = [ imports = [
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
./hard.nix ./hard.nix
./host.nix
./disk.nix ./disk.nix
../../modules ../../modules
]; ];
inherit (meta) host;
home-manager.users.${config.host.username} = import ../../home/hosts/vm; home-manager.users.${config.host.username} = import ../../home/hosts/vm;
"ai-tools".enable = true; "ai-tools".enable = true;

View File

@@ -1,5 +0,0 @@
{
host = {
username = "h";
};
}

View File

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

View File

@@ -9,11 +9,11 @@ in
if builtins.pathExists (hostDir + "/meta.nix") then if builtins.pathExists (hostDir + "/meta.nix") then
import (hostDir + "/meta.nix") import (hostDir + "/meta.nix")
else else
throw "meta.nix required in ${hostDir}"; throw "meta.nix required in ${toString hostDir}";
adminHosts = adminHosts =
hostsPath: hostsPath:
builtins.filter (host: ((import (hostsPath + "/${host}/host.nix")).host.admin or false)) ( builtins.filter (host: ((import (hostsPath + "/${host}/meta.nix")).host.admin or false)) (
fs.dirNames hostsPath fs.dirNames hostsPath
); );
} }