This is bad practice, please don’t do that.
library
hs-source-dirs:
src
exposed-modules:
Data.Password.Validate
if flag(argon2)
exposed-modules:
Data.Password.Argon2
if flag(bcrypt)
exposed-modules:
Data.Password.Bcrypt
if flag(pbkdf2)
exposed-modules:
Data.Password.PBKDF2
if flag(scrypt)
exposed-modules:
Data.Password.Scrypt
What people forget here is that you can’t enable flags of dependencies through the cabal file.
If someone wrote a library depending on Data.Password.Scrypt, which happens to be in your depgraph, and the user disabled -scrypt, you’ll get an obscure compilation failure. If your feature flag is off by default, then that actually makes your package broken for hackage.
Exposed API should not depend on flags: Educate (or prevent) users from making flag-dependent API · Issue #8128 · haskell/cabal · GitHub