Insomnia is one of the most prevalent and burdensome mental disorders worldwide, affecting between 10-20% of adults and up to 48% of the geriatric population. It is further associated with substance usage and dependence, as well other psychiatric disorders. In this study, we combined electronic health record (EHR) derived phenotypes and genotype information to conduct a genome wide analysis of insomnia in a 18,055 patient cohort. Diagnostic codes were used to identify 3,135 patients with insomnia. Our genome-wide association study (GWAS) identified one novel genomic risk locus on chromosome 8 (lead SNP rs17052966, p = 4.53 × 10 −9 , odds ratio = 1.28, se = 0.04). The heritability analysis indicated that common SNPs accounts for 7% (se = 0.02, p = 0.015) of phenotypic variation. We further conducted a large-scale meta-analysis of our results and summary statistics of two recent insomnia GWAS and 13 significant loci were identified. The genetic correlation analysis yielded a strong positive genetic correlation between insomnia and alcohol use (rG = 0.56, se = 0.14, p < 0.001), nicotine use (rG = 0.50, se = 0.12, p < 0.001) and opioid use (rG = 0.43, se = 0.18, p = 0.02) disorders, suggesting a significant common genetic risk factors between insomnia and substance use.