nixos-vps/modules/system.nix

88 lines
2.2 KiB
Nix

# System Module
# Provides: Common system configuration options used by other modules
{
config,
lib,
pkgs,
...
}:
let
cfg = config.myModules.system;
in
{
options.myModules.system = {
mainUser = lib.mkOption {
type = lib.types.str;
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 = {
# 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;
};
}