64 lines
1.7 KiB
Nix
64 lines
1.7 KiB
Nix
{ 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;
|
|
};
|
|
};
|
|
};
|
|
}
|