Add auto-update and maintenance options to system module

This commit is contained in:
ashisgreat22 2026-03-19 00:03:54 +01:00
parent 99c23a1aa5
commit abf2080f91
2 changed files with 71 additions and 5 deletions

View file

@ -48,10 +48,13 @@
# Then add the public key to .sops.yaml
};
# === Automatic Updates ===
system.autoUpgrade = {
enable = true;
allowReboot = false;
# === System Maintenance & Updates ===
myModules.system = {
mainUser = "ashie";
autoUpdate = {
enable = true;
allowReboot = false; # Set to true to allow automatic reboots for kernel updates
};
};
system.stateVersion = "23.11";

View file

@ -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;
};
}