@@ -28,17 +28,23 @@ import System.Process
28
28
import Text.Regex.Applicative
29
29
30
30
data Env = Env
31
- { gitBin :: FilePath
32
- , nixBin :: FilePath
33
- , cacheDir :: FilePath
34
- , manager :: Manager
31
+ { gitBin :: FilePath
32
+ , nixBin :: FilePath
33
+ , nixHashBin :: FilePath
34
+ , nixBuildBin :: FilePath
35
+ , cpBin :: FilePath
36
+ , cacheDir :: FilePath
37
+ , manager :: Manager
35
38
}
36
39
37
40
-- | Initializes the read-only environment
38
41
getEnv :: IO Env
39
42
getEnv = Env
40
43
<$> (fromMaybe (error " Can't find git executable" ) <$> findExecutable " git" )
41
44
<*> (fromMaybe (error " Can't find nix-instantiate executable" ) <$> findExecutable " nix-instantiate" )
45
+ <*> (fromMaybe (error " Can't find nix-hash executable" ) <$> findExecutable " nix-hash" )
46
+ <*> (fromMaybe (error " Can't find nix-build executable" ) <$> findExecutable " nix-build" )
47
+ <*> (fromMaybe (error " Can't find cp executable" ) <$> findExecutable " cp" )
42
48
<*> getXdgDirectory XdgCache " all-hies"
43
49
<*> newTlsManager
44
50
@@ -64,9 +70,13 @@ run = do
64
70
65
71
setupDirectories :: App ()
66
72
setupDirectories = do
67
- cachePath " per-nixpkgs" >>= liftIO . createDirectoryIfMissing True
73
+ cachePath " per-nixpkgs/ghcVersions" >>= liftIO . createDirectoryIfMissing True
74
+ cachePath " per-nixpkgs/sha256" >>= liftIO . createDirectoryIfMissing True
68
75
cachePath " per-hie" >>= liftIO . createDirectoryIfMissing True
76
+ cachePath " per-ghcMinor" >>= liftIO . createDirectoryIfMissing True
69
77
liftIO $ createDirectoryIfMissing True " nixpkgsForGhc"
78
+ cleanDirectory " ghcBaseLibraries"
79
+ cleanDirectory " nixpkgsHashes"
70
80
71
81
-- | Makes sure that the given directory is existent and empty
72
82
cleanDirectory :: FilePath -> App ()
@@ -122,13 +132,49 @@ genS2N hash version = do
122
132
exists <- liftIO $ doesFileExist path
123
133
124
134
nixpkgsRev <- findNixpkgsForGhc version
135
+ sha <- nixpkgsSha nixpkgsRev
136
+ liftIO $ writeFile (" nixpkgsHashes" </> nixpkgsRev) sha
137
+
138
+ genBaseLibraries version nixpkgsRev
125
139
126
140
unless exists $ do
127
141
liftIO $ putStrLn $ " Using nixpkgs revision " ++ nixpkgsRev ++ " for ghc version " ++ show version
128
142
git nixpkgs [ " checkout" , nixpkgsRev ]
129
143
callStack2nix hash path version
130
144
return path
131
145
146
+ genBaseLibraries :: Version -> String -> App ()
147
+ genBaseLibraries version@ (Version major minor patch) nixpkgsRev = do
148
+ cache <- cachePath $ " per-ghcMinor" </> show major ++ show minor
149
+ exists <- liftIO $ doesFileExist cache
150
+ unless exists $ do
151
+ git nixpkgs [ " checkout" , nixpkgsRev ]
152
+ nix <- lift $ asks nixBuildBin
153
+ ghcPath <- liftIO $ init <$> readProcess nix
154
+ [ " --no-out-link" , " <nixpkgs>" , " -A" , " haskell.compiler." ++ nixVersion version ] " "
155
+ libs <- liftIO $ readProcess (ghcPath </> " bin/ghc-pkg" )
156
+ [ " list" , " --no-user-package-db" , " --simple" ] " "
157
+ liftIO $ writeFile cache libs
158
+ liftIO $ copyFile cache (" ghcBaseLibraries" </> nixVersion version)
159
+
160
+ nixpkgsSha :: String -> App String
161
+ nixpkgsSha revision = do
162
+ cacheFile <- cachePath $ " per-nixpkgs/sha256" </> revision
163
+ exists <- liftIO $ doesFileExist cacheFile
164
+ if exists then liftIO $ readFile cacheFile
165
+ else do
166
+ git nixpkgs [ " checkout" , revision ]
167
+ path <- repoPath nixpkgs
168
+ tmp <- cachePath " tmp"
169
+ cp <- lift $ asks cpBin
170
+ liftIO $ readProcess cp [" -rl" , path, tmp] " "
171
+ liftIO $ removeDirectoryRecursive (tmp </> " .git" )
172
+ nixHash <- lift $ asks nixHashBin
173
+ hash <- liftIO $ head . lines <$> readProcess nixHash [" --type" , " sha256" , " --base32" , tmp] " "
174
+ liftIO $ writeFile cacheFile hash
175
+ liftIO $ removeDirectoryRecursive tmp
176
+ return hash
177
+
132
178
-- | Finds a suitable nixpkgs revision that has a the specified compiler available
133
179
findNixpkgsForGhc :: Version -> App String
134
180
findNixpkgsForGhc version = do
@@ -154,7 +200,7 @@ findNixpkgsForGhc version = do
154
200
-- | Determines the available GHC versions for a nixpkgs revision
155
201
ghcVersionsForNixpkgs :: String -> App [Version ]
156
202
ghcVersionsForNixpkgs rev = do
157
- path <- cachePath $ " per-nixpkgs" </> rev
203
+ path <- cachePath $ " per-nixpkgs/ghcVersions " </> rev
158
204
exists <- liftIO $ doesFileExist path
159
205
if exists then do
160
206
contents <- liftIO $ readFile path
@@ -253,7 +299,7 @@ getHistory = do
253
299
response <- liftIO $ responseBody <$> httpLbs (parseRequest_ url) mgr
254
300
-- Because this file is downloaded in the order of oldest to newest
255
301
-- We reverse it for easier processing
256
- let items = reverse . map (head . BS. words ) $ BS. lines response
302
+ let items = reverse . ( " 45e819dd49799d8b680084ed57f6d0633581b957 " : ) . map (head . BS. words ) $ BS. lines response
257
303
258
304
liftIO $ BS. writeFile path $ BS. unlines items
259
305
return $ map BS. unpack items
0 commit comments