pkgs/bijwerken-*,modules/bijwerken: Consolidate system update management and refactor under the same name
This commit is contained in:
57
modules/bijwerken/default.nix
Normal file
57
modules/bijwerken/default.nix
Normal file
@@ -0,0 +1,57 @@
|
||||
{ pkgs, lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.bijwerken;
|
||||
in
|
||||
|
||||
{
|
||||
options = {
|
||||
services.bijwerken = {
|
||||
enable = mkEnableOption "Automatic system upgrades";
|
||||
autoUpgrade = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Automatically check and install upgrades";
|
||||
};
|
||||
startAt = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "Systemd time string for starting the unit";
|
||||
};
|
||||
nodeExporterTextfilePath = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "Path to node exporter textfile for putting metrics";
|
||||
};
|
||||
};
|
||||
};
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services.bijwerken-system-upgrade = {
|
||||
requires = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
|
||||
# Make sure this unit does not stop themself while upgrading
|
||||
restartIfChanged = false;
|
||||
unitConfig.X-StopOnRemoval = false;
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = (getExe pkgs.bijwerken-system-upgrade) + " --no-confirm${optionalString (cfg.nodeExporterTextfilePath != null) " --node-exporter-metrics-path ${cfg.nodeExporterTextfilePath}"}";
|
||||
};
|
||||
};
|
||||
systemd.timers.bijwerken-system-upgrade = mkIf cfg.autoUpgrade {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = if cfg.startAt == null then "*-*-* 05:37:00" else cfg.startAt;
|
||||
RandomizedDelaySec = if cfg.startAt == null then "2h" else "10m";
|
||||
};
|
||||
requires = [ "network-online.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
};
|
||||
environment.systemPackages = with pkgs; [
|
||||
bijwerken-system-upgrade
|
||||
];
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user