feat(nixos): add control center host with hypervisor gitops service
This commit is contained in:
parent
89cec4e0f3
commit
dc9b7a30d9
10 changed files with 259 additions and 42 deletions
|
|
@ -2,5 +2,6 @@
|
|||
imports = [
|
||||
./actions
|
||||
./openssh
|
||||
./hypervisor-gitops
|
||||
];
|
||||
}
|
||||
|
|
|
|||
64
nixos/modules/services/hypervisor-gitops/default.nix
Normal file
64
nixos/modules/services/hypervisor-gitops/default.nix
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.homelab.services.hypervisor-gitops;
|
||||
|
||||
hypervisorSyncScript = pkgs.writeShellApplication {
|
||||
name = "hypervisor-sync";
|
||||
runtimeInputs = with pkgs; [ git opentofu coreutils ];
|
||||
text = builtins.readFile ../../../../scripts/hypervisor-sync.sh;
|
||||
};
|
||||
in {
|
||||
options.homelab.services.hypervisor-gitops = {
|
||||
enable = mkEnableOption "Hypervisor GitOps Service";
|
||||
|
||||
repoUrl = mkOption {
|
||||
type = types.str;
|
||||
description = "The URL of the git repository to pull";
|
||||
};
|
||||
|
||||
# TODO Replace with webhooks
|
||||
pollInterval = mkOption {
|
||||
type = types.str;
|
||||
default = "hourly";
|
||||
description = "Systemd calendar event for polling interval";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = with pkgs; [
|
||||
git
|
||||
opentofu
|
||||
];
|
||||
|
||||
systemd.services.hypervisor-gitops = {
|
||||
description = "Hypervisor GitOps Polling Service";
|
||||
|
||||
# We need network access to reach Forgejo and Proxmox API
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root"; # Needs root to read SOPS secrets potentially
|
||||
|
||||
# We will create a state directory for the repo
|
||||
StateDirectory = "hypervisor-gitops";
|
||||
WorkingDirectory = "/var/lib/hypervisor-gitops";
|
||||
|
||||
ExecStart = "${hypervisorSyncScript}/bin/hypervisor-sync ${cfg.repoUrl} opentofu/nodes/mikoshi";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.hypervisor-gitops = {
|
||||
description = "Timer for Hypervisor GitOps Service";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = cfg.pollInterval;
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue