modules.system.fileSystems.cluster: allow specify master address

This commit is contained in:
2025-07-03 11:52:55 +08:00
parent ed1a98d7f8
commit 6030a965ce

View File

@@ -1,13 +1,15 @@
inputs:
{
options.nixos.system.fileSystems.cluster = let inherit (inputs.lib) mkOption types; in mkOption
{
type = types.nullOr (types.submodule { options =
{
masterAddress = mkOption { type = types.str; default = "1"; };
};});
default = if inputs.config.nixos.model.cluster != null then {} else null;
};
config = inputs.lib.mkMerge
[
# for cluster master, export NFS
(inputs.lib.mkIf (inputs.config.nixos.model.cluster.nodeType or null == "master")
{ nixos.services.nfs."/" = [ "192.168.178.0/24" ]; })
# for cluster worker, mount nfs, disable some home manager files
(let inherit (inputs.config.nixos.model) cluster; in inputs.lib.mkIf (cluster.nodeType or null == "worker")
{ nixos.system.fileSystems.mount.nfs."192.168.178.1:/" = "/nix/remote/${cluster.clusterName}"; })
# 将一部分由 home-manager 生成软链接的文件改为直接挂载,以兼容集群的设置
(let files = [ ".zshrc" ".zshenv" ".profile" ".bashrc" ".bash_profile" ".zlogin" ]; in
{
@@ -32,5 +34,20 @@ inputs:
)
inputs.config.nixos.user.users);
})
(
let
fsCluster = inputs.config.nixos.system.fileSystems.cluster;
inherit (inputs.config.nixos.model) cluster;
in inputs.lib.mkIf (fsCluster != null)
{
nixos =
{
services.nfs = inputs.lib.mkIf (cluster.nodeType or null == "master") { "/" = [ "192.168.178.0/24" ]; };
system.fileSystems.mount.nfs = inputs.lib.mkIf (cluster.nodeType or null == "worker")
{
"192.168.178.${fsCluster.masterAddress}:/" = "/nix/remote/${cluster.clusterName}";
};
};
})
];
}