diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,2 +1,33 @@
+{-# LANGUAGE CPP #-}
+{-# OPTIONS_GHC -Wall #-}
+module Main (main) where
+
+#ifndef MIN_VERSION_cabal_doctest
+#define MIN_VERSION_cabal_doctest(x,y,z) 0
+#endif
+
+#if MIN_VERSION_cabal_doctest(1,0,0)
+
+import Distribution.Extra.Doctest ( defaultMainWithDoctests )
+main :: IO ()
+main = defaultMainWithDoctests "doctests"
+
+#else
+
+#ifdef MIN_VERSION_Cabal
+-- If the macro is defined, we have new cabal-install,
+-- but for some reason we don't have cabal-doctest in package-db
+--
+-- Probably we are running cabal sdist, when otherwise using new-build
+-- workflow
+#warning You are configuring this package without cabal-doctest installed. \
+         The doctests test-suite will not work as a result. \
+         To fix this, install cabal-doctest before configuring.
+#endif
+
 import Distribution.Simple
+
+main :: IO ()
 main = defaultMain
+
+#endif
diff --git a/package.yaml b/package.yaml
deleted file mode 100644
--- a/package.yaml
+++ /dev/null
@@ -1,68 +0,0 @@
-name:                servant-auth-docs
-version:             0.2.7.0
-synopsis:            servant-docs/servant-auth compatibility
-description:         Please see README.md
-homepage:            http://github.com/plow-technologies/servant-auth#readme
-license:             BSD3
-license-file:        LICENSE
-author:              Julian K. Arni
-maintainer:          jkarni@gmail.com
-category:            Web, Servant, Authentication
-copyright:           (c) Julian K. Arni
-github:              plow-technologies/servant-auth
-tested-with:         GHC == 7.10.2, GHC == 8.0.1
-
-ghc-options: -Wall
-
-extra-source-files:
-  - package.yaml
-
-dependencies:
-  - base >= 4.7 && < 4.10
-  - text
-  - servant-docs
-  - servant
-  - servant-auth == 0.2.*
-  - lens
-
-
-default-extensions:
-  - AutoDeriveTypeable
-  - ConstraintKinds
-  - DataKinds
-  - DefaultSignatures
-  - DeriveFoldable
-  - DeriveFunctor
-  - DeriveGeneric
-  - DeriveTraversable
-  - FlexibleContexts
-  - FlexibleInstances
-  - FunctionalDependencies
-  - GADTs
-  - KindSignatures
-  - MultiParamTypeClasses
-  - OverloadedStrings
-  - RankNTypes
-  - ScopedTypeVariables
-  - TypeFamilies
-  - TypeOperators
-
-library:
-  source-dirs:      src
-  other-modules:    []
-
-tests:
-  spec:
-    main:            Spec.hs
-    source-dirs:     test
-    dependencies:
-      - servant-auth-docs
-      - hspec > 2 && < 3
-      - QuickCheck >= 2.8 && < 2.10
-  doctest:
-    main:            Doctest.hs
-    source-dirs:     test
-    dependencies:
-      - doctest >= 0.9 && < 0.12
-      - Glob >= 0.7 && < 0.8
-      - yaml == 0.8.*
diff --git a/servant-auth-docs.cabal b/servant-auth-docs.cabal
--- a/servant-auth-docs.cabal
+++ b/servant-auth-docs.cabal
@@ -1,9 +1,5 @@
--- This file has been generated from package.yaml by hpack version 0.15.0.
---
--- see: https://github.com/sol/hpack
-
 name:           servant-auth-docs
-version:        0.2.7.0
+version:        0.2.8.0
 synopsis:       servant-docs/servant-auth compatibility
 description:    Please see README.md
 category:       Web, Servant, Authentication
@@ -14,12 +10,13 @@
 copyright:      (c) Julian K. Arni
 license:        BSD3
 license-file:   LICENSE
-tested-with:    GHC == 7.10.2, GHC == 8.0.1
-build-type:     Simple
+tested-with:    GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.1
+build-type:     Custom
 cabal-version:  >= 1.10
 
-extra-source-files:
-    package.yaml
+custom-setup
+  setup-depends:
+    base, Cabal, cabal-doctest >=1.0.2 && <1.1
 
 source-repository head
   type: git
@@ -31,36 +28,28 @@
   default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators
   ghc-options: -Wall
   build-depends:
-      base >= 4.7 && < 4.10
+      base >= 4.8 && < 4.11
     , text
     , servant-docs
     , servant
-    , servant-auth == 0.2.*
+    , servant-auth == 0.3.*
     , lens
   exposed-modules:
       Servant.Auth.Docs
   default-language: Haskell2010
 
-test-suite doctest
-  type: exitcode-stdio-1.0
-  main-is: Doctest.hs
-  hs-source-dirs:
-      test
-  default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators
-  ghc-options: -Wall
+test-suite doctests
+  type:                exitcode-stdio-1.0
+  main-is:             doctests.hs
   build-depends:
-      base >= 4.7 && < 4.10
-    , text
-    , servant-docs
-    , servant
-    , servant-auth == 0.2.*
-    , lens
-    , doctest >= 0.9 && < 0.12
-    , Glob >= 0.7 && < 0.8
-    , yaml == 0.8.*
-  other-modules:
-      Spec
-  default-language: Haskell2010
+    base,
+    doctest >= 0.11.3 && <0.14,
+    servant-auth-docs,
+    QuickCheck >= 2.8 && <2.11,
+    template-haskell
+  ghc-options:         -Wall -threaded
+  hs-source-dirs:      test
+  default-language:    Haskell2010
 
 test-suite spec
   type: exitcode-stdio-1.0
@@ -69,16 +58,21 @@
       test
   default-extensions: AutoDeriveTypeable ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveTraversable FlexibleContexts FlexibleInstances FunctionalDependencies GADTs KindSignatures MultiParamTypeClasses OverloadedStrings RankNTypes ScopedTypeVariables TypeFamilies TypeOperators
   ghc-options: -Wall
+  build-tool-depends: hspec-discover:hspec-discover
+
+  -- dependencies with bounds inherited from the library stanza
   build-depends:
-      base >= 4.7 && < 4.10
+      base
     , text
     , servant-docs
     , servant
-    , servant-auth == 0.2.*
+    , servant-auth
     , lens
-    , servant-auth-docs
+
+  -- test dependencies
+  build-depends:
+      servant-auth-docs
     , hspec > 2 && < 3
-    , QuickCheck >= 2.8 && < 2.10
-  other-modules:
-      Doctest
+    , QuickCheck >= 2.8 && < 2.11
+
   default-language: Haskell2010
diff --git a/src/Servant/Auth/Docs.hs b/src/Servant/Auth/Docs.hs
--- a/src/Servant/Auth/Docs.hs
+++ b/src/Servant/Auth/Docs.hs
@@ -8,14 +8,13 @@
   -- >>> putStr $ markdown $ docs (Proxy :: Proxy API)
   -- ## GET /
   -- ...
-  -- #### Authentication
+  -- ... Authentication
   -- ...
   -- This part of the API is protected by the following authentication mechanisms:
   -- ...
   --  * JSON Web Tokens ([JWTs](https://en.wikipedia.org/wiki/JSON_Web_Token))
   --  * [Cookies](https://en.wikipedia.org/wiki/HTTP_cookie)
   --  * [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication)
-  -- ...
   -- ...
   -- Clients must supply the following data
   -- ...
diff --git a/test/Doctest.hs b/test/Doctest.hs
deleted file mode 100644
--- a/test/Doctest.hs
+++ /dev/null
@@ -1,26 +0,0 @@
-module Main (main) where
-
--- Runs doctest on all files in "src" dir. Assumes:
---   (a) You are using hpack
---   (b) The top-level "default-extensions" are the only extensions besides the
---   ones in the files.
-
-import System.FilePath.Glob (glob)
-import Test.DocTest (doctest)
-import Data.Yaml
-
-newtype Exts = Exts { getExts :: [String] }
-  deriving (Eq, Show, Read)
-
-instance FromJSON Exts where
-  parseJSON (Object v) = Exts <$> v .: "default-extensions"
-  parseJSON _ = fail "expecting object"
-
-main :: IO ()
-main = do
-  hpack' <- decodeFile "package.yaml"
-  hpack <- case hpack' of
-    Nothing -> return $ Exts []
-    Just v  -> return v
-  files <- glob "src/**/*.hs"
-  doctest $ files ++ fmap ("-X" ++) (getExts hpack)
diff --git a/test/doctests.hs b/test/doctests.hs
new file mode 100644
--- /dev/null
+++ b/test/doctests.hs
@@ -0,0 +1,12 @@
+module Main where
+
+import Build_doctests (flags, pkgs, module_sources)
+import Data.Foldable (traverse_)
+import Test.DocTest
+
+main :: IO ()
+main = do
+    traverse_ putStrLn args
+    doctest args
+  where
+    args = flags ++ pkgs ++ module_sources
