Use dìng (fourth tone) when the character means the ACTION of fastening: driving a nail in, stapling pages, pinning fabric, sewing a button on. Anchor compound:
钉书机 (stapler — literally 'staple-paper machine'). Inside the idiom
板上钉钉 (set in stone), both readings appear in order: dìng for the action of nailing, then dīng for the nail itself.