For a fixed $n \in \mathbb{N}$ let $[n]$ denote $S^n(0)$, so that e.g. $[2]$ denotes $S(S(0))$. Let $n \cdot x$ denote $x + x + \dots + x$ where $x$ occurs $n$ times, so that e.g. $3 \cdot x$ denotes the term $x + x + x$.
Take an eventually periodic set $X\subseteq \mathbb{N}$ with corresponding fixed constants $n_0$ and $p$ so that for all $n \geq n_0$, $n \in X \leftrightarrow n + p \in X$.
We can write the set $X$ as a union of three sets:
- $X_i = \{n \in \mathbb{N} \:|\: n \in X \wedge n < n_0 \}$
- $X_b = \{n \in \mathbb{N} \:|\: n \in X \wedge n < n_0 + p\}$
- $X_p = \{n \in \mathbb{N} \:|\: n \in X \wedge n_0 + p \leq n\}$.
We will show that each of these sets is definable.
First notice that the sets $X_i$ and $X_b$ are finite (they have no more than $n_0 + p$ elements), so one can define $X_i$ using the finite disjunction $$\varphi_i(x) \leftrightarrow \bigvee_{j < n_0,\\ j \in X_i} x = [j],$$
and one can define membership in $X_b$ using the finite disjunction
$$\varphi_b(x) \leftrightarrow \bigvee_{j < n_0 + p,\\ j \in X_b} x = [j].$$
Finally, notice that by the eventual periodicity of $X$, $n \in X_p$ holds when one can find some $n' \in X_b$ and $k \in \mathbb{N}$ so that $n' + p\cdot k = n$. This means that we can define
$$ \varphi_p(x) \leftrightarrow \exists n. \exists k. \varphi_b(n) \wedge x = n + p \cdot k$$
Since $X = X_i \cup X_b \cup X_p$, we can define $X$ using the formula
$$ \varphi(x) \leftrightarrow \varphi_i(x) \vee \varphi_b(x) \vee \varphi_p(x).$$
This definition has some redundancy (for example $\varphi_b(x) \rightarrow \varphi_p(x)$ always holds by taking $k = 0$), but it gets the job done.