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