1
0
Fork 0
forked from emily/nixfiles
nixfiles-emily/modules/deployment/default.nix

65 lines
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";
};
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.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 "1h";
};
requires = [ "network-online.target" ];
after = [ "network-online.target" ];
};
environment.systemPackages = [ pkgs.upgrade-system ];
};
}