Add auto-update and maintenance options to system module
This commit is contained in:
parent
99c23a1aa5
commit
abf2080f91
2 changed files with 71 additions and 5 deletions
|
|
@ -17,9 +17,72 @@ in
|
|||
default = "ashie";
|
||||
description = "Main user account for running services";
|
||||
};
|
||||
|
||||
autoUpdate = {
|
||||
enable = lib.mkEnableOption "automatic system updates";
|
||||
flake = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "git+ssh://forgejo@git.ashisgreat.xyz:2222/ashie/nixos-vps.git";
|
||||
description = "Flake URI to update from";
|
||||
};
|
||||
dates = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "04:00";
|
||||
description = "Schedule for updates (systemd.timer format)";
|
||||
};
|
||||
allowReboot = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Allow automatic reboots after updates";
|
||||
};
|
||||
};
|
||||
|
||||
maintenance = {
|
||||
gc = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Enable automatic garbage collection";
|
||||
};
|
||||
dates = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "weekly";
|
||||
description = "Schedule for GC (systemd.timer format)";
|
||||
};
|
||||
olderThan = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "7d";
|
||||
description = "Delete generations older than this";
|
||||
};
|
||||
};
|
||||
optimise = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "Enable automatic Nix store optimisation";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
# Nothing here by default - just provides the option
|
||||
# Automatic Updates
|
||||
system.autoUpgrade = lib.mkIf cfg.autoUpdate.enable {
|
||||
enable = true;
|
||||
inherit (cfg.autoUpdate) dates allowReboot flake;
|
||||
flags = [
|
||||
"--update-input"
|
||||
"nixpkgs"
|
||||
"-L" # show logs
|
||||
];
|
||||
};
|
||||
|
||||
# Nix Maintenance
|
||||
nix.gc = lib.mkIf cfg.maintenance.gc.enable {
|
||||
automatic = true;
|
||||
dates = cfg.maintenance.gc.dates;
|
||||
options = "--delete-older-than ${cfg.maintenance.gc.olderThan}";
|
||||
};
|
||||
nix.optimise.automatic = cfg.maintenance.optimise.enable;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue