Well as part of the original deal, Russia and Turkey were supposed to co produce the 2nd batch of the S-400 and I believe that Turkey was supposed to receive the software codes. However there is likely a stipulation within the contract that if the buyer nation endangers the national security of the supplier nation in any way then the software codes will not be provided.
This is what has happened with Turkey, as Turkey is supplying Ukraine with Bayraktar drones and is on the side of Ukraine when it comes to the issues of Donbas and Crimea. If Russia were to supply Turkey with the software codes, then Turkey could hypothetically hand them over to Ukraine.
This becomes especially relevant in regards to the Bayraktar drones since Russia has recently deployed air defenses right by its border with Ukraine. If Ukraine were to gain access to the S-400 software codes then it could in theory assist them in using Bayraktar drones on Russian targets.
Of course, at the end of the day, the S-400 batteries sold to Turkey are export variants, however Russia has not deployed the S-500 yet and the S-400 will still remain their most potent air defense system for some time to come. Aside from the software codes and technology transfers, all the vital spare parts will be supplied by Russia and the vital maintenance must be done by Russian technicians.
In regards to the nuclear plants that Russia is set to build for Turkey, it's a similar deal. The plants will be run by Russian experts and all the fissile material will be removed by the Russians on a consistent basis.
Initially Turkey chose to purchase the S-400 because they could not agree on a favorable price for the Patriot SAM and the US was unwilling to share technology transfers under any circumstances. Yes the S-400 did end up being cheaper, but realistically the CAATSA sanctions imposed on Turkey by the west made the S-400 deal several times more costly than simply purchasing the Patriot batteries.
With the fact that Turkey lost out on the F-35 and the fact that the US is now refusing to give Turkey their deposit back, even unwilling to put the deposit towards a larger F-16 purchase, Erdogan pretty much shot himself in the foot. Of course the failed coup, which many believe was sponsored by the CIA/Mossad, did contribute towards Erdogans ultimate decision to purchase the S-400, however by doing so Erdogan pretty much burned both his bridges.
Turkey now finds itself in a similar situation regarding its tank program, which is effectively stuck in the mud. Now Turkey has had to put the Altay turret onto old Leopard 2 hulls because the Altay still lacks an engine. At the moment Turkey is looking to purchase motors from Ukraine however Ukraine is already behind on its outstanding commitments to deliver T-84 tanks to Thailand. Now with the threat of a war with Russia looming large, it seems very unlikely that Ukraine would be willing to go through with such a deal.
As far as fighter jets are concerned. Turkey has now teamed up with Pakistan and Azerbaijan to produce a 5th generation fighter jet, but it remains to be seen how that's even possible. Turkey and Pakistan are both economically in dire straits. Azerbaijan on the other hand cannot afford to fund such a program by itself.
Turkey recently tried to purchase dozens of F-16s from the US along with 80 modernization kits. Turkey obviously can't even modernize its F-16s or reverse engineer the F-16 and build a viable 4th generation fighter jet. Pakistan has the JF-17, which is a poor mans F-16, but that was built with help from China. Without help from China it's extremely unlikely that Turkey, Pakistan, Azerbaijan can build a 5th generation fighter jet out of thin air.
Another theory floating around regarding the S-400 deal is that with the massive devaluation of Turkeys currency recently, that Turkey really cannot afford to give up precious foreign currency reserves at this point in time. Therefore to save face, perhaps Turkey is bringing up various issues simply to stall the deal and save face until the economy stabilizes.
At the end of the day, Erdogans impulsive decision making regarding the S-400/Patriot F-35/F-16/Altay are an excellent reference on how a middle power with regional / global ambitions should not conduct diplomacy. While trying to play both sides in an attempt to garner the maximum benefit, Erdogan has effectively shot himself in the foot, with nowhere to go as he has burnt all of his bridges to both east and west. However in the end, how this tragic comedy will play out, remains to be seen.
Just wanted to clarify some thing about ToT in general because it may have different meaning for some people...At least from my experience in the Western defence industries that no source code will be given to any ToT customer..All that relates to Software ToT is what is called "Interface Control Doucument" or ICD...ICDs allow customers to hook up their own equipment or systems to the systems they buy with a ToT..it includes the communication Protocols, timmings and "messages" That the "host" will accept from outside..or gives to the outside...Many of the large systems heavy on the software codes such as AD or radars have legacy codes that are even hard for the original equipment supplier to open up..remember if you change a single code in such a system you need to qualify the entire software through tests... a very expensive task.