  We study the magnetic field generation in a neutron star within the model
based on the magnetic field instability in the nuclear matter owing to the
electron-nucleon parity violating interaction. We suggest that the growing
magnetic field takes the energy from thermal background fermions in the neutron
star matter. The system of kinetic equations for the spectra of the magnetic
helicity density and magnetic energy density as well as the chiral imbalance
are solved numerically accounting for this energy source. We obtain that, for
the initial conditions corresponding to a typical neutron star, the large scale
magnetic field $\sim 10^{15}\thinspace\text{G}$ is generated during
$(10^4-10^5)\thinspace\text{yr}$. We suggest that the proposed model describes
strong magnetic fields observed in magnetars.
