In a pact aimed at curbing the spread of nuclear weapons, the United States and 14 other advanced nations agreed on ground rules for the export of their nuclear technology today.

The agreement, nailed down after two days of closed-door meetings here, climaxes 30 months of secret bargaining. In effect, the world's nuclear salesmen - East and West - customers from using the plants and knowhow they buy for making bombs.

Those subscribing to the code also include the Soviet Union and three East-bloc nations; Britain, France, West Germany, Canada and Japan; and five other industrialized European countries.

Since the United States took the initiative in April 1975 and called in five other nations, the Nuclear Suppliers' Group, as the club is called, has been wrestling with how to sell foreigners the capacity to produce nuclear energy but bar them from making weapons.

Withoug an agreement, an aggressive seller could win away more customers by relaxing the terms of any deal. So the code agreed on today rules out competition in this area at least.

The guidelines themselves will not be made public for several months, but according to authoritative sources, they contain these points:

Every customer must agree to inspection his nuclear operation by the International Atomic Energy Agency, the United Nations body in Vienna, and accept all the agency's other safeguards against bomb-making.

Every customer must pledge that he will not attempt to set off any nuclear explosion, even for so-called peaceful purposes.

Every customer must demonstrate his ability to protect bomb-making materials from theft or sabotage.

Every customer must promise he will not try to evade these safeguards by copying plants he has bought.

Every customer must promise that any re-export or sale to a third nation of imported nuclear materials will be governed by these same rules.

Virtually all of this code had been agreed in principle more than a year ago by the members of the suppliers' group. Then latest session here, it is understood, was devoted largely to sharpening, tightening and harmonizing language. In addition, it was learned, this final meeting also adopted procedures for dealing with violators.

The code, a six-page text, will go to the head of the International Atomic Energy Agency after each of the 15 government has reviewed it. The guidelines are not supposed to be published generally until Vienna has had a look.

Despite today's announced agreement, it is clear that the 15 are not in accord on all points. U.S. officials, for example, suggested that the group might be enlarged in the future, but the British contended that expansion is not envisaged.

The other members are Poland, East Germany, Czecholovakia, the Netherlands, Italy, Belgium, Sweden and Switzerland.

The U.S. delegation was led by Joseph Nye, deputy to the under secretary of state for security assistance, science and technology.

He said today's agreement "proved that in matters of nuclear energy, the countries have decided their larger concerns about proliferation are more important than short-term commercial adantages. They have agreed on principles to put that in practice."

He denied reports in the British press that the United States had "softened" President Carter's stance against the spread of weapons to reach the agreement here.