1module Distribution.Nixpkgs.PackageMap where
3import qualified Data.Aeson as JSON
4import qualified Data.ByteString.Lazy as LBS
6import qualified Data.Map as Map
7import Data.Map.Strict ( Map )
9import qualified Data.Set as Set
12import Language.Nix.Identifier
13import Language.Nix.Path
15import Distribution.Nixpkgs.Util.PrettyPrinting
17type PackageMap = Map Identifier (Set Path)
19readNixpkgPackageMap :: FilePath -> Maybe Path -> IO PackageMap
20readNixpkgPackageMap nixpkgs attrpath = fmap identifierSet2PackageMap (readNixpkgSet nixpkgs attrpath)
22readNixpkgSet :: FilePath -> Maybe Path -> IO (Set String)
23readNixpkgSet nixpkgs attrpath = do
24 let extraArgs = maybe [] (\p -> ["-A", render (pPrint p)]) attrpath
25 (_, Just h, _, _) <- createProcess (proc "nix-env" (["-qaP", "--json", "-f"++nixpkgs] ++ extraArgs))
26 { std_out = CreatePipe, env = Nothing } -- TODO: ensure that overrides don't screw up our results
27 buf <- LBS.hGetContents h
28 let pkgmap :: Either String (Map String JSON.Object)
29 pkgmap = JSON.eitherDecode buf
30 either fail (return . Map.keysSet) pkgmap
32identifierSet2PackageMap :: Set String -> PackageMap
33identifierSet2PackageMap pkgset = foldr (uncurry insertIdentifier) Map.empty pkglist
35 pkglist :: [(Identifier, Path)]
36 pkglist = mapMaybe parsePackage (Set.toList pkgset)
38 insertIdentifier :: Identifier -> Path -> PackageMap -> PackageMap
39 insertIdentifier i = Map.insertWith Set.union i . Set.singleton
41parsePackage :: String -> Maybe (Identifier, Path)
42parsePackage x | null x = error "Distribution.Nixpkgs.PackageMap.parsepackage: empty string is no valid identifier"
43 | xs <- splitOn "." x = if needsQuoting (head xs)
45 else Just (create ident (last xs), create path (map (create ident) (init xs)))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list