diff --git a/flake.nix b/flake.nix index df3c490..77e8f92 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,10 @@ outputs = { self, nixpkgs, nixos-hardware, ... }: let + # Global domain + domain = "domain.com"; + git_url = "git+https://git.${domain}/owner/infra.git"; + # Per-user mapping of auth (login) and sudo keys key_mappings = { alice = { @@ -32,10 +36,11 @@ sharedModules = [ ./modules/users.nix + ./modules/auto-update.nix ]; sharedArgs = { - inherit key_mappings; + inherit domain git_url key_mappings; }; in { nixosConfigurations = { diff --git a/machines/auth.domain.com/configuration.nix b/machines/auth.domain.com/configuration.nix index c378732..6948bd8 100644 --- a/machines/auth.domain.com/configuration.nix +++ b/machines/auth.domain.com/configuration.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, git_url, ... }: { imports = [ @@ -39,5 +39,12 @@ }; }; + infra.autoUpdate = { + enable = true; + # selects the nixosConfigurations.auth.domain.com output from the flake + flake = "${git_url}#auth.domain.com"; + allowReboot = true; + }; + system.stateVersion = "26.05"; } \ No newline at end of file diff --git a/machines/status.domain.com/configuration.nix b/machines/status.domain.com/configuration.nix index 5706f37..26133d9 100644 --- a/machines/status.domain.com/configuration.nix +++ b/machines/status.domain.com/configuration.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, git_url, ... }: { imports = [ @@ -28,5 +28,12 @@ bash ]; + infra.autoUpdate = { + enable = true; + # selects the nixosConfigurations.status.domain.com output from the flake + flake = "${git_url}#status.domain.com"; + allowReboot = true; + }; + system.stateVersion = "26.05"; } \ No newline at end of file diff --git a/modules/auto-update.nix b/modules/auto-update.nix new file mode 100644 index 0000000..91d5c8e --- /dev/null +++ b/modules/auto-update.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.infra.autoUpdate; +in { + options.infra.autoUpdate = { + enable = mkEnableOption "automatic system upgrades"; + + flake = mkOption { + type = types.nullOr types.str; + default = null; + description = "Flake URI to build from"; + }; + + flags = mkOption { + type = types.listOf types.str; + default = [ "--commit-lock-file" ]; + description = "Extra flags passed to nix flake update"; + }; + + dates = mkOption { + type = types.str; + default = "04:00"; + description = "Schedule for the upgrade"; + }; + + allowReboot = mkOption { + type = types.bool; + default = false; + description = "Reboot the system after an upgrade if needed"; + }; + + randomizedDelaySec = mkOption { + type = types.str; + default = "45min"; + description = "Randomized delay added to the schedule"; + }; + }; + + config = mkIf cfg.enable { + system.autoUpgrade = { + enable = true; + inherit (cfg) dates flags allowReboot randomizedDelaySec; + flake = cfg.flake; + }; + }; +} \ No newline at end of file