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