From 04ec7debc9aaa195468cc02fdca9ac85300b6aab Mon Sep 17 00:00:00 2001 From: ooks-io Date: Sun, 30 Jul 2023 21:59:08 +1200 Subject: [PATCH] auto-upgrade added --- system/common/global/auto-upgrade.nix | 31 +++++++++++++++++++++++++++ system/common/global/default.nix | 1 + 2 files changed, 32 insertions(+) create mode 100644 system/common/global/auto-upgrade.nix diff --git a/system/common/global/auto-upgrade.nix b/system/common/global/auto-upgrade.nix new file mode 100644 index 0000000..05bd6a9 --- /dev/null +++ b/system/common/global/auto-upgrade.nix @@ -0,0 +1,31 @@ +{ config, inputs, pkgs, lib, ... }: + +let + inherit (config.networking) hostName; + isClean = inputs.self ? rev; +in +{ + system.autoUpgrade = { + enable = isClean; + dates = "hourly"; + flags = [ + "--refresh" + ]; + flake = "github:ooks-io/nix#${hostName}; + }; + +# Only run if current config (self) is older than the new one. + + systemd.services.nixos-upgrade = lib.mkIf config.system.autoUpgrade.enable { + serviceConfig.ExecCondition = lib.getExe ( + pkgs.writeShellScriptBin "check-date" '' + lastModified() { + nix flake metadata "$1" --refresh --json | ${lib.getExe pkgs.jq} '.lastModified' + } + test "$(lastModified "${config.system.autoUpgrade.flake}")" -gt "$(lastModified "self")" + '' + ); + }; +} + + diff --git a/system/common/global/default.nix b/system/common/global/default.nix index c3fb1f7..65babec 100644 --- a/system/common/global/default.nix +++ b/system/common/global/default.nix @@ -7,6 +7,7 @@ ./security.nix ./systemdboot.nix ./pipewire.nix + # ./auto-upgrade.nix # still needs some work ] ++ (builtins.attrValues outputs.nixosModules); home-manager.extraSpecialArgs = { inherit inputs outputs; };