{ stdenv, writeTextFile , ghcWithPackages , user ? "gkleen" # , libnotify }: stdenv.mkDerivation { name = ''notify-${user}''; src = writeTextFile { name = ''notify-${user}.hs''; text = '' {-# LANGUAGE ViewPatterns #-} import System.FilePath.Glob (glob) import System.Environment (setEnv, getArgs) import System.Process (spawnProcess, waitForProcess) import System.Exit (exitWith, ExitCode(..)) import Data.List (isPrefixOf, dropWhile, dropWhileEnd, init) import Data.Char (isSpace) import Control.Monad (forM_, void) import qualified Libnotify as Notify import Data.Monoid main = do envFiles <- glob "/home/${user}/.dbus/session-bus/*" forM_ envFiles $ \envFile -> do sessionAddr <- unQuote . tail . snd . break (== '=') . head . filter ("DBUS_SESSION_BUS_ADDRESS=" `isPrefixOf`) . lines <$> readFile envFile setEnv "DBUS_SESSION_BUS_ADDRESS" sessionAddr lines <- lines <$> getContents case lines of ((trim -> app):(trim -> summary):(trim . unlines -> contents)) -> do Notify.display_ $ Notify.appName app <> Notify.summary summary <> Notify.body contents _ -> exitWith ExitFailure where trim = dropWhileEnd isSpace . dropWhile isSpace unQuote ('\''':xs) = init xs unQuote ('"':xs) = init xs unQuote xs = xs ''; }; phases = [ "buildPhase" "installPhase" ]; buildPhase = '' ${ghcWithPackages (p: with p; [ Glob process libnotify ])}/bin/ghc -odir . -hidir . $src -o notify-${user} ''; installPhase = '' mkdir -p $out/bin cp notify-${user} $out/bin chmod +x $out/bin/notify-${user} ''; }