nixfiles/modules/deployment/default.nix
2024-05-14 12:24:04 +02:00

70 lines
2.2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let cfg = config.kyouma.deployment.upgradeSystem;
in {
options.kyouma.deployment = {
tags = mkOption {
type = with types; listOf str;
default = [ ];
description = "colmena deployment tags";
};
targetHost = mkOption {
type = with types; nullOr str;
default = null;
description = "colmena target host override";
};
upgradeSystem = {
enable = mkEnableOption "automatically apply hydra builds";
allowReboot = mkOption {
type = types.bool;
default = true;
description = "automatically reboot if needed";
};
branch = mkOption {
type = types.str;
default = "main";
description = "branch to use for updates";
};
hostName = mkOption {
type = with types; nullOr str;
default = null;
description = "Set hostname";
};
noDelay = mkOption {
type = types.bool;
default = false;
description = "dont use delays";
};
runFreq = mkOption {
type = types.str;
default = "*-*-* *:04:20";
description = "How often Updates should be fetched. See {manpage}`systemd.timer(5)`";
};
};
};
config = mkIf cfg.enable {
systemd.services.upgrade-system = {
requires = [ "network-online.target" ];
after = [ "network-online.target" ];
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.upgrade-system}/bin/upgrade-system${optionalString cfg.allowReboot " --allow-reboot"} --branch ${cfg.branch}${
optionalString (cfg.hostName != null) " --hostname ${cfg.hostName}"
}${optionalString cfg.noDelay " --no-delay"}";
};
};
systemd.timers.upgrade-system = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = if cfg.noDelay then "*-*-* *:*:00" else cfg.runFreq;
RandomizedDelaySec = if cfg.noDelay then "1s" else "10m";
};
requires = [ "network-online.target" ];
after = [ "network-online.target" ];
};
environment.systemPackages = [ pkgs.upgrade-system ];
};
}