{ config, lib, ... }:

with lib;

let
  cfg = config.roles.nfs-mounts;
in
{
  options.roles.nfs-mounts = {
    enable = mkEnableOption "Enable default NFS mounts";
    server = mkOption {
      type = types.str;
      default = "10.0.0.43";
      description = "IP address or hostname of the NFS server";
    };
    remotePath = mkOption {
      type = types.str;
      default = "/media";
      description = "Remote path to mount from the NFS server";
    };
    mountPoint = mkOption {
      type = types.str;
      default = "/media";
      description = "Local mount point for the NFS share";
    };
    # TODO: implement requireMount
    requireMount = mkOption {
      type = types.bool;
      description = "Hard fail if the NFS mounts are not available";
      default = false;
    };
  };

  config = mkIf cfg.enable
    {
      fileSystems.${cfg.mountPoint} = {
        device = "${cfg.server}:${cfg.remotePath}";
        fsType = "nfs";
        options = [
          "defaults"
          "nofail"
          "softreval"
        ];
      };
    };
}
