refactor: move homelab config to module

This commit is contained in:
Nickolaj Jepsen 2025-12-12 04:30:57 +01:00
parent 742a55e5a0
commit e03f3af01d
19 changed files with 123 additions and 62 deletions

View file

@ -44,6 +44,7 @@ with lib; let
../modules/system ../modules/system
../modules/programs ../modules/programs
../modules/desktop ../modules/desktop
../modules/homelab
(mkSystemImports hostname) (mkSystemImports hostname)
{nixpkgs.config.allowUnfree = true;} {nixpkgs.config.allowUnfree = true;}
] ]

View file

@ -4,6 +4,7 @@
... ...
}: { }: {
fireproof.dev.enable = true; fireproof.dev.enable = true;
fireproof.homelab.enable = true;
boot = { boot = {
# Use grub as bootloader as it works better with mdadm # Use grub as bootloader as it works better with mdadm

View file

@ -1,8 +1,10 @@
{ {
config, config,
lib,
username, username,
... ...
}: let }:
lib.mkIf config.fireproof.homelab.enable (let
user = "media"; user = "media";
group = "media"; group = "media";
@ -80,4 +82,4 @@ in {
}; };
prowlarr.enable = true; prowlarr.enable = true;
}; };
} })

View file

@ -0,0 +1,19 @@
{lib, ...}: {
options.fireproof.homelab = {
enable = lib.mkEnableOption "Enable homelab services (arr, nginx, postgres, prometheus, etc.)";
};
imports = [
./arr.nix
./flame.nix
./home-assistant.nix
./nextcloud.nix
./nginx.nix
./plex.nix
./postgres.nix
./prometheus.nix
./restic.nix
./sso.nix
./vaultwarden.nix
];
}

View file

@ -1,4 +1,9 @@
_: let {
config,
lib,
...
}:
lib.mkIf config.fireproof.homelab.enable (let
dataDir = "/var/lib/flame"; dataDir = "/var/lib/flame";
domain = "flame.nickolaj.com"; domain = "flame.nickolaj.com";
in { in {
@ -29,4 +34,4 @@ in {
}; };
}; };
}; };
} })

View file

@ -1,8 +1,10 @@
{ {
pkgs, pkgs,
config, config,
lib,
... ...
}: let }:
lib.mkIf config.fireproof.homelab.enable (let
mosquittoPort = 1883; mosquittoPort = 1883;
zigbee2mqttPort = 8180; zigbee2mqttPort = 8180;
homeAssistantPort = 8123; homeAssistantPort = 8123;
@ -65,7 +67,7 @@ in {
package = pkgs.home-assistant; package = pkgs.home-assistant;
customComponents = with pkgs.home-assistant-custom-components; [ customComponents = with pkgs.home-assistant-custom-components; [
adaptive_lighting adaptive_lighting
sleep_as_android sleep_as_android_mqtt
(pkgs.buildHomeAssistantComponent rec { (pkgs.buildHomeAssistantComponent rec {
owner = "Sian-Lee-SA"; owner = "Sian-Lee-SA";
domain = "switch_manager"; domain = "switch_manager";
@ -183,4 +185,4 @@ in {
}; };
}; };
}; };
} })

View file

@ -1,8 +1,10 @@
{ {
config, config,
pkgs, pkgs,
lib,
... ...
}: { }:
lib.mkIf config.fireproof.homelab.enable {
age.secrets.nextcloud-admin-pass = { age.secrets.nextcloud-admin-pass = {
rekeyFile = ../../secrets/hosts/homelab/nextcloud-admin-pass.age; rekeyFile = ../../secrets/hosts/homelab/nextcloud-admin-pass.age;
owner = "nextcloud"; owner = "nextcloud";

View file

@ -1,4 +1,9 @@
_: { {
config,
lib,
...
}:
lib.mkIf config.fireproof.homelab.enable {
networking.firewall.allowedTCPPorts = [80 443]; networking.firewall.allowedTCPPorts = [80 443];
services.nginx = { services.nginx = {

View file

@ -1,4 +1,10 @@
{pkgsUnstable, ...}: let {
config,
pkgsUnstable,
lib,
...
}:
lib.mkIf config.fireproof.homelab.enable (let
domain = "plex.nickolaj.com"; domain = "plex.nickolaj.com";
in { in {
services.nginx.virtualHosts."${domain}" = { services.nginx.virtualHosts."${domain}" = {
@ -18,4 +24,4 @@ in {
user = "media"; user = "media";
group = "media"; group = "media";
}; };
} })

View file

@ -1,4 +1,9 @@
{config, ...}: { {
config,
lib,
...
}:
lib.mkIf config.fireproof.homelab.enable {
services = { services = {
restic.backups.homelab.paths = [config.services.postgresqlBackup.location]; restic.backups.homelab.paths = [config.services.postgresqlBackup.location];

View file

@ -1,8 +1,10 @@
{ {
config, config,
hostname, hostname,
lib,
... ...
}: let }:
lib.mkIf config.fireproof.homelab.enable (let
mkScrapeConfig = name: { mkScrapeConfig = name: {
job_name = name; job_name = name;
static_configs = [ static_configs = [
@ -49,4 +51,4 @@ in {
]; ];
}; };
}; };
} })

View file

@ -1,8 +1,10 @@
{ {
pkgs, pkgs,
config, config,
lib,
... ...
}: { }:
lib.mkIf config.fireproof.homelab.enable {
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
restic restic
]; ];

View file

@ -1,8 +1,10 @@
{ {
config, config,
pkgsUnstable, pkgsUnstable,
lib,
... ...
}: let }:
lib.mkIf config.fireproof.homelab.enable (let
port = 9190; port = 9190;
rootDomain = "nickolaj.com"; rootDomain = "nickolaj.com";
zitadelDomain = "sso.${rootDomain}"; zitadelDomain = "sso.${rootDomain}";
@ -105,4 +107,4 @@ in {
cookie-domain = ".${rootDomain}"; cookie-domain = ".${rootDomain}";
}; };
}; };
} })

View file

@ -1,4 +1,9 @@
{config, ...}: let {
config,
lib,
...
}:
lib.mkIf config.fireproof.homelab.enable (let
domain = "bitwarden.nickolaj.com"; domain = "bitwarden.nickolaj.com";
in { in {
services = { services = {
@ -27,4 +32,4 @@ in {
}; };
}; };
}; };
} })

View file

@ -30,50 +30,52 @@ in {
forwardAgent = true; forwardAgent = true;
serverAliveInterval = 60; serverAliveInterval = 60;
serverAliveCountMax = 10; serverAliveCountMax = 10;
matchBlocks = { matchBlocks =
"*" = { {
identityFile = "${config.age.secrets.ssh-key.path}"; "*" = {
identityFile = "${config.age.secrets.ssh-key.path}";
};
homelab = {
hostname = "x.nickolaj.com";
user = "nickolaj";
};
}
// lib.optionalAttrs workEnabled {
# Work hostnames definded in ./networking.nix
"bastion.ao" = {
user = "nij";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"clickhouse.ao" = {
user = "ubuntu";
hostname = "51.158.205.48";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"flex.ao" = {
user = "nij";
hostname = "192.168.2.5";
proxyJump = "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"scw.ao" = {
user = "nij";
hostname = "51.15.81.1";
proxyJump = lib.mkDefault "dev.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"dev.ao" = {
user = "nij";
hostname = "192.168.2.28";
proxyJump = lib.mkDefault "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"staging.ao" = {
user = "staging";
hostname = "172.16.2.102";
proxyJump = lib.mkDefault "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
}; };
homelab = {
hostname = "x.nickolaj.com";
user = "nickolaj";
};
} // lib.optionalAttrs workEnabled {
# Work hostnames definded in ./networking.nix
"bastion.ao" = {
user = "nij";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"clickhouse.ao" = {
user = "ubuntu";
hostname = "51.158.205.48";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"flex.ao" = {
user = "nij";
hostname = "192.168.2.5";
proxyJump = "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"scw.ao" = {
user = "nij";
hostname = "51.15.81.1";
proxyJump = lib.mkDefault "dev.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"dev.ao" = {
user = "nij";
hostname = "192.168.2.28";
proxyJump = lib.mkDefault "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
"staging.ao" = {
user = "staging";
hostname = "172.16.2.102";
proxyJump = lib.mkDefault "bastion.ao";
identityFile = "${config.age.secrets.ssh-key-ao.path}";
};
};
}; };
}; };