1module Distribution.NixOS.PackageMap where
3import qualified Data.Aeson as JSON
5import qualified Data.Map as Map
6import Data.Map.Strict ( Map )
8import qualified Data.Set as Set
9import qualified Data.String.UTF8 as UTF8 ( fromString, toRep )
12type Attribute = String
13type Path = [Attribute]
15readNixpkgAttributeSet :: IO (Set Attribute)
16readNixpkgAttributeSet = do
17 buf <- readProcess "nix-env" ["-qaP", "--json"] ""
18 let pkgmap :: Either String (Map Attribute JSON.Object)
19 pkgmap = JSON.eitherDecodeStrict (UTF8.toRep (UTF8.fromString buf))
20 either fail (return . Map.keysSet) pkgmap
22parsePackage :: Attribute -> (Attribute, Path)
23parsePackage "" = error "empty string is not a valid package name"
24parsePackage x = (last xs, init xs) where xs = splitOn "." x
26type PackageMap = Map Attribute (Set Path)
28attributeSet2PackageMap :: Set Attribute -> PackageMap
29attributeSet2PackageMap pkgset = foldr (uncurry insertAttribute) Map.empty pkglist
31 pkglist :: [(Attribute, Path)]
32 pkglist = Set.toList (Set.map parsePackage pkgset)
34 insertAttribute :: Attribute -> Path -> PackageMap -> PackageMap
35 insertAttribute attr = Map.insertWith Set.union attr . Set.singleton
37readNixpkgPackageMap :: IO PackageMap
38readNixpkgPackageMap = fmap attributeSet2PackageMap readNixpkgAttributeSet
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