3 Commits

Author SHA1 Message Date
c214f8543c homelab: add deploy.enable option with assertion
All checks were successful
Run nix flake check / flake-check (push) Successful in 2m6s
Run nix flake check / flake-check (pull_request) Successful in 2m7s
- Add homelab.deploy.enable option (requires vault.enable)
- Create shared homelab-deploy Vault policy for all hosts
- Enable homelab.deploy on all vault-enabled hosts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-07 06:54:42 +01:00
7933127d77 system: enable homelab-deploy listener for all vault hosts
Add system/homelab-deploy.nix module that automatically enables the
listener on all hosts with vault.enable=true. Uses homelab.host.tier
and homelab.host.role for NATS subject subscriptions.

- Add homelab-deploy access to all host AppRole policies
- Remove manual listener config from vaulttest01 (now handled by system module)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-07 06:54:42 +01:00
13c3897e86 flake: update homelab-deploy, add to devShell
Update homelab-deploy to include bugfix. Add CLI to devShell for
easier testing and deployment operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-07 06:54:42 +01:00
14 changed files with 76 additions and 33 deletions

8
flake.lock generated
View File

@@ -28,11 +28,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1770437282, "lastModified": 1770443536,
"narHash": "sha256-7C6hheIP8JUkK0Aoib/lQ4xbOaXHoqSe9SJjU2u3t/Q=", "narHash": "sha256-UufZIVggiioMFDSjKx+ifgkDOk9alNSiRmkvc4/+HIA=",
"ref": "master", "ref": "master",
"rev": "cf3b1ce2c9e85ad954d8c230161553c5473e9579", "rev": "95b795dcfd86b7b36045bba67e536b3a1c61dd33",
"revCount": 12, "revCount": 20,
"type": "git", "type": "git",
"url": "https://git.t-juice.club/torjus/homelab-deploy" "url": "https://git.t-juice.club/torjus/homelab-deploy"
}, },

View File

@@ -225,11 +225,12 @@
{ pkgs }: { pkgs }:
{ {
default = pkgs.mkShell { default = pkgs.mkShell {
packages = with pkgs; [ packages = [
ansible pkgs.ansible
opentofu pkgs.opentofu
openbao pkgs.openbao
(pkgs.callPackage ./scripts/create-host { }) (pkgs.callPackage ./scripts/create-host { })
homelab-deploy.packages.${pkgs.system}.default
]; ];
}; };
} }

View File

@@ -57,6 +57,7 @@
# Vault secrets management # Vault secrets management
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
vault.secrets.backup-helper = { vault.secrets.backup-helper = {
secretPath = "shared/backup/password"; secretPath = "shared/backup/password";
extractKey = "password"; extractKey = "password";

View File

@@ -61,6 +61,7 @@
"flakes" "flakes"
]; ];
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
nix.settings.tarball-ttl = 0; nix.settings.tarball-ttl = 0;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [

View File

@@ -58,6 +58,7 @@
# Vault secrets management # Vault secrets management
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
vault.secrets.backup-helper = { vault.secrets.backup-helper = {
secretPath = "shared/backup/password"; secretPath = "shared/backup/password";
extractKey = "password"; extractKey = "password";

View File

@@ -55,6 +55,7 @@
"flakes" "flakes"
]; ];
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
nix.settings.tarball-ttl = 0; nix.settings.tarball-ttl = 0;
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [

View File

@@ -48,6 +48,7 @@
"flakes" "flakes"
]; ];
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
homelab.host = { homelab.host = {
role = "dns"; role = "dns";

View File

@@ -48,6 +48,7 @@
"flakes" "flakes"
]; ];
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
homelab.host = { homelab.host = {
role = "dns"; role = "dns";

View File

@@ -92,6 +92,7 @@ in
# Testing config # Testing config
# Enable Vault secrets management # Enable Vault secrets management
vault.enable = true; vault.enable = true;
homelab.deploy.enable = true;
# Define a test secret # Define a test secret
vault.secrets.test-service = { vault.secrets.test-service = {
@@ -101,28 +102,6 @@ in
services = [ "vault-test" ]; services = [ "vault-test" ];
}; };
# Homelab-deploy listener NKey
vault.secrets.homelab-deploy-nkey = {
secretPath = "shared/homelab-deploy/listener-nkey";
extractKey = "nkey";
};
# Enable homelab-deploy listener
services.homelab-deploy.listener = {
enable = true;
tier = "test";
role = "vault";
natsUrl = "nats://nats1.home.2rjus.net:4222";
nkeyFile = "/run/secrets/homelab-deploy-nkey";
flakeUrl = "git+https://git.t-juice.club/torjus/nixos-servers.git";
};
# Ensure listener starts after vault secret is available
systemd.services.homelab-deploy-listener = {
after = [ "vault-secret-homelab-deploy-nkey.service" ];
requires = [ "vault-secret-homelab-deploy-nkey.service" ];
};
# Create a test service that uses the secret # Create a test service that uses the secret
systemd.services.vault-test = { systemd.services.vault-test = {
description = "Test Vault secret fetching"; description = "Test Vault secret fetching";

View File

@@ -1,6 +1,7 @@
{ ... }: { ... }:
{ {
imports = [ imports = [
./deploy.nix
./dns.nix ./dns.nix
./host.nix ./host.nix
./monitoring.nix ./monitoring.nix

View File

@@ -0,0 +1,16 @@
{ config, lib, ... }:
{
options.homelab.deploy = {
enable = lib.mkEnableOption "homelab-deploy listener for NATS-based deployments";
};
config = {
assertions = [
{
assertion = config.homelab.deploy.enable -> config.vault.enable;
message = "homelab.deploy.enable requires vault.enable to be true (needed for NKey secret)";
}
];
};
}

View File

@@ -3,6 +3,7 @@
imports = [ imports = [
./acme.nix ./acme.nix
./autoupgrade.nix ./autoupgrade.nix
./homelab-deploy.nix
./monitoring ./monitoring
./motd.nix ./motd.nix
./packages.nix ./packages.nix

30
system/homelab-deploy.nix Normal file
View File

@@ -0,0 +1,30 @@
{ config, lib, ... }:
let
hostCfg = config.homelab.host;
in
{
config = lib.mkIf config.homelab.deploy.enable {
# Fetch listener NKey from Vault
vault.secrets.homelab-deploy-nkey = {
secretPath = "shared/homelab-deploy/listener-nkey";
extractKey = "nkey";
};
# Enable homelab-deploy listener
services.homelab-deploy.listener = {
enable = true;
tier = hostCfg.tier;
role = hostCfg.role;
natsUrl = "nats://nats1.home.2rjus.net:4222";
nkeyFile = "/run/secrets/homelab-deploy-nkey";
flakeUrl = "git+https://git.t-juice.club/torjus/nixos-servers.git";
};
# Ensure listener starts after vault secret is available
systemd.services.homelab-deploy-listener = {
after = [ "vault-secret-homelab-deploy-nkey.service" ];
requires = [ "vault-secret-homelab-deploy-nkey.service" ];
};
};
}

View File

@@ -4,6 +4,17 @@ resource "vault_auth_backend" "approle" {
path = "approle" path = "approle"
} }
# Shared policy for homelab-deploy (all hosts need this for NATS-based deployments)
resource "vault_policy" "homelab_deploy" {
name = "homelab-deploy"
policy = <<EOT
path "secret/data/shared/homelab-deploy/*" {
capabilities = ["read", "list"]
}
EOT
}
# Define host access policies # Define host access policies
locals { locals {
host_policies = { host_policies = {
@@ -90,11 +101,9 @@ locals {
] ]
} }
# Vault test host with homelab-deploy access
"vaulttest01" = { "vaulttest01" = {
paths = [ paths = [
"secret/data/hosts/vaulttest01/*", "secret/data/hosts/vaulttest01/*",
"secret/data/shared/homelab-deploy/*",
] ]
} }
} }
@@ -122,7 +131,7 @@ resource "vault_approle_auth_backend_role" "hosts" {
backend = vault_auth_backend.approle.path backend = vault_auth_backend.approle.path
role_name = each.key role_name = each.key
token_policies = concat( token_policies = concat(
["${each.key}-policy"], ["${each.key}-policy", "homelab-deploy"],
lookup(each.value, "extra_policies", []) lookup(each.value, "extra_policies", [])
) )