forked from emily/nixfiles
emily
1de66b3795
weird thing happen when you try to copy things from a binary cache to a local store
77 lines
2.4 KiB
Nix
77 lines
2.4 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
with lib;
|
|
let cfg = config.kyouma.deployment.auto-upgrade;
|
|
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";
|
|
};
|
|
auto-upgrade = {
|
|
enable = mkEnableOption "automatically upgrade from hydra";
|
|
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";
|
|
};
|
|
cache = mkOption {
|
|
type = types.str;
|
|
default = "https://cache.kyouma.net";
|
|
description = "Set the binary cache";
|
|
};
|
|
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} --cache ${cfg.cache}${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 ];
|
|
};
|
|
}
|