Created
November 16, 2021 02:49
-
-
Save chris-martin/0a58beab176bacca7da65d06dee41921 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.Foldable | |
import Data.Functor | |
import Data.List | |
import Data.Maybe | |
import Data.Time.Clock | |
import System.Directory | |
import System.Process | |
main = listPackages >>= filterM needsUpdate >>= traverse_ update | |
listPackages = listDirectory "hackage" <&> mapMaybe (dropSuffix ".nix") | |
needsUpdate pkg = do | |
now <- getCurrentTime | |
before <- getModificationTime (pkgFile pkg) | |
return $ diffUTCTime now before > nominalDay | |
pkgFile pkg = "hackage/" <> pkg <> ".nix" | |
update pkg = cabal2nix pkg >>= writeNixFile pkg | |
cabal2nix pkg = readCreateProcess (proc "cabal2nix" ["cabal://" <> pkg]) "" | |
writeNixFile pkg expr = writeFile (pkgFile pkg) expr | |
dropSuffix sfx x | |
| sfx `isSuffixOf` x = Just $ take (length x - length sfx) x | |
| otherwise = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment