nixfiles/modules/deployment/default.nix

71 lines
2.2 KiB
Nix
Raw Normal View History

2024-05-14 03:08:06 +02:00
{ config, lib, pkgs, ... }:
with lib;
let cfg = config.kyouma.deployment.upgradeSystem;
in {
2024-04-27 19:34:17 +02:00
options.kyouma.deployment = {
tags = mkOption {
2024-05-14 03:08:06 +02:00
type = with types; listOf str;
default = [ ];
2024-04-27 19:34:17 +02:00
description = "colmena deployment tags";
};
targetHost = mkOption {
2024-05-14 03:08:06 +02:00
type = with types; nullOr str;
2024-04-27 19:34:17 +02:00
default = null;
description = "colmena target host override";
};
2024-05-14 03:08:06 +02:00
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";
};
2024-05-14 11:10:01 +02:00
hostName = mkOption {
type = with types; nullOr str;
default = null;
description = "Set hostname";
};
2024-05-14 03:08:06 +02:00
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}${
2024-05-14 11:10:01 +02:00
optionalString (cfg.hostName != null) " --hostname ${cfg.hostName}"
}${optionalString cfg.noDelay " --no-delay"}";
2024-05-14 03:08:06 +02:00
};
};
systemd.timers.upgrade-system = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = if cfg.noDelay then "*-*-* *:*:00" else cfg.runFreq;
2024-05-14 11:10:01 +02:00
RandomizedDelaySec = if cfg.noDelay then "1s" else "10m";
2024-05-14 03:08:06 +02:00
};
requires = [ "network-online.target" ];
after = [ "network-online.target" ];
};
environment.systemPackages = [ pkgs.upgrade-system ];
2024-04-27 19:34:17 +02:00
};
}