git.iko.soy/typeable/cabal2nix
on 05809a4 help sign in
22 lines 705 B history raw
1module Language.Nix.Path ( Path, mkPath, path ) where
3import Control.Lens
4import Distribution.Nixpkgs.Util.PrettyPrinting ( Pretty(..), punctuate, hcat, char )
5import Language.Nix.Identifier
7-- | Paths are non-empty lists of identifiers in Nix.
9newtype Path = Path { _segments :: [Identifier] }
10 deriving (Show, Eq, Ord)
12mkPath :: [Identifier] -> Path
13mkPath [] = error "Nix paths cannot be empty"
14mkPath p
15 | [Identifier s] <- p, needsQuoting s = error ("invalid Nix path: " ++ show p)
16 | otherwise = Path p
18path :: Lens' Path [Identifier]
19path f (Path ids) = mkPath `fmap` f ids
21instance Pretty Path where
22 pPrint p = hcat $ punctuate (char '.') $ pPrint <$> p^.path