Sum of Random Variables

As part of my statistical mechanics class, I'm trying to go through Kardar's statistical physics of particles and I'm having trouble with this one line:

Consider the sum $$X=\displaystyle \sum_{i=1}^N x_i$$, where $$x_i$$ are random variables with a joint PDF of $$p(\mathbf{x})$$. The PDF of $$X$$ is:

$$p_X(x) = \displaystyle\int d^N\mathbf{x}p(\mathbf{x}) \delta(x-\sum x_i) = \int \prod_{i=1}^{N-1} dx_ip(x_1,\ldots,x_{N-1},x-x_1 - \cdots-x_{N-1})$$

My two questions are: why is that first integral the pdf for $$X$$ and how does that second equality follow?

I assume that $\delta(\cdot)$ denotes the Dirac delta or impulse which has the sifting property $$\int_{-\infty}^\infty f(x)\delta(x-a)\,\mathrm dx = \int_{-\infty}^\infty f(x)\delta(a-x)\,\mathrm dx = f(a)$$ provided that $f(x)$ is continuous at $x=a$. If so, the integral is merely over all points in $\mathbb R^n$ for which the sum $\sum_i x_i$ equals $x$. The following simple example illustrates (I hope!) what is going on.
For two random variables $X$ and $Y$, the density of their sum $Z$ is given by \begin{align} f_Z(z) &= \int_{-\infty}^\infty f_{X,Y}(x, z-x)\,\mathrm dx\\ &= \int_{-\infty}^\infty \left[ \int_{-\infty}^\infty f_{X,Y}(x,y)\delta((z-x)-y)\,\mathrm dy \right]\,\mathrm dx\\ &=\int_{-\infty}^\infty f_{X,Y}(x,y)\delta(z-x-y)\,\mathrm dy \,\mathrm dx \end{align}