Sure. Just replicate the ecosystems of the Earth and the power source of the Sun sufficiently to provide a closed cycle. The Earth and Sun are such a spaceship.
You can buy such closed systems (Sun not included) with plants, animals and bacteria.

They are called "ecospheres". They work thusly:

If you really want something "indefinite", biological systems are self-replicating, self-repairing, and will even evolve over time to better meet your needs if you cull the populations that don't meet your needs.
As for replicating the Sun if you're far from any star, that would require nuclear power in any practical system of long duration. You could use existing fission systems, or, we can hope, future fusion systems. And bring enough fuel. You could in theory collect interstellar hydrogen, but that is not likely to be practical. Truly "indefinite" is not possible, and is limited by the fuel you can bring or find. The same is true of our Sun.