Retirement tax questions

I still haven't had explained to me if the Roth contribution is based on net income, MAGI income or gross income.  Ex. Gross income $17,000 (my pension doesn't count), AGI is taking our Gross income, subtracting 1/2 self employment tax, minus SEP contribution for a AGI of $16,000.  The MAGI takes the $16,000 and adds (I think) the working spouse's social security payments, SEP contribution and 1/2 self employment tax.  So is the Roth based on gross income, net income, AGI, or MAGI? Thank you.