This commit is contained in:
Yan Lin 2025-10-25 15:41:09 +02:00
parent 475ab0df9b
commit 7ed7224d53
2 changed files with 26 additions and 20 deletions

View file

@ -32,26 +32,32 @@ in
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable (
services.autofs = { let
enable = true; # Build server list: primary host followed by replicas
timeout = 300; allHosts = [ cfg.remoteHost ] ++ cfg.replicas;
autoMaster = # Format as "host1,host2,host3:/path" for NFS replicas
let locations = "${concatStringsSep "," allHosts}:${cfg.remotePath}";
# Build server list: primary host followed by replicas in
allHosts = [ cfg.remoteHost ] ++ cfg.replicas; {
# Format as "host1:/path host2:/path host3:/path" services.autofs = {
locations = concatStringsSep " " (map (host: "${host}:${cfg.remotePath}") allHosts); enable = true;
in timeout = 300;
'' autoMaster = ''
${cfg.mountPoint} -fstype=nfs4,rw,soft,intr,noatime ${locations} /- /etc/auto.nfs --timeout=300
''; '';
}; };
systemd.tmpfiles.rules = [ # Create the auto.nfs map file
"d ${cfg.mountPoint} 0755 root root -" environment.etc."auto.nfs".text = ''
]; ${cfg.mountPoint} -fstype=nfs4,rw,soft,intr,noatime ${locations}
'';
environment.systemPackages = [ pkgs.nfs-utils ]; systemd.tmpfiles.rules = [
}; "d ${cfg.mountPoint} 0755 root root -"
];
environment.systemPackages = [ pkgs.nfs-utils ];
}
);
} }

View file

@ -26,7 +26,7 @@ in
services.nfs.server = { services.nfs.server = {
enable = true; enable = true;
exports = '' exports = ''
${cfg.exportPath} ${concatStringsSep " " (map (net: "${net}(rw,sync,no_subtree_check,no_root_squash)") cfg.allowedNetworks)} ${cfg.exportPath} ${concatStringsSep " " (map (net: "${net}(rw,sync,no_subtree_check,no_root_squash,fsid=0)") cfg.allowedNetworks)}
''; '';
}; };
}; };