feat: add auto update

main
flop 5 days ago
parent bf4c33042d
commit e26d4dd255
  1. 7
      flake.nix
  2. 9
      machines/auth.domain.com/configuration.nix
  3. 9
      machines/status.domain.com/configuration.nix
  4. 49
      modules/auto-update.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 = {

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

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

@ -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;
};
};
}
Loading…
Cancel
Save