Files
nixos-core/nixos/modules/homeserver.nix
T
kiskaadee 1a50c8a668 feat(nixos): scaffold declarative NixOS appliance for homelab server
Phase 1 & 2 of the homelab-core NixOS migration plan.

Adds a fully standalone NixOS flake configuration targeting the
roadtotech.me homelab server. Goal: wipe & restore from any bare
NixOS install via `nixos-install --flake ~/Core#server`.

Changes:
- flake.nix: 2-input flake (nixpkgs channel tarball + sops-nix)
- flake.lock: generated lockfile pinning nixos-26.11pre1070770.8ce4ef6
- .sops.yaml: SOPS rules scoped to nixos/secrets.yaml (server + laptop keys)
- nixos/configuration.nix: clean standalone config; no HM, no desktop
  inheritance, no lib.mkForce; headless-optimised; SOPS set exactly once
- nixos/hardware-configuration.nix: copied from Config/hosts/server/
- nixos/secrets.yaml: copied SOPS-encrypted secrets from Config/hosts/server/
- nixos/modules/homeserver.nix: migrated; sops.defaultSopsFile removed
- nixos/modules/traefik-deployments.nix: migrated; sops.defaultSopsFile removed
- nixos/modules/dynu.nix: migrated; paths updated to ../scripts/
- nixos/scripts/monitor.py: dynu IP monitor Python script
- nixos/scripts/ddclient.conf: ddclient config template
- AGENTS.md: fix stale reference to deprecated desktop secrets path

Validated:
  nix flake check -> all checks passed
  nix build .#nixosConfigurations.server.config.system.build.toplevel \
    --no-link -> success (nixos-system-server-26.11.20260910.8ce4ef6)
2026-09-11 17:29:22 -05:00

119 lines
4.4 KiB
Nix

# 🌐 Homeserver Core Environment Secrets & Systemd service configuration
# This NixOS module manages secrets and the systemd lifecycle for the core homeserver stack.
{ config, lib, pkgs, ... }:
let
# Declarative user database for Authelia
autheliaUsers = {
kiskaadee = {
displayName = "kiskaadee";
email = "fcortesbio@gmail.com";
groups = [ "admins" "dev" ];
passwordPlaceholder = config.sops.placeholder."authelia/users/kiskaadee/password_hash";
};
misa = {
displayName = "misa";
email = "icdf0728@gmail.com";
groups = [ "users" ];
passwordPlaceholder = config.sops.placeholder."authelia/users/misa/password_hash";
};
valenvg = {
displayName = "valenvg";
email = "vegavalentina069@gmail.com";
groups = [ "users" ];
passwordPlaceholder = config.sops.placeholder."authelia/users/valenvg/password_hash";
};
};
renderUser = username: user: " " + username + ":\n"
+ " displayname: \"" + user.displayName + "\"\n"
+ " password: '" + user.passwordPlaceholder + "'\n"
+ " email: \"" + user.email + "\"\n"
+ " groups:\n"
+ (lib.concatMapStringsSep "\n" (g: " - " + g) user.groups);
renderedUsersYaml = "users:\n" + (lib.concatStringsSep "\n\n" (lib.mapAttrsToList renderUser autheliaUsers)) + "\n";
in
{
# Define the keys to decrypt from secrets.yaml
sops.secrets = lib.genAttrs [
"dynu/api_key"
"traefik/acme_email"
"authelia/session_secret"
"authelia/storage_encryption_key"
"authelia/jwt_secret"
"authelia/users/kiskaadee/password_hash"
"authelia/users/misa/password_hash"
"authelia/users/valenvg/password_hash"
] (name: { owner = "kiskaadee"; });
# Generate the unified environment file at runtime in /run/secrets/homeserver.env
sops.templates."homeserver.env" = {
owner = "kiskaadee";
content = lib.generators.toKeyValue {} {
DOMAIN = "roadtotech.me";
DOCKER_API_VERSION = "1.40";
DYNU_API_KEY = config.sops.placeholder."dynu/api_key";
ACME_EMAIL = config.sops.placeholder."traefik/acme_email";
AUTHELIA_SESSION_SECRET = config.sops.placeholder."authelia/session_secret";
AUTHELIA_STORAGE_ENCRYPTION_KEY = config.sops.placeholder."authelia/storage_encryption_key";
AUTHELIA_IDENTITY_VALIDATION_RESET_PASSWORD_JWT_SECRET = config.sops.placeholder."authelia/jwt_secret";
};
};
# Generate the declarative Authelia user database file at runtime in /run/secrets/users.yml
sops.templates."users.yml" = {
owner = "kiskaadee";
content = renderedUsersYaml;
};
# Define the declarative systemd service to manage the homeserver container stack
systemd.services.homeserver-core = {
description = "Homeserver Core Stack (Traefik, Authelia, Homepage, etc.)";
after = [ "network-online.target" "docker.service" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
WorkingDirectory = "/home/kiskaadee/Core";
ExecStart = "${pkgs.docker-compose}/bin/docker-compose --env-file ${config.sops.templates."homeserver.env".path} up -d --remove-orphans";
ExecStop = "${pkgs.docker-compose}/bin/docker-compose down";
};
};
# Declarative Dynamic GitOps Webhook Service (Internal Port 9000)
systemd.services.homelab-gitops = {
description = "Dynamic Homelab GitOps Webhook Dispatcher";
after = [ "network-online.target" "docker.service" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ git docker docker-compose python3 coreutils bash openssh ];
serviceConfig = {
Type = "simple";
User = "kiskaadee";
WorkingDirectory = "/home/kiskaadee/Core";
ExecStart = "${pkgs.webhook}/bin/webhook -hooks ${pkgs.writeText "hooks.json" (builtins.toJSON [
{
id = "deploy";
execute-command = "/home/kiskaadee/Core/scripts/gitops_dispatcher.py";
pass-arguments-to-command = [
{ source = "entire-payload"; }
];
command-working-directory = "/home/kiskaadee/Core";
response-message = "Deployment payload dispatched successfully.";
}
])} -port 9000 -verbose";
Restart = "on-failure";
RestartSec = "5s";
};
};
# Open ports in the firewall for Traefik, Gitea SSH, and GitOps Webhook Receiver
networking.firewall.allowedTCPPorts = [ 80 443 2223 9000 ];
}