git.delta.rocks / fleet / refs/heads / push-kyumtlkprzyo

difftreelog

source

modules/nixos/online.nix2.6 KiBsourcehistory
1{2  config,3  lib,4  ...5}:6let7  inherit (lib.options) mkOption;8  inherit (lib.modules) mkIf mkDefault;9  inherit (lib.types)10    attrsOf11    str12    submodule13    either14    listOf15    lines16    bool17    ;18  inherit (lib.attrsets) mapAttrs;19  inherit (lib.trivial) isString;20  inherit (lib.meta) getExe';21in22{23  options.system.onlineActivationScripts = mkOption {24    default = { };25    type = attrsOf (26      either str (submodule {27        options = {28          deps = mkOption {29            type = listOf str;30            default = [ ];31          };32          text = mkOption {33            type = lines;34          };35          supportsDryActivation = mkOption {36            type = bool;37            default = false;38          };39        };40      })41    );42    description = ''43      Same as activation scripts, but only ran on online activation (i.e when operator is actively running fleet deploy, and not on system restart)4445      Can be used to apply configuration such as ceph monitor maps, which is required to be up-to-date to correctly function,46      we should not apply outdated ceph monmap.47    '';4849    apply =50      set:51      mapAttrs (52        name: value:53        if isString value then54          {55            text = ''56              if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then57                ${value}58              fi59            '';60            deps = [ "onlineActivation" ];61          }62        else63          value64          // {65            deps = [ "onlineActivation" ] ++ value.deps;66            text = ''67              if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then68                ${value.text}69              fi70            '';71          }72      ) set;73  };7475  config = {76    systemd.targets.online-activation = {77      description = "Online activation target for deploy-time services";78    };7980    system.activationScripts = {81      onlineActivation = {82        text = ''83          if [ ! -z ''${FLEET_ONLINE_ACTIVATION+x} ]; then84            1>&2 echo "online activation; hello, fleet!"85            ${getExe' config.systemd.package "systemctl"} start online-activation.target86          fi87        '';88        supportsDryActivation = true;89      };90    }91    // config.system.onlineActivationScripts;9293    systemd.services = mkIf config.networking.networkmanager.enable {94      # If machine is managed by fleet, we should not restart NetworkManager during activation,95      # as it will disrupt the activation process. Furthermore, NetworkManager is not declarative,96      # so even if user wants to update his network settings - disabled NetworkManager restart97      # will not affect that.98      NetworkManager.restartIfChanged = mkDefault false;99    };100  };101}