-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
melpa2nix.hs
107 lines (91 loc) · 3.74 KB
/
melpa2nix.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{-
emacs2nix - Generate Nix expressions for Emacs packages
Copyright (C) 2016 Thomas Tuegel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
import Control.Concurrent ( getNumCapabilities, setNumCapabilities )
import Control.Monad ( join )
import Data.HashSet ( HashSet )
import qualified Data.HashSet as HashSet
import Data.Monoid ( (<>) )
import Data.Text ( Text )
import qualified Data.Text as T
import Options.Applicative
import System.Environment ( setEnv, unsetEnv )
import qualified Distribution.Emacs.Name as Emacs
import Distribution.Melpa
import Distribution.Melpa.Melpa ( Stable (..) )
import qualified Distribution.Nix.Name as Nix.Name
import Exceptions
main :: IO ()
main =
(catchPretty_ . joinParser)
(info (helper <*> parser) desc)
where
desc = fullDesc <> progDesc "Generate Nix expressions from MELPA recipes"
joinParser :: ParserInfo (IO ()) -> IO ()
joinParser = join . execParser
parser :: Parser (IO ())
parser =
melpa2nix
<$> (threads <|> pure 0)
<*> melpa
<*> stable
<*> work
<*> output
<*> names
<*> indexOnly
<*> packages
where
threads = option auto (long "threads" <> short 't' <> metavar "N"
<> help "use N threads; default is number of CPUs")
melpa = strOption (long "melpa" <> metavar "DIR"
<> help "path to MELPA repository")
stable = Stable <$> switch (long "stable" <> help "generate packages from MELPA Stable")
work = strOption (long "work" <> metavar "DIR"
<> help "path to temporary workspace")
output = strOption (long "output" <> short 'o' <> metavar "FILE"
<> help "dump MELPA data to FILE")
names = strOption (long "names" <> metavar "FILE"
<> help "map Emacs names to Nix names using FILE")
indexOnly = flag False True
(long "index-only"
<> help "don't update packages, only update the index file")
packages = HashSet.fromList . map T.pack
<$> many (strArgument
(metavar "PACKAGE" <> help "only work on PACKAGE"))
melpa2nix :: Int -- ^ number of threads to use
-> FilePath -- ^ path to MELPA repository
-> Stable -- ^ generate packages from MELPA Stable
-> FilePath -- ^ temporary workspace
-> FilePath -- ^ dump MELPA recipes here
-> FilePath -- ^ map of Emacs names to Nix names
-> Bool -- ^ only generate the index
-> HashSet Text
-> IO ()
melpa2nix nthreads melpaDir stable workDir melpaOut namesFile indexOnly packages =
do
-- set number of threads before beginning
if nthreads > 0
then setNumCapabilities nthreads
else getNumCapabilities >>= setNumCapabilities . (* 4)
names <- Nix.Name.readNames namesFile
selected <- getSelectedNames names (HashSet.map Emacs.Name packages)
-- Force our TZ to match the melpa build machines
setEnv "TZ" "PST8PDT"
-- Any operation requiring a password should fail
unsetEnv "SSH_ASKPASS"
updateMelpa melpaDir stable workDir melpaOut indexOnly names selected