I was in need of such a result and google led me to this post, which I found the answer given above a bit tricky and subsequently made an attempt to derive the result myself.
The derivations are carried out in two parts: (1) the lensmakers' equation of a thin lens for media with different indices (2) generation of the result to the case of the thick lens.
As it becomes apparent that the lensmakers equation depends on the refractive indice, not only for the focal distance, but also the terms involving object and image distances. To be specific, one finds
$$\frac{1}{f}=\frac{n_p}{p}+\frac{n_i}{i} ,$$
with
$$\frac{1}{f}\equiv \frac{1}{R_p}(n-n_p)+\frac{1}{R_i}(n_i-n) ,$$
for the case of thin lens and
$$\frac{1}{f}\equiv \frac{1}{R_p}(n-n_p)+\frac{1}{R_i}(n_i-n)+\frac{d}{R_pR_i}\frac{(n-n_p)(n-n_i)}{n} ,$$
for the case of thick lens.
where $p$ and $i$ are the distance of the object and image, $n_p$ and $n_i$ are the refractive indices of the medium on the respective sides, $n$ indicates the reflective index of the material which makes the lens, and $d$ the thickness or the distance between two vertices.
We note that the above result readily falls back to that given in standard textbooks, such as Eq. (6.2) in Optics, 5th edition, Pearson Education, by Hecht and Eugene, as one considers $n_i=n_p=1$.
Here are the derivations.
The first part of the derivation can be decomposed further into two sections. First, one shows that if the entire space consists of two different media, denoted by $1$ and $2$, with reflective indices $n_1$ and $n_2$, separated by a spherical surface with radius $R$ (defined being positive as the light ray goes from $1$ to $2$, it encounters a convex surface), we have
$$\frac1R\left({n_2}-{n_1}\right)=\frac{n_1}{p}+\frac{n_2}{i} .$$
This is an effective lensmaker's equation for an half-infinite lens.
It can be shown by either using Snelling's law and geometry or Fermat's principle. A brief proof using the latter method can be found here.
The final result given above can be readily utilized to obtain the desired lensmaker's equation as one stacks two of the above half-infinite lenses at the same spot. To be specific, one has
$$\frac{1}{f_1}=\frac{1}{R_1}\left(1-\frac{n_1}{n_2}\right)=\frac{1}{p_1}\frac{n_1}{n_2}+\frac{1}{i_1} ,$$
and
$$\frac{1}{f_2}=\frac{1}{R_2}\left(1-\frac{n_2}{n_3}\right)=\frac{1}{p_2}\frac{n_2}{n_3}+\frac{1}{i_2}$$
Moreover, one recognizes a relationship between the image of the first lens and the object of the second, namely,
$$i_1 = - p_2 ,$$
and $R_i$ is given as a positive value (as in most literature) but it should be compensated by a negative sign when employing the intermediate formula.
Now, by adopting the notation above, which reads $R_1\to R_p$, $R_2\to R_i$, $n_1\to n_p$, $n_3\to n_i$, $n_2\to n$, $p_1\to p$, and $i_2\to i$. Some straightforward algebra gives
$$\frac{1}{R_p}(n-n_p)+\frac{1}{R_i}(n_i-n)=\frac{n_p}{p}+\frac{n_i}{i} ,$$
which is the precisely the lensmakers' equation for a thin lens given above.
The second part of the derivation considers that the two half-infinite lenses are cascaded but not at the same location, and therefore, one instead has the relation
$${i'}_1 + {p'}_2 = {i}_1 + {p}_2 - d = 0 .$$
In other words, one takes into account the fact that the distances (eg. $i_1, p_2$) in a lensmakers' equation must be measured w.r.t. the vertices and the two vertices are separated by a distance $d$, the thickness of the lens.
This gives
$$\frac{n_2}{\frac{1}{R_1}(n_2-n_1)-\frac{n_1}{p_1}}+\frac{n_2}{\frac{1}{R_2}(n_3-n_2)-\frac{n_3}{i_2}}=d ,$$
which can be further simplified to
$$\frac{n_2\left[\frac{1}{R_1}(n_2-n_1)+\frac{1}{R_2}(n_3-n_2)-\frac{n_1}{p_1}-\frac{n_3}{i_2}\right]}{\frac{1}{R_1R_2}(n_2-n_1)(n_3-n_2)+\cdots}=d ,$$
where we have ignore the higher-order terms on the denominator denoted by ``$\cdots$''.
This is because $\left(\frac{1}{R_1}-\frac{1}{R_2}\right)\sim \frac{1}{p}\sim \frac{1}{i}$, thus $\frac{1}{R_1}\sim \frac{1}{R_2} \gg \frac{1}{p}\sim \frac{1}{i}$.
It is not difficult to show the above expression gives rise to the desired form of the lensmakers' equation.