This paper investigates the impact of physical layer secrecy on the performance of a unified non-orthogonal multiple access (NOMA) framework, where both external and internal eavesdropping scenarios are examined. The spatial locations of legitimate users (LUs) and eavesdroppers are modeled by invoking stochastic geometry. To characterize the security performance, new exact and asymptotic expressions of secrecy outage probability (SOP) are derived for both code-domain NOMA (CD-NOMA) and power-domain NOMA (PD-NOMA), in which imperfect successive interference cancellation (ipSIC) and perfect SIC (pSIC) are taken into account. For the external eavesdropping scenario, the secrecy diversity orders by a pair of LUs (the n-th user and m-th user) for CD/PD-NOMA are obtained. Analytical results make known that the diversity orders of the n-th user with ipSIC/pSIC for CD-NOMA and PD-NOMA are equal to zero/K and zero/one, respectively. The diversity orders of the m-th user are equal to K/one for CD/PD-NOMA. For the internal eavesdropping scenario, we examine the analysis of secrecy diversity order and observe that the m-th user to wiretap the n-th user with ipSIC/pSIC for CD-NOMA and PD-NOMA provide the diversity orders of zero/K and zero/one, respectively, which is consistent with external eavesdropping scenario. Numerical results are present to confirm the accuracy of the analytical results developed and show that: i) The secrecy outage behavior of the n-th user is superior to that of the m-th user; ii) By increasing the number of subcarriers, CD-NOMA is capable of achieving a larger secrecy diversity gain compared to PD-NOMA.