1{-# LANGUAGE RecordWildCards #-}
3module Cabal2Nix.Normalize ( normalize, normalizeList ) where
5import Distribution.NixOS.Derivation.Cabal
7import Cabal2Nix.CorePackages
12normalize :: Derivation -> Derivation
13normalize deriv@(MkDerivation {..}) = deriv
14 { buildDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) buildDepends)
15 , testDepends = normalizeNixNames (filter (`notElem` (pname : corePackages)) testDepends)
16 , buildTools = normalizeNixBuildTools (filter (`notElem` coreBuildTools) buildTools)
17 , extraLibs = normalizeNixLibs extraLibs
18 , pkgConfDeps = normalizeNixLibs pkgConfDeps
19 , metaSection = normalizeMeta metaSection
22normalizeMeta :: Meta -> Meta
23normalizeMeta meta@(Meta {..}) = meta
24 { description = normalizeDescription description
25 , maintainers = normalizeMaintainers maintainers
26 , platforms = normalizePlatforms platforms
29normalizeDescription :: String -> String
30normalizeDescription desc
32 | last desc == '.' && length (filter ('.'==) desc) == 1 = normalizeDescription (init desc)
33 | otherwise = quote (unwords (words desc))
35quote :: String -> String
36quote ('\\':c:cs) = '\\' : c : quote cs
37quote ('"':cs) = '\\' : '"' : quote cs
38quote (c:cs) = c : quote cs
41normalizeList :: [String] -> [String]
42normalizeList = nub . sortBy (compare `on` map toLower)
44normalizeNixNames :: [String] -> [String]
45normalizeNixNames = normalizeList . map toNixName
47normalizeNixLibs :: [String] -> [String]
48normalizeNixLibs = normalizeList . concatMap libNixName
50normalizeNixBuildTools :: [String] -> [String]
51normalizeNixBuildTools = normalizeList . concatMap buildToolNixName
53normalizeMaintainers :: [String] -> [String]
54normalizeMaintainers maints = normalizeList
55 [ if '.' `elem` m then m else "self.stdenv.lib.maintainers." ++ m | m <- maints ]
57normalizePlatforms :: [String] -> [String]
58normalizePlatforms [] = ["self.ghc.meta.platforms"]
59normalizePlatforms plats = normalizeList
60 [ if '.' `elem` p then p else "self.stdenv.lib.platforms." ++ p | p <- plats ]
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