Created
June 9, 2018 19:40
-
-
Save infinisil/9be491bbe84a3bc1992445f3b5d60b19 to your computer and use it in GitHub Desktop.
This file contains 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
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE NamedFieldPuns #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Nix | |
import Control.Monad | |
import Control.Monad.Trans | |
import qualified Data.HashMap.Strict as H | |
import Data.Maybe | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
import qualified Data.Text.IO as TextIO | |
import Data.Time | |
import Nix.Utils | |
getDrvs :: MonadThunk (NValue m) (NThunk m) m => AttrSet (NThunk m) -> m [(Text, AttrSet (NThunk m))] | |
getDrvs set = do | |
attrs <- mapM (\(n, t) -> force t $ \v -> case _baseValue v of | |
NVSetF x _ -> return (Just (n, x)) | |
_ -> return Nothing | |
) (H.toList set) | |
filterM (\(n, v) -> isDerivation v) (catMaybes attrs) | |
nixpkgs :: (MonadIO m, MonadNix e m, Has e Options) => m (NValue m) | |
nixpkgs = do | |
let path = "/home/infinisil/src/nixpkgs/default.nix" | |
r <- parseNixFileLoc path | |
case r of | |
Failure doc -> fail (show doc) | |
Success expr -> nixEvalExprLoc (Just path) expr | |
program :: (MonadIO m, MonadNix e m, Has e Options) => m () | |
program = do | |
n <- nixpkgs | |
case _baseValue n of | |
NVSetF set _ -> do | |
drvs <- getDrvs set | |
liftIO . print $ "The first 10 derivations are:" | |
liftIO . print . map fst . take 10 $ drvs | |
return () | |
_ -> fail "Nixpkgs is no attrset???" | |
main :: IO () | |
main = do | |
time <- liftIO getCurrentTime | |
let opts = defaultOptions time | |
runLazyM opts program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment