nixos/modules/system/cluster.nix
2024-09-14 22:42:26 +08:00

22 lines
867 B
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

inputs:
{
options.nixos.system.cluster = let inherit (inputs.lib) mkOption types; in mkOption
{
type = types.nullOr (types.submodule { options =
{
clusterName = mkOption { type = types.nonEmptyStr; };
nodeName = mkOption { type = types.nonEmptyStr; };
nodeType = mkOption { type = types.enum [ "master" "worker" ]; default = "worker"; };
};});
default = null;
};
config = let inherit (inputs.config.nixos.system) cluster; in inputs.lib.mkIf (cluster != null)
{
nixos.system.networking.hostname = "${cluster.clusterName}-${cluster.nodeName}";
# 作为从机时home-manager 需要被禁用
systemd.services = inputs.lib.mkIf (cluster.nodeType == "worker") (builtins.listToAttrs (builtins.map
(user: { name = "home-manager-${user}"; value.enable = false; })
inputs.config.nixos.user.users));
};
}