refactor: add config.host option for host variables

This commit is contained in:
2026-03-11 21:53:47 +01:00
parent 4c9db2b822
commit 43dff3e8e5
10 changed files with 89 additions and 72 deletions

View File

@@ -5,9 +5,6 @@
...
}:
let
username = "h";
in
{
imports = [
../../modules
@@ -35,8 +32,8 @@ in
home = {
stateVersion = "25.05";
inherit username;
homeDirectory = "/home/${username}";
username = config.host.username;
homeDirectory = "/home/${config.host.username}";
};
xdg.userDirs.createDirectories = false;

View File

@@ -4,9 +4,6 @@
...
}:
let
username = "h";
in
{
imports = [
../../modules
@@ -33,8 +30,8 @@ in
home = {
stateVersion = "25.05";
inherit username;
homeDirectory = "/home/${username}";
username = config.host.username;
homeDirectory = "/home/${config.host.username}";
};
xdg.userDirs.createDirectories = false;

View File

@@ -7,8 +7,6 @@
}:
let
username = "h";
hostName = "andromache";
wolInterfaces = import ./wol-interfaces.nix;
in
{
@@ -30,7 +28,7 @@ in
../../modules/bluetooth
../../modules/gaming
../../modules/keyboard
(import ../../modules/networking { inherit hostName; })
(import ../../modules/networking { hostName = config.host.name; })
../../modules/users
../../modules/audio
../../modules/localization
@@ -45,7 +43,12 @@ in
../../modules/yubikey
];
home-manager.users.${username} = import ../../home/hosts/andromache {
host = {
username = "h";
name = "andromache";
};
home-manager.users.${config.host.username} = import ../../home/hosts/andromache {
inherit
inputs
config
@@ -54,13 +57,11 @@ in
;
};
networking.hostName = hostName;
ssh.username = username;
ssh.username = config.host.username;
ssh.authorizedHosts = [ "astyanax" ];
secrets.username = username;
docker.user = username;
secrets.username = config.host.username;
docker.user = config.host.username;
nix.settings.secret-key-files = [ config.sops.secrets.nix_signing_key_andromache.path ];
@@ -94,7 +95,7 @@ in
my.yubikey = {
enable = false;
inherit username;
username = config.host.username;
keys = [
{
handle = "<KeyHandle1>";

View File

@@ -6,8 +6,6 @@
...
}:
let
username = "h";
hostName = "astyanax";
wolInterfaces = import ../andromache/wol-interfaces.nix;
in
{
@@ -30,7 +28,7 @@ in
../../modules/backups
../../modules/bluetooth
../../modules/keyboard
(import ../../modules/networking { inherit hostName; })
(import ../../modules/networking { hostName = config.host.name; })
../../modules/users
../../modules/localization
../../modules/fonts
@@ -42,7 +40,12 @@ in
../../modules/nfc
];
home-manager.users.${username} = import ../../home/hosts/astyanax {
host = {
username = "h";
name = "astyanax";
};
home-manager.users.${config.host.username} = import ../../home/hosts/astyanax {
inherit
inputs
config
@@ -51,14 +54,12 @@ in
;
};
networking.hostName = hostName;
ssh.username = username;
ssh.username = config.host.username;
ssh.authorizedHosts = [ "andromache" ];
secrets.username = username;
docker.user = username;
nfc.user = username;
secrets.username = config.host.username;
docker.user = config.host.username;
nfc.user = config.host.username;
desktop.ly.enable = true;
nix.settings.secret-key-files = [ config.sops.secrets.nix_signing_key_astyanax.path ];

View File

@@ -1,21 +1,23 @@
{ pkgs, ... }:
{ pkgs, config, ... }:
# Raspberry Pi 3
# See <https://nixos.wiki/wiki/NixOS_on_ARM/Raspberry_Pi_3>
let
username = "h";
hostName = "eetion-02";
in
{
imports = [
./hard.nix
../../modules/ssh
../../modules/common
];
host = {
username = "h";
name = "eetion-02";
};
ssh = {
inherit username;
publicHostname = "eetion-02";
username = config.host.username;
publicHostname = config.host.name;
authorizedHosts = [
"andromache"
"astyanax"
@@ -38,7 +40,7 @@ in
hardware.enableRedistributableFirmware = true;
networking = {
inherit hostName;
hostName = config.host.name;
networkmanager.enable = true;
firewall = {
enable = true;
@@ -51,7 +53,7 @@ in
users.users = {
root.hashedPassword = "!";
${username} = {
${config.host.username} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};

View File

@@ -1,22 +1,24 @@
{ pkgs, ... }:
{ pkgs, config, ... }:
# Orange Pi Zero2 H616
# See <https://nixos.wiki/wiki/NixOS_on_ARM/Orange_Pi_Zero2_H616>
let
username = "h";
hostName = "eetion";
in
{
imports = [
./hard.nix
../../modules/ssh
../../modules/common
# ../../modules/uptime-kuma
];
host = {
username = "h";
name = "eetion";
};
ssh = {
inherit username;
publicHostname = "eetion";
username = config.host.username;
publicHostname = config.host.name;
authorizedHosts = [
"andromache"
"astyanax"
@@ -29,7 +31,7 @@ in
};
networking = {
inherit hostName;
hostName = config.host.name;
networkmanager.enable = true;
firewall = {
enable = true;
@@ -44,7 +46,7 @@ in
users.users = {
root.hashedPassword = "!";
${username} = {
${config.host.username} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
@@ -57,19 +59,19 @@ in
enable = true;
passwordFile = "/etc/paperless-admin-pass";
settings = {
PAPERLESS_URL = "http://paperless.eetion";
PAPERLESS_URL = "http://paperless.${config.host.name}";
};
};
# added (OPNSense) domain override to make this work on LAN
#
# host: eetion
# host: <host-name>
# domain: <domain (e.g. lan)>
# ip address: <eetion-ip>
# ip address: <host-ip>
#
# host: paperless
# domain: eetion
# ip address: <eetion-ip>
# domain: <host-name>
# ip address: <host-ip>
nginx = {
enable = true;
recommendedGzipSettings = true;
@@ -78,13 +80,13 @@ in
recommendedTlsSettings = true;
virtualHosts = {
"eetion" = {
"${config.host.name}" = {
default = true;
locations."/" = {
proxyPass = "http://127.0.0.1:5006";
};
};
"paperless.eetion" = {
"paperless.${config.host.name}" = {
locations."/" = {
proxyPass = "http://127.0.0.1:28981";
};

View File

@@ -1,15 +1,12 @@
{
inputs,
pkgs,
config,
...
}:
# Also see <https://wiki.nixos.org/wiki/Install_NixOS_on_Hetzner_Cloud>
let
username = "username";
hostName = "hecuba";
in
{
imports = [
inputs.disko.nixosModules.disko
@@ -19,9 +16,14 @@ in
../../modules/docker
];
networking.hostName = hostName;
host = {
username = "username";
name = "hecuba";
};
networking.hostName = config.host.name;
ssh = {
inherit username;
username = config.host.username;
publicHostname = "server.hektormisplon.xyz";
authorizedHosts = [
"andromache"
@@ -29,7 +31,7 @@ in
];
};
docker.user = username;
docker.user = config.host.username;
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
@@ -50,7 +52,7 @@ in
users.users = {
root.hashedPassword = "!";
username = {
${config.host.username} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};

View File

@@ -5,10 +5,6 @@
pkgs,
...
}:
let
username = "h";
hostName = "vm";
in
{
imports = [
inputs.disko.nixosModules.disko
@@ -18,7 +14,7 @@ in
./disk.nix
../../modules/boot/bootloader.nix
../../modules/keyboard
(import ../../modules/networking { inherit hostName; })
(import ../../modules/networking { hostName = config.host.name; })
../../modules/users
../../modules/audio
../../modules/localization
@@ -31,14 +27,19 @@ in
})
];
home-manager.users.${username} = import ../../home/hosts/vm {
host = {
username = "h";
name = "vm";
};
home-manager.users.${config.host.username} = import ../../home/hosts/vm {
inherit inputs config pkgs;
};
networking.hostName = hostName;
ssh.username = username;
networking.hostName = config.host.name;
ssh.username = config.host.username;
secrets.username = username;
secrets.username = config.host.username;
disko = {
devices.disk.main = {

View File

@@ -12,6 +12,7 @@ in
{
imports = [
inputs.home-manager.nixosModules.default
./host.nix
];
options.nixpkgs.allowedUnfree = lib.mkOption {

13
modules/common/host.nix Normal file
View File

@@ -0,0 +1,13 @@
{ lib, ... }:
{
options.host = {
username = lib.mkOption {
type = lib.types.str;
};
name = lib.mkOption {
type = lib.types.str;
};
};
}