{ stdenv, haskellPackages, thinklight ? "thinklight", makeWrapper }: stdenv.mkDerivation { name = "thinklight-0.1"; ghc = haskellPackages.ghcWithPackages (self: [self.strict]); outputs = [ "out" ]; builder = builtins.toFile "builder.sh" '' source $stdenv/setup mkdir -p $out/bin $ghc/bin/ghc $src -o $out/bin/thinklight wrapProgram $out/bin/thinklight --set THINKLIGHT ${thinklight} ''; src = builtins.toFile "source.hs" '' import Control.Monad (sequence) import System.IO.Error import System.Environment import System.FilePath import Control.Concurrent (threadDelay) import System.IO.Strict (readFile) import Prelude hiding (readFile) import Data.List (intersperse) import Data.Maybe (fromMaybe) data Mode = On | Off | Toggle | Blink deriving (Read, Show, Eq) main :: IO () main = do args <- getArgs let mode = if length args >= 1 then read $ head args else Toggle sequence $ map (\g -> catchIOError g (\e -> if isDoesNotExistError e then return () else ioError e)) [thinklight mode] return () findBase :: IO FilePath findBase = do env <- fromMaybe "thinklight" <$> lookupEnv "THINKLIGHT" return $ "/sys/class/leds/tpacpi::" ++ env readMax, readCurrent :: IO String readMax = readFile =<< (( "max_brightness") <$> findBase) readCurrent = readFile =<< (( "brightness") <$> findBase) writeCurrent :: String -> IO () writeCurrent str = flip writeFile str =<< (( "brightness") <$> findBase) thinklight :: Mode -> IO () thinklight On = readMax >>= writeCurrent . show thinklight Off = writeCurrent "0" thinklight Toggle = do c <- readCurrent m <- readMax let m' = read m :: Int let c' = read c :: Int writeCurrent $ show $ if c' /= 0 then 0 else m' thinklight Blink = do args <- getArgs thinklight Toggle sequence $ intersperse (thinklight Toggle) $ map (\i -> threadDelay $ (read i) * 10^3) (tail args) thinklight Toggle ''; }