git.delta.rocks / jrsonnet / refs/commits / 0f6e11e64e77

difftreelog

feat(nixos) system.onlineActivationScripts

Lach2025-04-24parent: #1b47815.patch.diff
in: trunk

1 file changed

modifiedmodules/nixos/online.nixdiffbeforeafterboth
1{...}: {1{
2 config,
3 lib,
4 ...
5}: let
6 inherit (lib.options) mkOption;
7 inherit (lib.types) attrsOf str submodule either listOf lines bool;
8 inherit (lib.attrsets) mapAttrs;
9 inherit (lib.trivial) isString;
10in {
11 options.system.onlineActivationScripts = mkOption {
12 default = {};
13 type = attrsOf (either str (submodule {
14 options = {
15 deps = mkOption {
16 type = listOf str;
17 default = [];
18 };
19 text = mkOption {
20 type = lines;
21 };
22 supportsDryActivation = mkOption {
23 type = bool;
24 default = false;
25 };
26 };
27 }));
28 description = ''
29 Same as activation scripts, but only ran on online activation (i.e when operator is actively running fleet deploy, and not on system restart)
30
31 Can be used to apply configuration such as ceph monitor maps, which is required to be up-to-date to correctly function,
32 we should not apply outdated ceph monmap.
33 '';
34
35 apply = set:
36 mapAttrs (
37 name: value:
38 if isString value
39 then {
40 text = ''
41 if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then
42 ${value}
43 fi
44 '';
45 deps = ["onlineActivation"];
46 }
47 else
48 value
49 // {
50 deps = ["onlineActivation"] ++ value.deps;
51 text = ''
52 if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then
53 ${value.text}
54 fi
55 '';
56 }
57 )
58 set;
59 };
60
2 config.system.activationScripts.onlineActivation = ''61 config.system.activationScripts =
62 {
63 onlineActivation = {
64 text = ''
3 if [ -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then65 if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then
4 1>&2 echo "online activation; hello, fleet!"66 1>&2 echo "online activation; hello, fleet!"
5 fi67 fi
6 '';68 '';
69 supportsDryActivation = true;
70 };
71 }
72 // config.system.onlineActivationScripts;
7}73}
874