Question: I have a Nikon D3200 and just started shooting in Raw.

Raw files are 18-24mb, and if I convert them to JPEG using Nikon's ViewNX 2, I get 8-12mb files at the top quality and resolution using sRGB; the same size that I would get out-of-camera shooting in JPG with the maximum quality.

Instead using Darktable with the same options (quality 100 and sRGB at the maximum resolution), I get files of 25-30mb, which is a lot — even more than the original Raw. 

Is there a reason for that? How can I change it? If it's not possible to change, which setting would you advise me to use in Darktable to get smaller files without loosing too much quality?

Answer: 
It seems that the large file size is expected for the settings you chose.

When I take a NEF image from a Nikon D5100 and convert it to JPEG using the sRGB colour space and quality 100, the result is about 18MB in size. Doing the same with dcraw and ImageMagick's convert also leads to a 18MB file.

JPEG 100 quality should probably be never needed. If you want lossless files, use TIFF. For display JPEG 100 is not needed, you can safely use something like 95 and not be able to tell the difference.

What JPEG compression to pick can be researched further and there are questions about this here, but picking a value in the 90s will significantly reduce the size and be fit for purpose for most applications.
Different encoders use different values for the maximum quality. While JPEG is great at reducing file size by allowing images to be simplified in subtle ways, it's a one trick pony that doesn't look for patterns across the entire image that would allow for the size to be reduced losslessly.

The RAW file on the other hand is likely using a general purpose lossless compression that looks finds patterns that the JPEG encoder isn't finding. That, plus the overhead of the JPEG file format can result in a larger overall file than the original RAW potentially.

As far as different sizes for max quality between encoders, that's simply a result of the difference between values used when encoding "100%". It still isn't lossless and simplification still occurs, but the level of simplification can very from one program to another. Particularly at the higher qualities, relatively small amounts of quality gain can result in significantly more data being needed since you are adding on least significant bits of an already large number of values.