how to make an addon with custom driver function
Use a persistent load_post handler to register your drivers to the driver namespace.

import bpy
from bpy.app.handlers import persistent
from bpy.app import driver_namespace as dns

def driver(x):
    return x

@persistent
def load_handler(dummy):
    print("Load Handler:", bpy.data.filepath)
    #dns = bpy.app.driver_namespace
    # register your drivers
    dns["xdriver"] = driver

def register():
    load_handler(None)
    bpy.app.handlers.load_post.append(load_handler)

def unregister():
    bpy.app.handlers.load_post.remove(load_handler)

if __name__ == "__main__":
    register()