diff --git a/distribution-nixpkgs.cabal b/distribution-nixpkgs.cabal
--- a/distribution-nixpkgs.cabal
+++ b/distribution-nixpkgs.cabal
@@ -1,5 +1,5 @@
 name:          distribution-nixpkgs
-version:       1.3.0
+version:       1.3.1
 synopsis:      Types and functions to manipulate the Nixpkgs distribution
 description:   Types and functions to represent, query, and manipulate the Nixpkgs distribution.
 license:       BSD3
diff --git a/src/Language/Nix/PrettyPrinting.hs b/src/Language/Nix/PrettyPrinting.hs
--- a/src/Language/Nix/PrettyPrinting.hs
+++ b/src/Language/Nix/PrettyPrinting.hs
@@ -54,7 +54,15 @@
 bool False = text "false"
 
 string :: String -> Doc
-string = doubleQuotes . text
+string = doubleQuotes . quoteString
+
+quoteString :: String -> Doc
+quoteString []          = mempty
+quoteString ['\\']      = text "\\\\"
+quoteString ('\\':x:xs)
+  | x `elem` "\"rn$\\t" = text ['\\',x] <> quoteString xs
+  | otherwise           = text "\\\\" <> quoteString (x:xs)
+quoteString (x:xs)      = char x <> quoteString xs
 
 prepunctuate :: Doc -> [Doc] -> [Doc]
 prepunctuate _ []     = []
