The use of antiviral drugs can promote the appearance of mutations in the target protein that increase the resistance of the virus to the treatment. This is also the case of nirmatrelvir, a covalent inhibitor of the 3CL protease of SARS-CoV-2. In this work we show how the by-residue decomposition of noncovalent interactions established between the drug and the enzyme, in combination with an analysis of natural occurring mutations, can be used to detect potential mutations in 3CL protease conferring resistance to nirmatrelvir. We also investigate the consequences of these mutations on the reaction mechanism to form the covalent enzyme-inhibitor complex. In particular, we show that the E166V variant of the protease shows a smaller affinity by nirmatrelvir and a larger activation free energy for the formation of the covalent complex, both factors contributing to an increased resistance to the treatment with this drug. The conclusions derived from our work can be used to anticipate the consequences of the introduction of nirmatrelvir in the fitness landscape of the virus and to design new inhibitors to prevent resistance mechanisms.