Something along the lines of:
import GHC.Version qualified
main :: IO ()
main = print $ GHC.Version.current
-- would print Version 8 10 7
A roundabout way is to execute ghc --version from shell:
import System.Process
main = system "ghc --version"
but this may be incorrect when the running GHC isn't the same as the ghc in PATH.