diff --git a/configuration.nix b/configuration.nix index d1f881b..0826503 100644 --- a/configuration.nix +++ b/configuration.nix @@ -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"; diff --git a/modules/system.nix b/modules/system.nix index ea302af..48d6316 100644 --- a/modules/system.nix +++ b/modules/system.nix @@ -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; }; }