From 0f6e11e64e77fde08c33f010cef106304b726dee Mon Sep 17 00:00:00 2001 From: Lach Date: Thu, 24 Apr 2025 21:57:40 +0000 Subject: [PATCH] feat(nixos): system.onlineActivationScripts --- --- a/modules/nixos/online.nix +++ b/modules/nixos/online.nix @@ -1,7 +1,73 @@ -{...}: { - config.system.activationScripts.onlineActivation = '' - if [ -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then - 1>&2 echo "online activation; hello, fleet!" - fi - ''; +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption; + inherit (lib.types) attrsOf str submodule either listOf lines bool; + inherit (lib.attrsets) mapAttrs; + inherit (lib.trivial) isString; +in { + options.system.onlineActivationScripts = mkOption { + default = {}; + type = attrsOf (either str (submodule { + options = { + deps = mkOption { + type = listOf str; + default = []; + }; + text = mkOption { + type = lines; + }; + supportsDryActivation = mkOption { + type = bool; + default = false; + }; + }; + })); + description = '' + Same as activation scripts, but only ran on online activation (i.e when operator is actively running fleet deploy, and not on system restart) + + Can be used to apply configuration such as ceph monitor maps, which is required to be up-to-date to correctly function, + we should not apply outdated ceph monmap. + ''; + + apply = set: + mapAttrs ( + name: value: + if isString value + then { + text = '' + if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then + ${value} + fi + ''; + deps = ["onlineActivation"]; + } + else + value + // { + deps = ["onlineActivation"] ++ value.deps; + text = '' + if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then + ${value.text} + fi + ''; + } + ) + set; + }; + + config.system.activationScripts = + { + onlineActivation = { + text = '' + if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then + 1>&2 echo "online activation; hello, fleet!" + fi + ''; + supportsDryActivation = true; + }; + } + // config.system.onlineActivationScripts; } -- gitstuff