Use lockf instead of flock, the former works on NFS.