diff --git a/cabal-debian.cabal b/cabal-debian.cabal
--- a/cabal-debian.cabal
+++ b/cabal-debian.cabal
@@ -1,5 +1,5 @@
 Name:           cabal-debian
-Version:        4.0.4
+Version:        4.0.5
 License:        BSD3
 License-File:   debian/copyright
 Author:         David Fox <dsf@seereason.com>
@@ -134,11 +134,17 @@
  complex packaging issues.  For documentation of the executable run
  @cabal-debian --help@, for documentation of the library API follow
  the link to the @Debian.Debianize@ module below.
+
 Flag tests
   Description: enable the unit test executable (disabled by default because it has a lot of wacky dependencies.)
   Default: False
   Manual: True
 
+-- flag local-debian
+--   Description: Link directly to the source of the debian library
+--   Default: False
+--   Manual: True
+
 Source-Repository head
   type: darcs
   location: http://src.seereason.com/debian-tools
@@ -147,13 +153,11 @@
  Hs-Source-Dirs: src
  GHC-Options: -Wall -O2
  Build-Depends:
-   ansi-wl-pprint,
    base < 5,
    Cabal >= 1.9,
    containers,
    data-lens,
    data-lens-template,
-   debian >= 3.71,
    Diff,
    directory,
    filepath,
@@ -191,12 +195,16 @@
    Debian.Debianize.SubstVars
    Debian.Debianize.Types
    Debian.Debianize.Types.Atoms
-   Debian.Debianize.Types.Base
    Debian.Debianize.Types.BinaryDebDescription
    Debian.Debianize.Types.SourceDebDescription
    Debian.Debianize.VersionSplits
  Other-Modules:
    Debian.Orphans
+--  if flag(local-debian)
+--    Hs-Source-Dirs: ., ../../haskell-debian
+--    Build-Depends: regex-compat, bytestring, process-listlike, network, old-locale, time
+--  else
+ Build-depends: debian >= 3.81
 
 Executable cabal-debian
  Hs-Source-Dirs: src
@@ -224,6 +232,11 @@
    text,
    unix,
    utf8-string
+--  if flag(local-debian)
+--    Hs-Source-Dirs: ., ../../haskell-debian
+--    Build-Depends: regex-compat, bytestring, process-listlike, network, old-locale, time
+--  else
+ Build-Depends: debian >= 3.81
 
 Executable cabal-debian-tests
  Hs-Source-Dirs: src
@@ -252,3 +265,8 @@
    text,
    unix,
    utf8-string
+--  if flag(local-debian)
+--    Hs-Source-Dirs: ., ../../haskell-debian
+--    Build-Depends: regex-compat, bytestring, process-listlike, network, old-locale, time
+--  else
+ Build-depends: debian >= 3.81
diff --git a/changelog b/changelog
--- a/changelog
+++ b/changelog
@@ -1,3 +1,18 @@
+haskell-cabal-debian (4.0.5) unstable; urgency=low
+
+  * Changes for debian-3.81 - use the pretty printer in Debian.Pretty
+    instead of ansi-wl-pprint.
+
+ -- David Fox <dsf@seereason.com>  Tue, 14 Jan 2014 05:02:59 -0800
+
+haskell-cabal-debian (4.0.4) unstable; urgency=low
+
+  * Restore the test data, the problem I had with long filenames
+    is solved by using cabal sdist to create the tarball rather
+    than runhaskell Setup sdist.
+
+ -- David Fox <dsf@seereason.com>  Wed, 18 Dec 2013 09:37:34 -0800
+
 haskell-cabal-debian (4.0.3) unstable; urgency=low
 
   * Include the build dependencies of the executables in the debian
diff --git a/src/Data/Algorithm/Diff/Pretty.hs b/src/Data/Algorithm/Diff/Pretty.hs
--- a/src/Data/Algorithm/Diff/Pretty.hs
+++ b/src/Data/Algorithm/Diff/Pretty.hs
@@ -1,10 +1,11 @@
+{-# LANGUAGE OverloadedStrings #-}
 module Data.Algorithm.Diff.Pretty
     ( prettyDiff
     ) where
 
 import Data.Algorithm.Diff (Diff(..))
 import Data.Monoid (mconcat, (<>))
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty), Doc, text, empty)
+import Debian.Pretty (Pretty(pretty), Doc, text, empty)
 
 -- | Format the output of 'contextDiff' to look approximately like the
 -- output of the unix diff command.
diff --git a/src/Debian/Debianize/Files.hs b/src/Debian/Debianize/Files.hs
--- a/src/Debian/Debianize/Files.hs
+++ b/src/Debian/Debianize/Files.hs
@@ -22,12 +22,12 @@
 import qualified Debian.Debianize.Types.Atoms as T
 import qualified Debian.Debianize.Types.BinaryDebDescription as B
 import qualified Debian.Debianize.Types.SourceDebDescription as S
+import Debian.Pretty (pretty)
 import Debian.Relation (Relations, BinPkgName(BinPkgName))
 import Distribution.License (License(AllRightsReserved))
 import Prelude hiding (init, unlines, writeFile, log)
 --import System.Directory (getCurrentDirectory)
 import System.FilePath ((</>))
-import Text.PrettyPrint.ANSI.Leijen (pretty)
 
 type FilesT m = WriterT [(FilePath, Text)] (DebT m)
 
diff --git a/src/Debian/Debianize/Finalize.hs b/src/Debian/Debianize/Finalize.hs
--- a/src/Debian/Debianize/Finalize.hs
+++ b/src/Debian/Debianize/Finalize.hs
@@ -40,6 +40,7 @@
 import Debian.Debianize.VersionSplits (packageRangesFromVersionSplits)
 import Debian.Orphans ()
 import Debian.Policy (getDebhelperCompatLevel, haskellMaintainer, PackageArchitectures(Any, All), PackagePriority(Optional), Section(..))
+import Debian.Pretty (pretty)
 import Debian.Relation (BinPkgName, BinPkgName(BinPkgName), Relation, Relation(Rel), Relations)
 import qualified Debian.Relation as D (BinPkgName(BinPkgName), Relation(..), Relations, VersionReq(EEQ, GRE, LTE, SGR, SLT))
 import Debian.Release (parseReleaseName)
@@ -48,7 +49,7 @@
 import Distribution.Package (Dependency(..), PackageIdentifier(..), PackageName(PackageName))
 import Distribution.PackageDescription (PackageDescription)
 import Distribution.PackageDescription as Cabal (allBuildInfo, BuildInfo(buildTools, extraLibs, pkgconfigDepends), Executable(..), BuildInfo(..))
-import qualified Distribution.PackageDescription as Cabal (BuildInfo(buildable), Executable(buildInfo, exeName), PackageDescription(buildDepends, dataFiles, executables, library, package), PackageDescription(license))
+import qualified Distribution.PackageDescription as Cabal (PackageDescription(buildDepends, dataFiles, executables, library, package), PackageDescription(license))
 import Distribution.Version (anyVersion, asVersionIntervals, earlierVersion, foldVersionRange', fromVersionIntervals, intersectVersionRanges, isNoVersion, laterVersion, orEarlierVersion, orLaterVersion, toVersionIntervals, unionVersionRanges, VersionRange, withinVersion)
 import Distribution.Version.Invert (invertVersionRange)
 import Prelude hiding (init, log, map, unlines, unlines, writeFile)
@@ -56,7 +57,6 @@
 import System.FilePath ((<.>), (</>), makeRelative, splitFileName, takeDirectory, takeFileName)
 import System.IO.Unsafe (unsafePerformIO)
 import System.Process (readProcessWithExitCode)
-import Text.PrettyPrint.ANSI.Leijen (pretty)
 
 -- | Given an Atoms value, get any additional configuration
 -- information from the environment, read the cabal package
diff --git a/src/Debian/Debianize/Goodies.hs b/src/Debian/Debianize/Goodies.hs
--- a/src/Debian/Debianize/Goodies.hs
+++ b/src/Debian/Debianize/Goodies.hs
@@ -32,6 +32,7 @@
 import qualified Debian.Debianize.Types.Atoms as T
 import qualified Debian.Debianize.Types.BinaryDebDescription as B
 import Debian.Orphans ()
+import Debian.Pretty (Pretty(pretty))
 import Debian.Policy (apacheLogDirectory, apacheErrorLog, apacheAccessLog, databaseDirectory, serverAppLog, serverAccessLog)
 import Debian.Relation (BinPkgName(BinPkgName), Relation(Rel))
 import Distribution.Package (PackageIdentifier(..), PackageName(PackageName))
@@ -39,7 +40,6 @@
 import Distribution.Text (display)
 import Prelude hiding (writeFile, init, unlines, log, map)
 import System.FilePath ((</>))
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty))
 
 showCommand :: String -> [String] -> String
 showCommand cmd args =
diff --git a/src/Debian/Debianize/Input.hs b/src/Debian/Debianize/Input.hs
--- a/src/Debian/Debianize/Input.hs
+++ b/src/Debian/Debianize/Input.hs
@@ -40,7 +40,7 @@
      logrotateStanza, link, install, installDir, intermediateFiles, compilerVersion, cabalFlagAssignments, verbosity)
 import Debian.Debianize.Monad (Atoms, DebT, execDebT)
 import Debian.Debianize.Prelude (getDirectoryContents', withCurrentDirectory, readFileMaybe, read', intToVerbosity', (~=), (~?=), (+=), (++=), (+++=))
-import Debian.Debianize.Types.Base (Top(unTop))
+import Debian.Debianize.Types (Top(unTop))
 import Debian.Orphans ()
 import Debian.Policy (Section(..), parseStandardsVersion, readPriority, readSection, parsePackageArchitectures, parseMaintainer,
                       parseUploaders, readSourceFormat, getDebianMaintainer)
diff --git a/src/Debian/Debianize/Monad.hs b/src/Debian/Debianize/Monad.hs
--- a/src/Debian/Debianize/Monad.hs
+++ b/src/Debian/Debianize/Monad.hs
@@ -18,14 +18,8 @@
     ) where
 
 import Control.Monad.State (evalState, evalStateT, execState, execStateT, runState, State, StateT(runStateT))
-import Data.Map as Map (alter)
-import Data.Version (Version)
 import Debian.Debianize.Types.Atoms (Atoms)
-import Debian.Debianize.Types (debianNameMap)
-import Debian.Debianize.Prelude ((%=))
-import Debian.Debianize.VersionSplits (insertSplit, makePackage, VersionSplits)
 import Debian.Orphans ()
-import Distribution.Package (PackageName)
 import Prelude hiding (init, log, unlines)
 
 type DebT m = StateT Atoms m
diff --git a/src/Debian/Debianize/Output.hs b/src/Debian/Debianize/Output.hs
--- a/src/Debian/Debianize/Output.hs
+++ b/src/Debian/Debianize/Output.hs
@@ -34,13 +34,13 @@
 import qualified Debian.Debianize.Types as T
 import qualified Debian.Debianize.Types.BinaryDebDescription as B (package)
 import qualified Debian.Debianize.Types.SourceDebDescription as S (source)
+import Debian.Pretty (Pretty(pretty))
 import Prelude hiding (unlines, writeFile, (.))
 import System.Directory (createDirectoryIfMissing, doesFileExist, getPermissions, Permissions(executable), setPermissions)
 import System.Environment (getEnv)
 import System.Exit (ExitCode(ExitSuccess))
 import System.FilePath ((</>), takeDirectory)
 import System.Process (readProcessWithExitCode)
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty))
 
 -- | Run the script in @debian/Debianize.hs@ with the given command
 -- line arguments.  Returns @True@ if the script exists and succeeds.
@@ -125,7 +125,7 @@
     case () of
       _ | oldVersion /= newVersion -> throw (userError ("Version mismatch, expected " ++ show (pretty oldVersion) ++ ", found " ++ show (pretty newVersion)))
         | oldSource /= newSource -> throw (userError ("Source mismatch, expected " ++ show (pretty oldSource) ++ ", found " ++ show (pretty newSource)))
-        | oldPackages /= newPackages -> throw (userError ("Package mismatch, expected " ++ show (pretty oldPackages) ++ ", found " ++ show (pretty newPackages)))
+        | oldPackages /= newPackages -> throw (userError ("Package mismatch, expected " ++ show (map pretty oldPackages) ++ ", found " ++ show (map pretty newPackages)))
         | True -> ()
     where
       oldVersion = logVersion (head (unChangeLog (fromMaybe (error "Missing changelog") (getL T.changelog old))))
diff --git a/src/Debian/Debianize/Prelude.hs b/src/Debian/Debianize/Prelude.hs
--- a/src/Debian/Debianize/Prelude.hs
+++ b/src/Debian/Debianize/Prelude.hs
@@ -37,20 +37,23 @@
     , (+=)
     , (++=)
     , (+++=)
+    , listElemLens
+    , maybeLens
     , fromEmpty
     , fromSingleton
     , Pretty(pretty)
     ) where
 
 import Control.Applicative ((<$>))
+import Control.Category ((.))
 import Control.Exception as E (catch, try, bracket, IOException)
 import Control.Monad (when)
 import Control.Monad.Reader (ReaderT, ask)
 import Control.Monad.State (MonadState, StateT, get, put)
 import Data.Char (isSpace)
 import qualified Data.Lens.Lazy as Lens ((~=), (%=))
+import Data.Lens.Lazy (getL, Lens, lens, modL, setL)
 import Data.List as List (isSuffixOf, intercalate, map, lines)
-import Data.Lens.Lazy (Lens, modL)
 import Data.Map as Map (Map, foldWithKey, empty, fromList, findWithDefault, insert, map, lookup, insertWith)
 import Data.Maybe (catMaybes, mapMaybe, listToMaybe, fromMaybe, fromJust)
 import Data.Monoid (Monoid, (<>), mappend)
@@ -60,19 +63,19 @@
 import Data.Text.IO (hGetContents)
 import Debian.Control (parseControl, lookupP, Field'(Field), unControl, stripWS)
 import Debian.Orphans ()
+import Debian.Pretty (Pretty(pretty))
 import Debian.Version (DebianVersion, prettyDebianVersion)
 import Debian.Version.String (parseDebianVersion)
 import qualified Debian.Relation as D
 import Distribution.Package (PackageIdentifier(..), PackageName(..))
 import Distribution.Verbosity (Verbosity, intToVerbosity)
-import Prelude hiding (map, lookup)
+import Prelude hiding (map, lookup, (.))
 import System.Directory (doesFileExist, doesDirectoryExist, removeFile, renameFile, removeDirectory, getDirectoryContents, getCurrentDirectory, setCurrentDirectory)
 import System.Exit(ExitCode(ExitSuccess, ExitFailure))
 import System.FilePath ((</>), dropExtension)
 import System.IO (IOMode (ReadMode), withFile, openFile, hSetBinaryMode)
 import System.IO.Error (isDoesNotExistError, catchIOError)
 import System.Process (readProcessWithExitCode, showCommandForUser)
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty), text)
 
 curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d
 curry3 f a b c = f (a, b, c)
@@ -185,12 +188,12 @@
 -- Would like to call pretty instead of D.prettyRelations, but the
 -- Pretty instance for [a] doesn't work for us.
 showDeps :: [[D.Relation]] -> String
-showDeps = show . D.prettyRelations
+showDeps = show . pretty
 
 -- The extra space after prefix' is here for historical reasons(?)
 showDeps' :: [a] -> [[D.Relation]] -> String
 showDeps' prefix xss =
-    intercalate  ("\n" ++ prefix' ++ " ") . Prelude.lines . show . D.prettyRelations $ xss
+    intercalate  ("\n" ++ prefix' ++ " ") . Prelude.lines . show . pretty $ xss
     where prefix' = List.map (\ _ -> ' ') prefix
 
 -- | From Darcs.Utils - set the working directory and run an IO operation.
@@ -256,7 +259,7 @@
 
 -- | If the current value of getL x is Nothing, replace it with f.
 maybeL :: Lens a (Maybe b) -> Maybe b -> a -> a
-maybeL lens mb x = modL lens (maybe mb Just) x
+maybeL l mb x = modL l (maybe mb Just) x
 
 indent :: [Char] -> String -> String
 indent prefix s = unlines (List.map (prefix ++) (List.lines s))
@@ -284,31 +287,55 @@
 
 -- | Set a lens value.  (This is a version of Data.Lens.Lazy.~= that returns () instead of b.)
 (~=) :: Monad m => Lens a b -> b -> StateT a m ()
-lens ~= x = lens Lens.~= x >> return ()
+l ~= x = l Lens.~= x >> return ()
 
 -- | Set @b@ if it currently isNothing and the argument isJust, that is
 --  1. Nothing happens if the argument isNothing
 --  2. Nothing happens if the current value isJust
 (~?=) :: Monad m => Lens a (Maybe b) -> Maybe b -> StateT a m ()
-lens ~?= (Just x) = lens Lens.%= maybe (Just x) Just >> return ()
+l ~?= (Just x) = l Lens.%= maybe (Just x) Just >> return ()
 _ ~?= _ = return ()
 
 -- | Modify a value.  (This is a version of Data.Lens.Lazy.%= that returns () instead of a.)
 (%=) :: Monad m => Lens a b -> (b -> b) -> StateT a m ()
-lens %= f = lens Lens.%= f >> return ()
+l %= f = l Lens.%= f >> return ()
 
 -- | Insert an element into a @(Set b)@
 (+=) :: (Monad m, Ord b) => Lens a (Set b) -> b -> StateT a m ()
-lens += x = lens %= Set.insert x
+l += x = l %= Set.insert x
 
 -- | Insert an element into a @(Map b c)@
 (++=) :: (Monad m, Ord b) => Lens a (Map b c) -> (b, c) -> StateT a m ()
-lens ++= (k, a) = lens %= Map.insert k a
+l ++= (k, a) = l %= Map.insert k a
 
 -- | Insert an element into a @(Map b (Set c))@
 (+++=) :: (Monad m, Ord b, Monoid c) => Lens a (Map b c) -> (b, c) -> StateT a m ()
-lens +++= (k, a) = lens %= Map.insertWith mappend k a
+l +++= (k, a) = l %= Map.insertWith mappend k a
 
+listElemLens :: (a -> Bool) -> Lens [a] (Maybe a)
+listElemLens p =
+    lens lensGet lensPut
+    where
+      lensGet xs =
+          case span (not . p) xs of
+            (_, x : _) -> Just x
+            _ -> Nothing
+      lensPut Nothing xs =
+          case span (not . p) xs of
+            (pre, _ : post) -> pre ++ post
+            _ -> xs
+      lensPut (Just x) xs =
+          case span (not . p) xs of
+            (pre, _ : post) -> pre ++ (x : post)
+            _ -> xs ++ [x]
+
+maybeLens :: a -> Lens a b -> Lens (Maybe a) b
+maybeLens def l =
+    lens (getL l . fromMaybe def)
+         (\ a b -> case (a, b) of
+                     (_, Nothing) -> Just (setL l a def)
+                     (_, Just b') -> Just (setL l a b'))
+
 fromEmpty :: Set a -> Set a -> Set a
 fromEmpty d s | Set.null s = d
 fromEmpty _ s = s
@@ -321,7 +348,7 @@
       xs -> multiple xs
 
 instance Pretty PackageIdentifier where
-    pretty p = pretty (pkgName p) <> text "-" <> pretty (pkgVersion p)
+    pretty p = pretty (pkgName p) <> pretty "-" <> pretty (pkgVersion p)
 
 instance Pretty PackageName where
-    pretty (PackageName s) = text s
+    pretty (PackageName s) = pretty s
diff --git a/src/Debian/Debianize/SubstVars.hs b/src/Debian/Debianize/SubstVars.hs
--- a/src/Debian/Debianize/SubstVars.hs
+++ b/src/Debian/Debianize/SubstVars.hs
@@ -27,6 +27,7 @@
 import Debian.Debianize.Types (Top)
 import qualified Debian.Debianize.Types.Atoms as T
 import Debian.Orphans ()
+import Debian.Pretty (pretty)
 import Debian.Relation (BinPkgName(BinPkgName), Relation, Relations)
 import qualified Debian.Relation as D (BinPkgName(BinPkgName), ParseRelations(parseRelations), Relation(Rel), Relations, VersionReq(GRE))
 import Distribution.Package (Dependency(..), PackageName(PackageName))
@@ -37,7 +38,6 @@
 import Prelude hiding (unlines)
 import System.Directory (doesDirectoryExist, getDirectoryContents)
 import System.FilePath ((</>))
-import Text.PrettyPrint.ANSI.Leijen (pretty)
 
 -- | Expand the contents of the .substvars file for a library package.
 -- Each cabal package corresponds to a directory <name>-<version>,
diff --git a/src/Debian/Debianize/Tests.hs b/src/Debian/Debianize/Tests.hs
--- a/src/Debian/Debianize/Tests.hs
+++ b/src/Debian/Debianize/Tests.hs
@@ -16,7 +16,7 @@
 import Data.Maybe (fromMaybe)
 import Data.Monoid ((<>), mconcat, mempty)
 import Data.Set as Set (fromList, singleton, union)
-import qualified Data.Text as T (intercalate, lines, pack, split, Text, unlines)
+import Data.Text as Text (intercalate, lines, split, Text, unlines)
 import Data.Version (Version(Version))
 import Debian.Changes (ChangeLog(..), ChangeLogEntry(..), parseEntry)
 import Debian.Debianize.DebianName (mapCabal, splitCabal)
@@ -31,6 +31,7 @@
 import qualified Debian.Debianize.Types.BinaryDebDescription as B
 import qualified Debian.Debianize.Types.SourceDebDescription as S
 import Debian.Policy (databaseDirectory, PackageArchitectures(All), PackagePriority(Extra), parseMaintainer, Section(MainSection), SourceFormat(Native3), StandardsVersion(..), getDebhelperCompatLevel, getDebianStandardsVersion)
+import Debian.Pretty (pretty, Pretty, text, Doc)
 import Debian.Relation (BinPkgName(..), Relation(..), SrcPkgName(..), VersionReq(..))
 import Debian.Release (ReleaseName(ReleaseName, relName))
 import Debian.Version (parseDebianVersion, buildDebianVersion)
@@ -42,7 +43,6 @@
 import System.Process (readProcessWithExitCode)
 import Test.HUnit hiding ((~?=))
 import Text.ParserCombinators.Parsec.Rfc2822 (NameAddr(..))
-import Text.PrettyPrint.ANSI.Leijen (pretty, Pretty, text)
 
 -- | A suitable defaultAtoms value for the debian repository.
 defaultAtoms :: Monad m => DebT m ()
@@ -108,7 +108,7 @@
           execDebM
             (do defaultAtoms
                 newDebianization log (Just 9) (Just (StandardsVersion 3 9 3 (Just 1)))
-                rulesHead %= (const (Just (T.unlines $
+                rulesHead %= (const (Just (Text.unlines $
                                                 [ "#!/usr/bin/make -f"
                                                 , ""
                                                 , "include /usr/share/cdbs/1/rules/debhelper.mk"
@@ -153,7 +153,7 @@
           execDebM
             (do defaultAtoms
                 newDebianization log (Just 9) (Just (StandardsVersion 3 9 3 (Just 1)))
-                rulesHead %= (const (Just (T.unlines $
+                rulesHead %= (const (Just (Text.unlines $
                                                 ["#!/usr/bin/make -f",
                                                  "",
                                                  "include /usr/share/cdbs/1/rules/debhelper.mk",
@@ -174,15 +174,16 @@
                               logVersion = Debian.Version.parseDebianVersion ("2.6.2" :: String),
                               logDists = [ReleaseName {relName = "unstable"}],
                               logUrgency = "low",
-                              logComments = unlines ["  * Fix a bug constructing the destination pathnames that was dropping",
-                                                     "    files that were supposed to be installed into packages."],
+                              logComments = Prelude.unlines ["  * Fix a bug constructing the destination pathnames that was dropping",
+                                                             "    files that were supposed to be installed into packages."],
                               logWho = "David Fox <dsf@seereason.com>",
                               logDate = "Thu, 20 Dec 2012 06:49:25 -0800"}]
 
 testEntry :: ChangeLogEntry
 testEntry =
     either (error "Error in test changelog entry") fst
-           (parseEntry (unlines [ "haskell-cabal-debian (2.6.2) unstable; urgency=low"
+           (parseEntry (Prelude.unlines
+                                [ "haskell-cabal-debian (2.6.2) unstable; urgency=low"
                                 , ""
                                 , "  * Fix a bug constructing the destination pathnames that was dropping"
                                 , "    files that were supposed to be installed into packages."
@@ -203,7 +204,7 @@
             (do defaultAtoms
                 newDebianization log (Just 7) (Just (StandardsVersion 3 9 4 Nothing))
                 T.sourceFormat ~= Just Native3
-                T.rulesHead ~= Just (T.pack (unlines ["#!/usr/bin/make -f",
+                T.rulesHead ~= Just (Text.unlines  ["#!/usr/bin/make -f",
                                                     "# -*- makefile -*-",
                                                     "",
                                                     "# Uncomment this to turn on verbose mode.",
@@ -246,7 +247,7 @@
                                                     "\tdh clean",
                                                     "\trm -f $(manpages)",
                                                     "",
-                                                    ""]))
+                                                    ""])
                 T.compat ~= Just 7
                 T.copyright ~= Just "This package was debianized by John Goerzen <jgoerzen@complete.org> on\nWed,  6 Oct 2004 09:46:14 -0500.\n\nCopyright information removed from this test data.\n\n"
                 T.source ~= Just (SrcPkgName {unSrcPkgName = "haskell-devscripts"})
@@ -262,7 +263,7 @@
                 T.binaryArchitectures (BinPkgName "haskell-devscripts") ~= Just All
                 T.debianDescription (BinPkgName "haskell-devscripts") ~=
                    Just
-                     (T.intercalate "\n" ["Tools to help Debian developers build Haskell packages",
+                     (intercalate "\n"   ["Tools to help Debian developers build Haskell packages",
                                           " This package provides a collection of scripts to help build Haskell",
                                           " packages for Debian.  Unlike haskell-utils, this package is not",
                                           " expected to be installed on the machines of end users.",
@@ -393,10 +394,10 @@
       fixRules =
           makeRulesHead >>= \ rh -> T.rulesHead %= (\ mt -> (Just . f) (fromMaybe rh mt))
           where
-            f t = T.unlines $ concat $
+            f t = Text.unlines $ concat $
                   map (\ line -> if line == "include /usr/share/cdbs/1/rules/debhelper.mk"
-                                 then ["DEB_SETUP_GHC_CONFIGURE_ARGS = -fbackups", "", line] :: [T.Text]
-                                 else [line] :: [T.Text]) (T.lines t)
+                                 then ["DEB_SETUP_GHC_CONFIGURE_ARGS = -fbackups", "", line] :: [Text]
+                                 else [line] :: [Text]) (Text.lines t)
 {-
           mapAtoms f deb
           where
@@ -481,18 +482,18 @@
              mapM_ (\ b -> T.depends b %= \ deps -> deps ++ [[anyrel (BinPkgName "markdown")]])
                    [(BinPkgName "creativeprompts-production"), (BinPkgName "creativeprompts-development")]
              T.debianDescription (BinPkgName "creativeprompts-development") ~=
-                   Just (T.intercalate "\n" [ "Configuration for running the creativeprompts.com server"
+                   Just (intercalate "\n" [ "Configuration for running the creativeprompts.com server"
                                             , "  Testing version of the blog server, runs on port"
                                             , "  8000 with HTML validation turned on." ])
              T.debianDescription (BinPkgName "creativeprompts-data") ~=
-                   Just (T.intercalate "\n" [ "creativeprompts.com data files"
+                   Just (intercalate "\n" [ "creativeprompts.com data files"
                                             , "  Static data files for creativeprompts.com"])
              T.debianDescription (BinPkgName "creativeprompts-production") ~=
-                   Just (T.intercalate "\n" [ "Configuration for running the creativeprompts.com server"
+                   Just (intercalate "\n" [ "Configuration for running the creativeprompts.com server"
                                             , "  Production version of the blog server, runs on port"
                                             , "  9021 with HTML validation turned off." ])
              T.debianDescription (BinPkgName "creativeprompts-backups") ~=
-                   Just (T.intercalate "\n" [ "backup program for creativeprompts.com"
+                   Just (intercalate "\n" [ "backup program for creativeprompts.com"
                                             , "  Install this somewhere other than creativeprompts.com to run automated"
                                             , "  backups of the database."])
              T.binaryArchitectures (BinPkgName "creativeprompts-production") ~= Just All
@@ -661,22 +662,23 @@
     where
       isUnchanged (Unchanged _ _) = True
       isUnchanged _ = False
-      prettyChange (Unchanged p _) = text ("Unchanged: " <> p <> "\n")
-      prettyChange (Deleted p _) = text ("Deleted: " <> p <> "\n")
+      prettyChange :: Change FilePath Text -> Doc
+      prettyChange (Unchanged p _) = text "Unchanged: " <> pretty p <> text "\n"
+      prettyChange (Deleted p _) = text "Deleted: " <> pretty p <> text "\n"
       prettyChange (Created p b) =
-          text ("Created: " <> p <> "\n") <>
+          text "Created: " <> pretty p <> text "\n" <>
           prettyDiff ("old" </> p) ("new" </> p)
                      -- We use split here instead of lines so we can
                      -- detect whether the file has a final newline
                      -- character.
-                     (contextDiff 2 mempty (T.split (== '\n') b))
+                     (contextDiff 2 mempty (split (== '\n') b))
       prettyChange (Modified p a b) =
-          text ("Modified: " <> p<> "\n") <>
+          text "Modified: " <> pretty p <> text "\n" <>
           prettyDiff ("old" </> p) ("new" </> p)
                      -- We use split here instead of lines so we can
                      -- detect whether the file has a final newline
                      -- character.
-                     (contextDiff 2 (T.split (== '\n') a) (T.split (== '\n') b))
+                     (contextDiff 2 (split (== '\n') a) (split (== '\n') b))
 
 sortBinaryDebs :: DebT IO ()
 sortBinaryDebs = T.binaryPackages %= sortBy (compare `on` getL B.package)
diff --git a/src/Debian/Debianize/Types.hs b/src/Debian/Debianize/Types.hs
--- a/src/Debian/Debianize/Types.hs
+++ b/src/Debian/Debianize/Types.hs
@@ -116,30 +116,25 @@
     , binaryPackages
     ) where
 
-import Debian.Debianize.Types.Base
-import Debian.Debianize.Types.Atoms
 import Control.Category ((.))
-import Data.Lens.Lazy (Lens, lens, iso, getL)
-import Data.Map as Map (Map)
-import Data.Monoid (Monoid(..))
+import Data.Generics (Typeable)
+import Data.Lens.Lazy (Lens, iso, getL)
 import Data.Set as Set (Set)
 import Data.Text (Text)
-import Data.Version (Version)
-import Debian.Changes (ChangeLog)
-import Debian.Debianize.Types.Base (maybeLens, listElemLens)
+import Debian.Debianize.Prelude (maybeLens, listElemLens)
+import Debian.Debianize.Types.Atoms
 import qualified Debian.Debianize.Types.BinaryDebDescription as B
 import qualified Debian.Debianize.Types.SourceDebDescription as S
-import Debian.Debianize.VersionSplits (VersionSplits)
 import Debian.Orphans ()
-import Debian.Policy (PackageArchitectures, PackagePriority, Section, SourceFormat, StandardsVersion)
+import Debian.Policy (PackageArchitectures, PackagePriority, Section, StandardsVersion)
 import Debian.Relation (BinPkgName, Relations, SrcPkgName)
-import Debian.Version (DebianVersion)
-import Distribution.License (License)
-import Distribution.Package (PackageName)
-import Distribution.PackageDescription as Cabal (FlagName, PackageDescription)
-import Distribution.Simple.Compiler (CompilerId)
 import Prelude hiding (init, init, log, log, unlines, (.))
 import Text.ParserCombinators.Parsec.Rfc2822 (NameAddr)
+
+-- | This is a special filepath that represents the top of a directory
+-- tree.  For a cabal package this directory would contain the .cabal
+-- file, for a debian package it would contain the debian directory.
+newtype Top = Top {unTop :: FilePath} deriving (Eq, Ord, Show, Typeable)
 
 binaryDebDescription :: BinPkgName -> Lens Atoms B.BinaryDebDescription
 binaryDebDescription b = maybeLens (B.newBinaryDebDescription b) (iso id id) . listElemLens ((== b) . getL B.package) . S.binaryPackages . control
diff --git a/src/Debian/Debianize/Types/Atoms.hs b/src/Debian/Debianize/Types/Atoms.hs
--- a/src/Debian/Debianize/Types/Atoms.hs
+++ b/src/Debian/Debianize/Types/Atoms.hs
@@ -15,19 +15,17 @@
     ) -} where
 
 import Control.Category ((.))
-import Data.Lens.Lazy (Lens, lens, iso, getL)
+import Data.Lens.Lazy (Lens, lens)
 import Data.Map as Map (Map)
 import Data.Monoid (Monoid(..))
 import Data.Set as Set (Set)
 import Data.Text (Text)
 import Data.Version (Version)
 import Debian.Changes (ChangeLog)
-import Debian.Debianize.Types.Base (maybeLens, listElemLens)
-import qualified Debian.Debianize.Types.BinaryDebDescription as B
 import qualified Debian.Debianize.Types.SourceDebDescription as S
 import Debian.Debianize.VersionSplits (VersionSplits)
 import Debian.Orphans ()
-import Debian.Policy (PackageArchitectures, PackagePriority, Section, SourceFormat, StandardsVersion)
+import Debian.Policy (PackageArchitectures, PackagePriority, Section, SourceFormat)
 import Debian.Relation (BinPkgName, Relations, SrcPkgName)
 import Debian.Version (DebianVersion)
 import Distribution.License (License)
diff --git a/src/Debian/Debianize/Types/Base.hs b/src/Debian/Debianize/Types/Base.hs
deleted file mode 100644
--- a/src/Debian/Debianize/Types/Base.hs
+++ /dev/null
@@ -1,42 +0,0 @@
-{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, OverloadedStrings, ScopedTypeVariables, TupleSections, TypeFamilies #-}
-{-# OPTIONS_GHC -Wall #-}
-module Debian.Debianize.Types.Base
-    ( Top(..)
-    , listElemLens
-    , maybeLens
-    ) where
-
-import Control.Category ((.))
-import Data.Generics (Typeable)
-import Data.Lens.Lazy (getL, lens, Lens, setL)
-import Data.Maybe (fromMaybe)
-import Prelude hiding ((.))
-
--- | This is a special filepath that represents the top of a directory
--- tree.  For a cabal package this directory would contain the .cabal
--- file, for a debian package it would contain the debian directory.
-newtype Top = Top {unTop :: FilePath} deriving (Eq, Ord, Show, Typeable)
-
-listElemLens :: (a -> Bool) -> Lens [a] (Maybe a)
-listElemLens p =
-    lens lensGet lensPut
-    where
-      lensGet xs =
-          case span (not . p) xs of
-            (_, x : _) -> Just x
-            _ -> Nothing
-      lensPut Nothing xs =
-          case span (not . p) xs of
-            (pre, _ : post) -> pre ++ post
-            _ -> xs
-      lensPut (Just x) xs =
-          case span (not . p) xs of
-            (pre, _ : post) -> pre ++ (x : post)
-            _ -> xs ++ [x]
-
-maybeLens :: a -> Lens a b -> Lens (Maybe a) b
-maybeLens def l =
-    lens (getL l . fromMaybe def)
-         (\ a b -> case (a, b) of
-                     (_, Nothing) -> Just (setL l a def)
-                     (_, Just b') -> Just (setL l a b'))
diff --git a/src/Debian/Orphans.hs b/src/Debian/Orphans.hs
--- a/src/Debian/Orphans.hs
+++ b/src/Debian/Orphans.hs
@@ -1,16 +1,16 @@
-{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, StandaloneDeriving #-}
+{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, OverloadedStrings, StandaloneDeriving #-}
 {-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
 module Debian.Orphans where
 
 import Data.Function (on)
 import Data.Generics (Data, Typeable)
-import Data.List (isPrefixOf)
+import Data.List (isPrefixOf, intersperse)
 import Data.Maybe (fromMaybe)
 import Data.Monoid ((<>))
-import Data.Text (Text, unpack)
 import Data.Version (Version(..), showVersion)
 import Debian.Changes (ChangeLog(..), ChangeLogEntry(..))
 import Debian.Control (Field'(..))
+import Debian.Pretty (Pretty(pretty), text, cat, empty)
 import Debian.Relation (Relation(..), VersionReq(..), ArchitectureReq(..),
                         BinPkgName(..), SrcPkgName(..))
 import Debian.Version (DebianVersion)
@@ -20,7 +20,6 @@
 import Distribution.Simple.Compiler (Compiler(..))
 import Distribution.Version (VersionRange(..), foldVersionRange')
 import Language.Haskell.Extension (Extension(..), KnownExtension(..), Language(..))
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty), text)
 import Text.ParserCombinators.Parsec.Rfc2822 (NameAddr(..))
 
 deriving instance Typeable Compiler
@@ -51,9 +50,6 @@
 instance Ord PackageDescription where
     compare = compare `on` package
 
-instance Pretty Text where
-    pretty = text . unpack
-
 {-
 instance Show (Control' String) where
     show _ = "<control file>"
@@ -121,7 +117,7 @@
     pretty OtherLicense = text "Non-distributable"
     pretty MIT = text "MIT"
     pretty (UnknownLicense _) = text "Unknown"
-    pretty x = text (show x)
+    pretty x = pretty (show x)
 
 deriving instance Data NameAddr
 deriving instance Typeable NameAddr
@@ -131,9 +127,16 @@
 -- changelog entry, it *must* have a name followed by an email address
 -- in angle brackets.
 instance Pretty NameAddr where
-    pretty x = text (fromMaybe (nameAddr_addr x) (nameAddr_name x) ++ " <" ++ nameAddr_addr x ++ ">")
+    pretty x = pretty (fromMaybe (nameAddr_addr x) (nameAddr_name x) ++ " <" ++ nameAddr_addr x ++ ">")
     -- pretty x = text (maybe (nameAddr_addr x) (\ n -> n ++ " <" ++ nameAddr_addr x ++ ">") (nameAddr_name x))
 
+instance Pretty [NameAddr] where
+    pretty = cat . intersperse (text ", ") . map pretty
+
+instance Pretty (Maybe NameAddr) where
+    pretty Nothing = empty
+    pretty (Just x) = pretty x
+
 deriving instance Show (Field' String)
 
 instance Pretty VersionRange where
@@ -152,7 +155,14 @@
           range
 
 instance Pretty Version where
-    pretty = text . showVersion
+    pretty = pretty . showVersion
 
 instance Pretty DebianVersion where
-    pretty = text . show
+    pretty = pretty . show
+
+instance Pretty (Maybe SrcPkgName) where
+    pretty Nothing = empty
+    pretty (Just x) = pretty x
+
+instance Pretty Bool where
+    pretty = pretty . show
diff --git a/src/Debian/Policy.hs b/src/Debian/Policy.hs
--- a/src/Debian/Policy.hs
+++ b/src/Debian/Policy.hs
@@ -1,6 +1,6 @@
 -- | Code pulled out of cabal-debian that straightforwardly implements
 -- parts of the Debian policy manual, or other bits of Linux standards.
-{-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
+{-# LANGUAGE DeriveDataTypeable, FlexibleInstances, OverloadedStrings #-}
 module Debian.Policy
     ( -- * Paths
       databaseDirectory
@@ -45,6 +45,7 @@
 import Data.Monoid ((<>))
 import Data.Text (Text, pack, unpack, strip)
 import Debian.Debianize.Prelude (read')
+import Debian.Pretty (Pretty(pretty), text, empty)
 import Debian.Relation (BinPkgName)
 import Debian.Version (DebianVersion, parseDebianVersion, version)
 import System.Environment (getEnvironment)
@@ -52,7 +53,6 @@
 import System.Process (readProcess)
 import Text.Parsec (parse)
 import Text.ParserCombinators.Parsec.Rfc2822 (NameAddr(..), address)
-import Text.PrettyPrint.ANSI.Leijen (Pretty(pretty), text)
 
 databaseDirectory :: BinPkgName -> String
 databaseDirectory x = "/srv" </> show (pretty x)
@@ -105,8 +105,8 @@
 data StandardsVersion = StandardsVersion Int Int Int (Maybe Int) deriving (Eq, Ord, Show, Data, Typeable)
 
 instance Pretty StandardsVersion where
-    pretty (StandardsVersion a b c (Just d)) = text $ show a <> "." <> show b <> "." <> show c <> "." <> show d
-    pretty (StandardsVersion a b c Nothing) = text $ show a <> "." <> show b <> "." <> show c
+    pretty (StandardsVersion a b c (Just d)) = pretty (show a) <> text "." <> pretty (show b) <> text "." <> pretty (show c) <> text "." <> pretty (show d)
+    pretty (StandardsVersion a b c Nothing) = pretty (show a) <> text "." <> pretty (show b) <> text "." <> pretty (show c)
 
 -- | Assumes debian-policy is installed
 getDebianStandardsVersion :: IO (Maybe StandardsVersion)
@@ -159,7 +159,7 @@
       x -> error $ "Invalid priority string: " ++ show x
 
 instance Pretty PackagePriority where
-    pretty = text . map toLower . show
+    pretty = pretty . map toLower . show
 
 -- | The architectures for which a binary deb can be built.
 data PackageArchitectures
@@ -171,8 +171,12 @@
 instance Pretty PackageArchitectures where
     pretty All = text "all"
     pretty Any = text "any"
-    pretty (Names xs) = text $ intercalate " " xs
+    pretty (Names xs) = pretty $ intercalate " " xs
 
+instance Pretty (Maybe PackageArchitectures) where
+    pretty Nothing = empty
+    pretty (Just x) = pretty x
+
 parsePackageArchitectures :: String -> PackageArchitectures
 parsePackageArchitectures "all" = All
 parsePackageArchitectures "any" = Any
@@ -193,8 +197,8 @@
       (a, _) -> MainSection a
 
 instance Pretty Section where
-    pretty (MainSection sec) = text sec
-    pretty (AreaSection area sec) = pretty area <> text ("/" <> sec)
+    pretty (MainSection sec) = pretty sec
+    pretty (AreaSection area sec) = pretty area <> text "/" <> pretty sec
 
 -- Is this really all that is allowed here?  Doesn't Ubuntu have different areas?
 data Area
